MySQL 是最流行的关系型数据库管理系统,MySQL 配置主备模式,基于一台服务器的数据复制,故得名单机热备,主-备 Active-Standby主-备方式,即指的是一台服务器处于某种业务的激活状态(即Active状态),另一台服务器处于该业务的备用状态(即Standby状态),主数据库数据更新后,备份服务器同步数据只本机。
[root@localhost ~]# source /etc/profile [root@localhost ~]# java -version java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
3.此步骤需要进入每一个数据库创建授权用户,也就是给MyCAT准备的使用数据库的授权用户.
[root@localhost ~]# mysql -uroot -p Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
[root@localhost~]# mysql -uroot -p123456 -h 127.0.0.1-P 9066
Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MySQL connection id is2 Server version: 5.6.29-mycat-1.6.5-release-20180122220033 MyCat Server (monitor)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
MySQL [(none)]>show @@heartbeat; #RS_CODE为1表示心跳正常 +---------+-------+--------------+------+---------+-------+--------+---------+--------------+---------------------+-------+ | NAME | TYPE | HOST | PORT | RS_CODE | RETRY | STATUS | TIMEOUT | EXECUTE_TIME | LAST_ACTIVE_TIME | STOP | +---------+-------+--------------+------+---------+-------+--------+---------+--------------+---------------------+-------+ | Master1 | mysql |192.168.1.11|3306|-1|0| idle |0|0,16,16|2018-12-2101:29:43|false| | Slave1 | mysql |192.168.1.12|3306|-1|0| idle |0|34,31,31|2018-12-2101:29:43|false| | Slave2 | mysql |192.168.1.13|3306|-1|0| idle |0|1,16,16|2018-12-2101:29:43|false| +---------+-------+--------------+------+---------+-------+--------+---------+--------------+---------------------+-------+ 3rowsinset (0.00 sec)
MySQL [(none)]>show @@datasource; #查看读写分离的机器配置情况 +----------+---------+-------+--------------+------+------+--------+------+------+---------+-----------+------------+ | DATANODE | NAME | TYPE | HOST | PORT | W/R | ACTIVE | IDLE | SIZE |EXECUTE| READ_LOAD | WRITE_LOAD | +----------+---------+-------+--------------+------+------+--------+------+------+---------+-----------+------------+ | dn_test | Master1 | mysql |192.168.1.11|3306| W |0|0|1000|0|0|0| | dn_test | Slave1 | mysql |192.168.1.12|3306| R |0|0|1000|0|0|0| | dn_test | Slave2 | mysql |192.168.1.13|3306| R |0|0|1000|0|0|0| +----------+---------+-------+--------------+------+------+--------+------+------+---------+-----------+------------+ 3rowsinset (0.01 sec)
MySQL [(none)]>
8.登录MyCat代理端,测试读写分离服务.
[root@localhost ~]# mysql -uroot -p123456 -h127.0.0.1 -P 8066
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.29-mycat-1.6.5-release-20180122220033 MyCat Server (OpenCloundDB)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MySQL [(none)]> MySQL [(none)]> MySQL [(none)]> MySQL [(none)]> show databases; +----------+ | DATABASE | +----------+ | MyCatDB | +----------+ 1 row inset (0.00 sec)