Centos 6.5 Mysql 5.7.11 双主双备

配置双主双备
192.168.31.66   master (slave)
192.168.31.67   slave  (master)
————————————————————————————————————————————————————————————————————

主master
========================================================================================================================================
192.168.31.66
   vim /etc/my.cnf
   log_bin = mysql-bin
   server_id = 66

重启Mysql服务
service mysqld restart

创建slave专用账户
mysql -u root -p  -e "GRANT REPLICATION SLAVE,RELOAD,SUPER ON*.* TO 'hz'@'192.168.31.67' IDENTIFIED BY 'Report@123';"

查询master的状态
mysql -u root -p -e "show master status"
Enter password:
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      770 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+

192.168.31.66 对端master
mysql -u root -p -e "change master to master_host='192.168.31.67',master_user='hz',master_password='Report@123',master_log_file='mysql-bin.000001',master_log_pos=462; start slave;"

检查从服务器的状态
mysql -u root -p -e "show slave status\G;"

注意一下两项同时为yes时为正常
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
========================================================================================================================================


备slave
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
192.168.31.67 slave
vim /etc/my.cnf
log_bin = mysql-bin
 server_id = 67

重启服务
service mysqld restart

创建备份用的专用账户:
mysql -u root -p  -e "GRANT REPLICATION SLAVE,RELOAD,SUPER ON*.* TO 'hz'@'192.168.31.66' IDENTIFIED BY 'Report@123';"

查询master的状态
mysql -u root -p -e "show master status"
Enter password:
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      462 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
 
配置192.168.31.67  slave 启动主从复制

mysql -u root -p -e "change master to master_host='192.168.31.66',master_user='hz',master_password='Report@123',master_log_file='mysql-bin.000001',master_log_pos=770; start slave;"

检查从服务器的状态
mysql -u root -p -e "show slave status\G;"

注意一下两项同时为yes时为正常
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

你可能感兴趣的:(Mysql)