开发者

How to write MySQL query on 2 different tables residing in 2 different databases on 2 different servers?

开发者 https://www.devze.com 2023-03-13 12:31 出处:网络
I have 2 tables table1 in database1 on server1 having userID and userName table2 in database2 on server2 having

I have 2 tables

table1 in database1 on server1 having userID and userName

table2 in database2 on server2 having 开发者_如何学编程 userID

I need a way to access table1 on server1 to get the userName of the userID in table2

How do I do query using MySQL?


I think you can use 2 different connections:

$connection1= mysql_connect('server1', 'user1', 'password1');
$connection2= mysql_connect('server2', 'user2', 'password2');

Retrieve data from database 1, and use it to query database2. Or the opposite, depending on what you need. This means you'll use 2 queries.

Edit: I automatically assumed you're using php, hence my answer. I'm sorry if it's irrelevant.


MySQL supports federated tables - tables housed in a physically distinct server instance. It makes the remote table appear local, and any queries executed on it are transparently sent to the remote server for execution.


not sure about mysql...

in Oracle you would link the databases and then fully qualify the table references in your query (with '.' seperators)

0

精彩评论

暂无评论...
验证码 换一张
取 消