热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在MariaDB数据库中使用federated引擎

federated引擎是mysql的一个特殊的引擎,类似于oracle的dblink的功能,能够访问远程数据库上的表,而不用本地存储数据默认是未启用的,MariaDB[(none)]showengines;+——————?+———+————————————————————+————?+——+——
federated引擎是mysql的一个特殊的引擎,类似于oracle的dblink的功能,能够访问远程数据库上的表,而不用本地存储数据
默认是未启用的,

MariaDB [(none)]> show engines;
+——————?+———+————————————————————+————?+——+————+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+——————?+———+————————————————————+————?+——+————+
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary
tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO |
NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and
foreign keys | YES | YES | YES |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO |
NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO
|
+——————?+———+————————————————————+————?+——+————+

google了下,该引擎是以插件形式使用的,所以要手动安装:
install plugin federated soname ‘ha_federatedx.dll’;

再查看引擎:
MariaDB [(none)]> show engines;
+——————?+———+————————————————————+————?+——+————+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+——————?+———+————————————————————+————?+——+————+
| CSV | YES | CSV storage engine | NO | NO | NO |
| FEDERATED | YES | FederatedX pluggable storage engine | YES | NO
| YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary
tables | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO |
NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and
foreign keys | YES | YES | YES |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO |
NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO
|
+——————?+———+————————————————————+————?+——+————+

建表语句:
CREATE TABLE `FEDERATED` (
`id` int(10),
`name` varchar(20)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8
cOnnection=’mysql://darkz:123456@192.168.12.5:3306/tab_item/201210′;
该表建表语句要和远程的表结构一致,最后的connection的格式为:

cOnnection=’mysql://username:password@host:port/dbname/tbname’; 简单测试了下,该表虽然可以访问远程数据库,但是表较大的时候,流量也较大,貌似是将远程数据库的内容取回到本地然后再进行操作的,而且没有缓存数据
局域网内测试刚才建的表,运行

select count(*) from `FEDERATED`;
结果带宽跑满,还持续了几十秒,这就说明,不是直接取的结果,二十将原始表的数据取回到本地,然后进行sql处理的,这样有个缺点就是比较占带宽,而且慢.
如果能进行优化,只返回查询结果,那么就会更好了.


推荐阅读
author-avatar
刘刘刘存乐_626
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有