Join tables from two different server(连接来自两个不同服务器的表)
问题描述
我有两个不同的服务器 server1 和 server2,现在我在 server1 和 中有 .我正在尝试像这样在 MySQL 中加入这两个表.db1server2 中的 db2
I have two different server server1 and server2, now I have db1 in server1 and db2 in server2.
I am trying to join these two table in MySQL like this.
Select a.field1,b.field2
FROM [server1, 3306].[db1].table1 a
Inner Join [server2, 3312].[db2].table2 b
ON a.field1=b.field2
但是我遇到了错误.在 MYSQL 中是可能的.
But I am getting error. Is is possible in MYSQL.
推荐答案
是的,在 MySQL 中是可能的.
之前也有类似的问题.您必须使用 联邦引擎 来执行此操作.这个想法是这样的:
Yes, it is possible in MySQL.
There are similar questions asked previously too. You have to use FEDERATED ENGINE to do this. The idea goes like this:
您必须有一个基于另一个远程位置的表的联合表,才能以您想要的方式使用.表的结构必须完全相同.
You have to have a federated table based on the table at another remote location to use the way you want. The structure of the table have to exactly same.
CREATE TABLE federated_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
other INT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
INDEX name (name),
INDEX other_key (other)
)
ENGINE=FEDERATED
DEFAULT CHARSET=latin1
CONNECTION='mysql://fed_user@remote_host:9306/federated/test_table';
[来源答案]
这篇关于连接来自两个不同服务器的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:连接来自两个不同服务器的表
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
