MySQL:从另一台服务器选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/508100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL: SELECT from another server
提问by BlaM
I'm afraid that I already know the answer to my question, but I'll ask it anyway:
恐怕我已经知道我的问题的答案了,但我还是会问:
When there are two MySQL DB servers, can I access data that is stored on the other server?
当有两台 MySQL DB 服务器时,我可以访问存储在另一台服务器上的数据吗?
In other words: Can I somehow do this:
换句话说:我可以以某种方式这样做吗:
INSERT INTO table (x, y, z)
SELECT x, y, x+y
FROM [otherserver].[database].[table]
Is the answer really as short as "No"?
答案真的像“不”一样简短吗?
采纳答案by volatilsis
You can set up federated tables in MySQL to accomplish what you're trying to do. There are some limitations.
您可以在 MySQL 中设置联合表来完成您想要做的事情。有一些限制。
http://dev.mysql.com/doc/refman/en/federated-storage-engine.htmlhttp://dev.mysql.com/doc/refman/en/federated-usagenotes.html
http://dev.mysql.com/doc/refman/en/federated-storage-engine.html http://dev.mysql.com/doc/refman/en/federated-usagenotes.html
回答by tim
CREATE TABLE `remote_table`(
`foo` VARCHAR(100),
UNIQUE KEY(`foo`(30))
) ENGINE=FEDERATED CONNECTION='mysql://thedomain.com:3306/remotedbname/remotetablename';
Then query it like any other table with SELECT, UPDATE, INSERT, DELETE.
然后像任何其他表一样使用 SELECT、UPDATE、INSERT、DELETE 查询它。