您的位置
主页 > 网站技术 > 数据库 > » 正文

MySQL中使用FREDATED引擎实现跨数据库服务器、跨实例访问(3)

来源: 锦尚中国 点击:


[root@rhel64a ~]# mysql -uroot -pxxx 
 
root@localhost[(none)]> show variables like 'version'; 
+---------------+--------+ 
| Variable_name | Value  | 
+---------------+--------+ 
| version       | 5.6.21 | 
+---------------+--------+ 
 
#查看是否支持FEDERATED引擎 
root@localhost[(none)]> select * from information_schema.engines where engine='federated'; 
+-----------+---------+--------------------------------+--------------+------+------------+ 
| ENGINE    | SUPPORT | COMMENT                        | TRANSACTIONS | XA   | SAVEPOINTS | 
+-----------+---------+--------------------------------+--------------+------+------------+ 
| FEDERATED | NO      | Federated MySQL storage engine | NULL         | NULL | NULL       | 
+-----------+---------+--------------------------------+--------------+------+------------+ 
 
root@localhost[(none)]> exit 
[root@rhel64a ~]# service mysql stop 
Shutting down MySQL..[  OK  ] 
#配置启用FEDERATED引擎 
[root@rhel64a ~]# vi /etc/my.cnf 
[root@rhel64a ~]# tail -7 /etc/my.cnf 
[mysqld] 
socket = /tmp/mysql3306.sock 
port = 3306 
pid-file = /var/lib/mysql/my3306.pid 
user = mysql 
server-id=3306/ 
federated         #添加该选项 
[root@rhel64a ~]# service mysql start 
Starting MySQL.[  OK  ] 
[root@rhel64a ~]# mysql -uroot -pxxx 
root@localhost[(none)]> select * from information_schema.engines where engine='federated'; 
+-----------+---------+--------------------------------+--------------+------+------------+ 
| ENGINE    | SUPPORT | COMMENT                        | TRANSACTIONS | XA   | SAVEPOINTS | 
+-----------+---------+--------------------------------+--------------+------+------------+ 
| FEDERATED | YES     | Federated MySQL storage engine | NO           | NO   | NO         | 
+-----------+---------+--------------------------------+--------------+------+------------+ 
 
root@localhost[(none)]> use test 
 
-- 创建基于FEDERATED引擎的表federated_engine 
root@localhost[test]> CREATE TABLE `federated_engine` ( 
    ->   `engine` varchar(64) NOT NULL DEFAULT '', 
    ->   `support` varchar(8) NOT NULL DEFAULT '', 
    ->   `comment` varchar(80) NOT NULL DEFAULT '' 
    -> ) ENGINE=FEDERATED DEFAULT CHARSET=utf8 
    -> CONNECTION='mysql://remote_user:xxx@192.168.1.131:3406/tempdb/tb_engine'; 
Query OK, 0 rows affected (0.00 sec) 
 
-- 下面是创建后表格式文件 
root@localhost[test]> system ls -hltr /var/lib/mysql/test 
total 12K 
-rw-rw---- 1 mysql mysql 8.5K Oct 24 08:22 federated_engine.frm 
 
--查询表federated_engine 
root@localhost[test]> select * from federated_engine limit 2; 
+------------+---------+---------------------------------------+ 
| engine     | support | comment                               | 
+------------+---------+---------------------------------------+ 
| MRG_MYISAM | YES     | Collection of identical MyISAM tables | 
| CSV        | YES     | CSV storage engine                    | 
+------------+---------+---------------------------------------+ 
 
--更新表federated_engine 
root@localhost[test]> update federated_engine set support='NO' where engine='CSV'; 
Query OK, 1 row affected (0.03 sec) 
Rows matched: 1  Changed: 1  Warnings: 0 
 
--查看更新后的结果 
root@localhost[test]> select * from federated_engine where engine='CSV'; 
+--------+---------+--------------------+ 
| engine | support | comment            | 
+--------+---------+--------------------+ 
| CSV    | NO      | CSV storage engine | 
+--------+---------+--------------------+ 

5、创建FEDERATED引擎表的链接方式

复制代码 代码如下:




首页  - 关于站长圈  - 广告服务  - 联系我们  - 关于站长圈  - 网站地图  - 版权声明