I have 2 tables
我有两个表
table1 in database1 on server1 having userID and userName
server1上的database1中有userID和userName
table2 in database2 on server2 having userID
表2在server2上的database2中具有userID。
I need a way to access table1 on server1 to get the userName of the userID in table2
我需要一种访问server1上的table1的方法来获取table2中userID的用户名
How do I do query using MySQL?
如何使用MySQL进行查询?
3 个解决方案
#1
2
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.
从数据库1检索数据,并使用它查询database2。或者相反,这取决于你需要什么。这意味着您将使用两个查询。
Edit: I automatically assumed you're using php, hence my answer. I'm sorry if it's irrelevant.
编辑:我自动假设您正在使用php,因此我的答案是。如果这无关紧要,我很抱歉。
#2
1
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.
MySQL支持联邦表——位于物理上不同的服务器实例中的表。它使远程表显示为本地的,并且对其执行的任何查询都透明地发送到远程服务器执行。
#3
0
not sure about mysql...
不确定关于mysql…
in Oracle you would link the databases and then fully qualify the table references in your query (with '.' seperators)
在Oracle中,您将链接数据库,然后完全限定查询中的表引用(使用')。分离器)
#1
2
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.
从数据库1检索数据,并使用它查询database2。或者相反,这取决于你需要什么。这意味着您将使用两个查询。
Edit: I automatically assumed you're using php, hence my answer. I'm sorry if it's irrelevant.
编辑:我自动假设您正在使用php,因此我的答案是。如果这无关紧要,我很抱歉。
#2
1
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.
MySQL支持联邦表——位于物理上不同的服务器实例中的表。它使远程表显示为本地的,并且对其执行的任何查询都透明地发送到远程服务器执行。
#3
0
not sure about mysql...
不确定关于mysql…
in Oracle you would link the databases and then fully qualify the table references in your query (with '.' seperators)
在Oracle中,您将链接数据库,然后完全限定查询中的表引用(使用')。分离器)