MySQL远程表使用
1.1.1 MySQL远程表介绍及注意问题
I. 实现原理
通过创建存储引擎为Federated 的表来实现远程共享服务器表数据。
Federated:能够将多个分离(不在同一台服务器上的机器)的MySQL服务器链接起来,从多个物理服务器创建一个逻辑数据库。十分适合于分布式环境或数据集市环境。
II. 应用注意问题
1. 本地数据库服务必须支持“FEDERATED”存储引擎,远程服务器可以不支持
2. 本地服务器最好不是集成环境,例如 apmxe ,wamp 等,集成环境,启动“FEDERATED”存储引擎会出现其他问题,不能正常启动
3. “FEDERATED”存储引擎是从MySQL5.0开始支持的 。
4. 因为操作本地库中的远程表,就是操作远程库中对应的数据库表,所以在本地库中对应远程表的操作(新增,修改,删除),均为反应都对应的远程表中。
5. 其他
III. 关于延迟问题
1. 本地服务器与远程服务器在同一网段中(局域网),测试延迟时间感觉不到。
2. 延迟与网速和服务器性能有关。
1.1.2 实际应用举例
I. 检查数据库服务器是否支持远程表
在MySQL命令行使用 “showengines ;”检查是否支持远程表,实际上是查看当前数据库服务器(想远程共享其他服务器数据库数据的机器)是否支持“FEDERATED”存储引擎。参考语句及结构如下
II. 为服务器开启“FEDERATED”存储引擎
第一步:
修改MySQL数据库配置文件 ,参考过程如下:
第二步:
重启MySQL数据库服务
第三步:检查“FEDERATED”存储引擎是否开启
III. “showengines ;”命令输出结果简单介绍
字符集
Value | Meaning |
| The engine is supported and is active (支持当前引擎) |
| Like |
| The engine is not supported (当前数据库默认不支持当前引擎,通过其他配置或安装对应插件可以支持) |
| The engine is supported but has been disabled (支持当前存储引擎,但未开启) |
A value of NO
means that the server wascompiled without support for the engine, so it cannot be enabled at runtime.
A value of DISABLED
occurs either because theserver was started with an option that disables the engine, or because not alloptions required to enable it were given. In the latter case, the error logfile should contain a reason indicating why the option is disabled. See Section 5.2.2, “The Error Log”.
You might also see DISABLED
for a storageengine if the server was compiled to support it, but was started with a --skip-engine_name
option. For the NDBCLUSTER
storage engine, DISABLED
means the server was compiled withsupport for MySQL Cluster, but was not started with the--ndbcluster
option.
IV. 应用举例
1.服务器情况
类别 | IP地址 | 数据库端口 | 登录用户名 | 登录用户密码 | 是否需要支持“FEDERATED” | 其他 | 数据库 | 表名 |
服务器1(本地服务器) | 192.168.1.134 | 3306 | zichen | 62672000 | 需要 | 本地服务器,远程共享183服务器数据 | cbs_db_zyh | dblink_jykzcs |
服务器2(远程服务器) | 192.168.1.183 | 3306 | zichen | 62672000 | 不需要 |
| tms_db | cs_jykzcs |
登录用户名与密码可以不一样 。
2.创建远程表 :