Federated存储引擎可以使你在本地数据库中访问远程数据库中的数据,针对federated存储引擎表的查询会被发送到远程数据库的表上执行,本地是不存储任何数据的。
简要介绍后,是不是发现它和Oracle的database link(数据库链接)非常相似,它所实现的功能和db link类似,要在MySQL下找寻db link替代品的,federated存储引擎是不二的选择。
1. 查看当前支持的存储引擎
SQL>show engines;
- +------------+---------+------------------------------------------------------------+--------------+------+------------+
- | Engine | Support | Comment | Transactions | XA | Savepoints |
- +------------+---------+------------------------------------------------------------+--------------+------+------------+
- | CSV | YES | CSV storage engine | NO | NO | NO |
- | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
- | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
- | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
- | MyISAM | YES | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
- +------------+---------+------------------------------------------------------------+--------------+------+------------+
- 5 rows in set (0.00 sec)
发现安装MySQL时没有编译进来,只能现安装了。
2. 安装federated存储引擎
由于编译时没有选择federated,所以打算通过INSTALL PLUGIN的方式安装,正常情况下,federated是支持动态安装的:
=== Federated Storage Engine ===
Plugin Name: federated
Description: Connects to tables on remote MySQL servers
Supports build: static and dynamic
Configurations: max, max-no-ndb
可是执行以下命令时报错:
SQL>install plugin federated soname 'ha_federated.so';
ERROR 1126 (HY000): Can't open shared library '/usr/local/mysql/lib/mysql/plugin/ha_federated.so' (errno: 2 undefined symbol: dynstr_append_mem)
搜了一下,发现是个老问题,竟然到现在都没解决,可见MySQL团队的效率和管理的混乱。http://bugs.mysql.com/bug.php?id=40942
没有办法了,只有重新编译MySQL源码了, 加上--with-plugins=federated。从5.1.26开始,默认MySQL不启用federated存储引擎,所以需要在my.cnf中加入federated选项或是在命令行用--federated选项启动mysqld。编译后的结果如下:
SQL>show engines;
转自: http://blog.163.com/ji_1006/blog/static/106123412011116265531/
- +------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
- | Engine | Support | Comment | Transactions | XA | Savepoints |
- +------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
- | CSV | YES | CSV storage engine | NO | NO | NO |
- | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
- | FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO |
- | MyISAM | YES | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
- | InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
- | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
- +------------+---------+----------------------------------------------------------------------------+--------------+------+------------+