Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Join query across multiple databases located on different servers

Tags:

php

mysql

In SQL Server there is a way to join tables from multiple sql servers by using link tables.

I wonder whether is it possible to do the same? I am using PHP, does PHP provides this kind of facilities?

like image 620
Graviton Avatar asked Feb 18 '26 08:02

Graviton


2 Answers

Try the federated storage engine to link to tables on other servers.

http://dev.mysql.com/tech-resources/articles/mysql-federated-storage.html

like image 193
Neil Avatar answered Feb 20 '26 21:02

Neil


It isn't necessarily easy, nor pretty, but this article gives some solutions to your problem: http://www.linux.com/archive/feature/52390

UPDATE

Since the link is gone now, here is more text

Creating a linked server using OLE DB for SQL Server This example creates a linked server named MyDatabase that uses the Microsoft OLE DB Provider for SQL Server.

USE master
GO
EXEC sp_addlinkedserver 
'MyDatabase',
N'SQL Server'
GO

Then you can reference as though they are on the same server, so if the databases are on the same mssql server then skip the above step and just do the following:

[Server name].[database name].[owner].table_name

like image 44
James Black Avatar answered Feb 20 '26 22:02

James Black



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!