您好,登錄后才能下訂單哦!
這篇文章給大家介紹FEDERATED存儲引擎實現(xiàn)oracle dblink功能及弊端分別是什么,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
mysql FEDERATED存儲引擎可以實現(xiàn)oracle dblink類似的遠程訪問功能,F(xiàn)EDERATED存儲引擎需要針對每個需要遠程訪問的表進行逐一創(chuàng)建,而不能像oracle dblink有全局功能。
mysql FEDERATED存儲引擎默認是不開啟的
mysql> show engines;
| Engine | Support | Comment | Transactions | XA | Savepoints |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
9 rows in set (0.00 sec)
開啟方法:my.cnf的[mysqld]下增加federated(小寫),重啟即可
mysql> show engines;
| Engine | Support | Comment | Transactions | XA | Savepoints |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
9 rows in set (0.00 sec)
測試一:遠程訪問
源192.168.129.150表test.fader
mysql> select * from fader;
+----+------+
| id | name |
+----+------+
| 1 | leo |
| 2 | mike |
| 3 | lucy |
| 4 | tom |
+----+------+
目標172.30.249.154上創(chuàng)建FEDERATED引擎表
CREATE TABLE fader_link (
`id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE =FEDERATED DEFAULT CHARSET=utf8 CONNECTION='mysql://root:Welcome1>@192.168.129.150:3306/test/fader' ;
mysql> select * from test.fader_link;
+----+------+
| id | name |
+----+------+
| 1 | leo |
| 2 | mike |
| 3 | lucy |
| 4 | tom |
+----+------+
4 rows in set (0.00 sec)
可遠程訪問
測試二:物理文件
源192.168.129.150表test.fader
[root@trcloud-gtt-db-master test]# ls -l fader*
-rw-rw---- 1 mysql mysql 8586 9月 22 10:22 fader.frm
-rw-rw---- 1 mysql mysql 98304 9月 22 10:22 fader.ibd
目標172.30.249.154表test.fader_link
[root@trcloud-gtt-test-db test]# ls -l fader_link*
-rw-rw---- 1 mysql mysql 8586 Sep 22 10:30 fader_link.frm
可以看出FEDERATED引擎表沒有idb的數(shù)據(jù)文件,只有結(jié)構(gòu)文件
測試三:修改表結(jié)構(gòu)
源192.168.129.150表test.fader增加字段并增加數(shù)據(jù)
ALTER TABLE `fader` ADD COLUMN `city` varchar(255) NULL AFTER `name`;
mysql> select * from test.fader;
+----+------+------+
| id | name | city |
+----+------+------+
| 1 | leo | bj |
| 2 | mike | sh |
| 3 | lucy | nj |
| 4 | tom | hz |
+----+------+------+
4 rows in set (0.00 sec)
目標172.30.249.154表test.fader_link查數(shù)據(jù)
mysql> select * from test.fader_link;
+----+------+
| id | name |
+----+------+
| 1 | leo |
| 2 | mike |
| 3 | lucy |
| 4 | tom |
+----+------+
4 rows in set (0.00 sec)
查不到新增的列數(shù)據(jù),嘗試增加字段
mysql> ALTER TABLE test.fader_link ADD COLUMN `city` varchar(255) NULL AFTER `name`;
ERROR 1031 (HY000): Table storage engine for 'fader_link' doesn't have this option 報錯無法對FEDERATED引擎表進行這個操作
源192.168.129.150表test.fader刪除字段
ALTER TABLE `fader` DROP COLUMN `city`;
ALTER TABLE `fader` DROP COLUMN `name`;
mysql> select * from test.fader;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
+----+
4 rows in set (0.00 sec)
目標172.30.249.154表test.fader_link查數(shù)據(jù)
mysql> select * from test.fader_link;
ERROR 1296 (HY000): Got error 10000 'Error on remote system: 1054: Unknown column 'name' in 'field list'' from FEDERATED
找不到name列
1.本地的表結(jié)構(gòu)必須與遠程的完全一樣。
2.遠程數(shù)據(jù)庫目前僅限MySQL
3.不支持事務(wù)
4.不支持表結(jié)構(gòu)修改
關(guān)于FEDERATED存儲引擎實現(xiàn)oracle dblink功能及弊端分別是什么就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。