1. 程式人生 > >mysql之 mysql 5.6不停機雙主一從搭建(活躍雙主一從基於日誌點復制)

mysql之 mysql 5.6不停機雙主一從搭建(活躍雙主一從基於日誌點復制)

stat 5.6 create 文件夾 eat ima send spec tar

環境說明:
版本 version 5.6.25-log
主1庫ip: 10.219.24.25
主2庫ip: 10.219.24.22
從1庫ip:10.219.24.26
os 版本: centos 6.7
已安裝熱備軟件:xtrabackup
防火墻已關

技術分享

雙主一從架構圖

補充:
主從復制原理: http://blog.csdn.net/zhang123456456/article/details/72972701
mysql 5.6安裝 :http://blog.csdn.net/zhang123456456/article/details/53608554
xtrabackup 安裝: http://blog.csdn.net/zhang123456456/article/details/72836184

整個流程:先搭建一主一從,然後反向搭建雙活,最後搭建一主一從

1、 主庫參數調整
-- 停止主庫mysql
[[email protected] ~]# service mysql stop
[[email protected] ~]# netstat -nltp|grep mysql|grep 3606
-- 主庫創建relay log目錄
[[email protected] full]# mkdir -p /data/mysql/relaylog/
[[email protected] full]# chown -R mysql:mysql /data/mysql/relaylog
-- 調整 my.cnf 參數
[[email protected]

/* */ ~]# cat /etc/my.cnf
[[email protected] full]# cat /etc/my.cnf
[client]
password = oracle
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
server-id=25
port = 3306
socket = /data/mysql/mysql.sock
character_set_server = utf8
character_set_client = utf8
collation-server=utf8_general_ci
lower_case_table_names = 1
max_connections = 1000
datadir = /data/mysql
log_bin = /data/mysql/binarylog/binlog
log_bin_index = /data/mysql/binarylog/binlog
log_slave_updates = 1
relay-log = /data/mysql/relaylog/relay
relay-log-index = /data/mysql/relaylog/relay
relay_log_purge = on
binlog_format = mixed
innodb_data_file_path = ibdata1:12M:autoextend
auto_increment_increment = 10
auto_increment_offset = 1
[mysql]
default-character-set = utf8

說明:
a、主庫必須配置的參數
server-id (主從的server-id必須不同)、log_bin、binlog_format、relay-log、relay-log-index、relay_log_purge、relay_log_purge
auto-increment-offset、auto-increment-increment

b、log-slave-updates 意思是,中繼日誌執行之後,這些變化是否需要計入自己的binarylog。 當你的B服務器需要作為另外一個服務器的主服務器的時候需要打開。 就是雙主互相備份,或者多主循環備份。 我們這裏需要, 所以打開。

c、auto-increment-offset、auto-increment-increment 兩個參數用於在 雙主(多主循環)互相備份。 因為每臺數據庫服務器都可能在同一個表中插入數據,如果表有一個自動增長的主鍵,那麽就會在多服務器上出現主鍵沖突。 解決這個問題的辦法就是讓每個數據庫的自增主鍵不連續。 上圖說是, 我假設需要將來可能需要10臺服務器做備份, 所以auto-increment-increment 設為10. 而 auto-increment-offset=1 表示這臺服務器的序號。 從1開始, 不超過auto-increment-increment。這樣做之後, 我在這臺服務器上插入的第一個id就是 1, 第二行的id就是 11了, 而不是2.(同理,在第二臺服務器上插入的第一個id就是2, 第二行就是12, 這個後面再介紹) 這樣就不會出現主鍵沖突了。 後面我們會演示這個id的效果。

-- 啟動主庫
[[email protected] ~]# mysqld_safe --defaults-file=/etc/my.cnf &
2、 從庫參數調整
-- 停止從庫mysql
[[email protected] ~]# service mysql stop
[[email protected] ~]# netstat -nltp|grep mysql|grep 3606
-- 調整 my.cnf 參數
[[email protected] ~]# cat /etc/my.cnf
[client]
password = oracle
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
server-id=22
port = 3306
socket = /data/mysql/mysql.sock
character_set_server = utf8
character_set_client = utf8
collation-server=utf8_general_ci
lower_case_table_names = 1
max_connections = 1000
datadir = /data/mysql
log_bin = /data/mysql/binarylog/binlog
log_bin_index = /data/mysql/binarylog/binlog
log_slave_updates = 1
relay-log = /data/mysql/relaylog/relay
relay-log-index = /data/mysql/relaylog/relay
relay_log_purge = on
auto_increment_increment = 10
auto_increment_offset = 2
[mysql]
default-character-set = utf8

說明:從庫必須配置的參數
server-id、log_bin、relay-log、relay_log_purge、auto-increment-offset、auto-increment-increment、relay_log_purge

3、 主庫備份
-- 主庫備份目錄
[[email protected] full]# pwd
/xtrabackup/full
-- 主庫 innobackupex 備份
[[email protected] ~]# innobackupex --user=root --password=oracle --port=3606 /xtrabackup/full/
170610 17:50:23 Backup created in directory ‘/xtrabackup/full/2017-06-10_17-50-19/‘
MySQL binlog position: filename ‘binlog.000010‘, position ‘120‘
....
170610 17:50:23 completed OK!
-- 查看備份 binlog編號 與 截止 position
[[email protected] 2017-06-10_17-50-19]# cat xtrabackup_binlog_info
binlog.000010 120

4、 從庫創建與主庫相同的備份目錄
[[email protected] ~]# mkdir -p /xtrabackup/full
[[email protected] ~]# chown -R mysql:mysql /xtrabackup/full/

5、 主庫將備份 scp 到從庫
[[email protected] full]# pwd
/xtrabackup/full
[[email protected] full]# scp -r 2017-06-10_17-50-19 10.219.24.22:/xtrabackup/full
6、 從庫查看scp過來的備份
[[email protected] ~]# cd /xtrabackup/full/2017-06-10_17-50-19/
[[email protected] 2017-06-10_17-50-19]# ll
total 12320
-rw-r-----. 1 root root 419 Jun 10 18:01 backup-my.cnf
-rw-r-----. 1 root root 12582912 Jun 10 18:01 ibdata1
drwxr-x---. 2 root root 4096 Jun 10 18:01 mysql
drwxr-x---. 2 root root 4096 Jun 10 18:01 performance_schema
drwxr-x---. 2 root root 4096 Jun 10 18:01 test
-rw-r-----. 1 root root 18 Jun 10 18:01 xtrabackup_binlog_info
-rw-r-----. 1 root root 113 Jun 10 18:01 xtrabackup_checkpoints
-rw-r-----. 1 root root 482 Jun 10 18:01 xtrabackup_info
-rw-r-----. 1 root root 2560 Jun 10 18:01 xtrabackup_logfile

7、 主庫創建同步用戶
mysql> GRANT replication slave ON *.* TO [email protected]%‘ IDENTIFIED BY ‘oracle‘;
Query OK, 0 rows affected (0.05 sec)

8、 從庫恢復主庫數據
-- 從庫將原有datadir文件夾重命名到新位置,並創建原文件夾
[[email protected] ~]# mv /data/mysql /data/mysqlbak
[[email protected] ~]# mkdir -p /data/mysql
-- innobackupex apply-log
[[email protected] ~]# innobackupex --apply-log --user=oracle \
--password=oracle --port=3606 /xtrabackup/full/2017-06-10_17-50-19/
-- innobackupex copy 恢復的文件到原來的數據位置
[[email protected] mysql]# innobackupex --defaults-file=/etc/my.cnf --user=root \
--copy-back /xtrabackup/full/2017-06-10_17-50-19/

170610 18:25:11 completed OK!
-- 創建binlog目錄與 relaylog 目錄並賦權
[[email protected] ~]# mkdir -p /data/mysql/binarylog
[[email protected] ~]# mkdir -p /data/mysql/relaylog/
[[email protected] mysql]# chown -R mysql:mysql /data/mysql

9、 從庫配置與檢測
-- 從庫啟動
[[email protected] mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
-- 從庫指定與主庫同步的基本信息
mysql>
change master to
master_host=‘10.219.24.25‘,
master_port=3306,
master_user=‘slave25‘,
master_password=‘oracle‘,
master_log_file=‘binlog.000010‘,
master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

參數解釋:
MASTER_HOST : 設置要連接的主服務器的ip地址
MASTER_USER : 設置要連接的主服務器的用戶名
MASTER_PASSWORD : 設置要連接的主服務器的密碼
MASTER_LOG_FILE : 設置要連接的主服務器的bin日誌的日誌名稱
MASTER_LOG_POS : 設置要連接的主服務器的bin日誌的記錄位置

-- 啟動slave 狀態(開始監聽msater的變化)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
-- 查看slave的狀態.
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.219.24.25
Master_User: slave25
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000017
Read_Master_Log_Pos: 217
Relay_Log_File: relay.000002
Relay_Log_Pos: 377
Relay_Master_Log_File: binlog.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 217
Relay_Log_Space: 540
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 25
Master_UUID: 29d68531-4cf9-11e7-8e1f-000c297c4100
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 29d68531-4cf9-11e7-8e1f-000c297c4100:1-4
Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

10、 主從同步檢查
-- 主庫
mysql> create database repl;
Query OK, 1 row affected (0.00 sec)
mysql> use repl
Database changed
mysql> create table repl (id int);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into repl values(1);
Query OK, 1 row affected (0.00 sec)

-- 從庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| binarylog |
| mysql |
| performance_schema |
| relaylog |
| repl |
| test |
+--------------------+
7 rows in set (0.00 sec)
mysql> use repl
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from repl;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec) >一主一從同步成功!

##################################################
#至此A到B的復制已經配置完成,下面配置從B到A的復制。#
##################################################

聲明> 下面操作中 新主庫即為原從庫(10.219.24.22) 新從庫為原主庫(10.219.24.25)

11、 新主庫創建同步用戶
mysql> GRANT replication slave ON *.* TO [email protected]%‘ IDENTIFIED BY ‘oracle‘;
Query OK, 0 rows affected (0.00 sec)

12、 新主庫查看 binlog 文件號與 position 點
mysql> show master status;
+---------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000010 | 120 | | | 29d68531-4cf9-11e7-8e1f-000c297c4100:1-4 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)

13、 新從庫指定與主庫同步的基本信息
mysql>
change master to
master_host=‘10.219.24.22‘,
master_port=3306,
master_user=‘slave22‘,
master_password=‘oracle‘,
master_log_file=‘binlog.000010‘,
master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

14、新從庫打開 slave 復制功能
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
15、 新從庫檢測同步復制狀態
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.219.24.22
Master_User: slave22
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000010
Read_Master_Log_Pos: 120
Relay_Log_File: relay.000002
Relay_Log_Pos: 280
Relay_Master_Log_File: binlog.000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 120
Relay_Log_Space: 443
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 22
Master_UUID: 70023652-4dc7-11e7-9360-000c2944297a
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 29d68531-4cf9-11e7-8e1f-000c297c4100:1-4
Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

-- 新從庫測試數據同步狀態
mysql> create database mm_repl;
Query OK, 1 row affected (0.00 sec)
mysql> use mm_repl;
Database changed
mysql> create table mm_repl(id int auto_increment,name varchar(10), primary key(id));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into mm_repl(name) values("andy"),("taoYe");
Query OK, 1 row affected (0.00 sec)
mysql> select * from mm_repl;
+----+-------+
| id | name |
+----+-------+
| 1 | andy |
| 11 | taoYe |
+----+-------+
2 rows in set (0.00 sec)
-- 新主庫測試數據同步狀態
mysql> select * from mm_repl;
+----+-------+
| id | name |
+----+-------+
| 1 | andy |
| 11 | taoYe |
+----+-------+
2 rows in set (0.00 sec)
mysql> insert into mm_repl(name) values("andy"),("taoYe");
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from mm_repl;
+----+-------+
| id | name |
+----+-------+
| 1 | andy |
| 11 | taoYe |
| 12 | andy |
| 22 | taoYe |
+----+-------+
4 rows in set (0.00 sec)
-- 新從庫檢查同步復制
mysql> select * from mm_repl;
+----+-------+
| id | name |
+----+-------+
| 1 | andy |
| 11 | taoYe |
| 12 | andy |
| 22 | taoYe |
+----+-------+
4 rows in set (0.00 sec) >主主同步測試成功

##################################################
#至此雙主復制已經配置完成,下面配置主A到從C的復制。#
##################################################

主1從1搭建:

1、 停止從庫mysql
[[email protected] ~]# service mysql stop
[[email protected] ~]# netstat -nltp|grep mysql|grep 3606

2、 從庫參數調整
-- 調整 my.cnf 參數
[[email protected] ~]# cat /etc/my.cnf
[[email protected] mysql]# cat /etc/my.cnf
[client]
password = oracle
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
server-id=26
port = 3306
socket = /data/mysql/mysql.sock
character_set_server = utf8
character_set_client = utf8
collation-server=utf8_general_ci
lower_case_table_names = 1
max_connections = 1000
datadir = /data/mysql
log_bin = /data/mysql/binarylog/binlog
log_bin_index = /data/mysql/binarylog/binlog
relay-log = /data/mysql/relaylog/relay
relay-log-index = /data/mysql/relaylog/relay
relay_log_purge = on
read-only = 1
[mysql]
default-character-set = utf8
說明:從庫必須配置的參數
server-id、log_bin、relay-log、read-only

3、 主庫備份
-- 主庫備份目錄
[[email protected] full]# pwd
/xtrabackup/full
-- 主庫 innobackupex 備份
[[email protected] ~]# innobackupex --user=root --password=oracle --port=3606 /xtrabackup/full/
170611 23:55:25 Backup created in directory ‘/xtrabackup/full/2017-06-11_23-55-20/‘
MySQL binlog position: filename ‘binlog.000017‘, position ‘980‘
....
170611 23:55:25 completed OK!
-- 查看備份 binlog編號 與 截止 position
[[email protected] 2017-06-11_23-55-20]# cat xtrabackup_binlog_info
binlog.000017 980

4、 從庫創建與主庫相同的備份目錄
[[email protected] ~]# mkdir -p /xtrabackup/full
[[email protected] ~]# chown -R mysql:mysql /xtrabackup/full/

5、 主庫將備份 scp 到從庫
[[email protected] full]# pwd
/xtrabackup/full
[[email protected] full]# scp -r 2017-06-11_23-55-20 10.219.24.26:/xtrabackup/full
6、 從庫查看scp過來的備份
[[email protected] ~]# cd /xtrabackup/full/2017-06-11_23-55-20/
[[email protected] 2017-06-11_23-55-20]# ll
total 12328
-rw-r-----. 1 root root 419 Jun 11 23:57 backup-my.cnf
-rw-r-----. 1 root root 12582912 Jun 11 23:57 ibdata1
drwxr-x---. 2 root root 4096 Jun 11 23:57 mm_repl
drwxr-x---. 2 root root 4096 Jun 11 23:57 mysql
drwxr-x---. 2 root root 4096 Jun 11 23:57 performance_schema
drwxr-x---. 2 root root 4096 Jun 11 23:57 repl
drwxr-x---. 2 root root 4096 Jun 11 23:57 test
-rw-r-----. 1 root root 18 Jun 11 23:57 xtrabackup_binlog_info
-rw-r-----. 1 root root 113 Jun 11 23:57 xtrabackup_checkpoints
-rw-r-----. 1 root root 482 Jun 11 23:57 xtrabackup_info
-rw-r-----. 1 root root 2560 Jun 11 23:57 xtrabackup_logfile

7、 主庫創建同步用戶
mysql> GRANT replication slave ON *.* TO [email protected]%‘ IDENTIFIED BY ‘oracle‘;
Query OK, 0 rows affected (0.05 sec)

8、 從庫恢復主庫數據
-- 從庫將原有datadir文件夾重命名到新位置,並創建原文件夾
[[email protected] ~]# mv /data/mysql /data/mysqlbak
[[email protected] ~]# mkdir -p /data/mysql
-- innobackupex apply-log
[[email protected] ~]# innobackupex --defaults-file=/etc/my.cnf --apply-log --user=oracle \
--password=oracle --port=3606 /xtrabackup/full/2017-06-11_23-55-20/
-- innobackupex copy 恢復的文件到原來的數據位置
[[email protected] mysql]# innobackupex --defaults-file=/etc/my.cnf --user=root \
--copy-back /xtrabackup/full/2017-06-11_23-55-20/
170610 18:25:11 completed OK!
-- 創建binlog目錄與 relaylog 目錄並賦權
[[email protected] ~]# mkdir -p /data/mysql/binarylog
[[email protected] ~]# mkdir -p /data/mysql/relaylog/
[[email protected] mysql]# chown -R mysql:mysql /data/mysql

9、 從庫配置與檢測
-- 從庫啟動
[[email protected] mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
-- 從庫指定與主庫同步的基本信息
mysql>
change master to
master_host=‘10.219.24.25‘,
master_port=3306,
master_user=‘slave26‘,
master_password=‘oracle‘,
master_log_file=‘binlog.000017‘,
master_log_pos=980;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

參數解釋:
MASTER_HOST : 設置要連接的主服務器的ip地址
MASTER_USER : 設置要連接的主服務器的用戶名
MASTER_PASSWORD : 設置要連接的主服務器的密碼
MASTER_LOG_FILE : 設置要連接的主服務器的bin日誌的日誌名稱
MASTER_LOG_POS : 設置要連接的主服務器的bin日誌的記錄位置
-- 啟動slave 狀態(開始監聽msater的變化)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
-- 查看slave的狀態.
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.219.24.25
Master_User: slave26
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000017
Read_Master_Log_Pos: 980
Relay_Log_File: relay.000002
Relay_Log_Pos: 280
Relay_Master_Log_File: binlog.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 980
Relay_Log_Space: 443
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 25
Master_UUID: 29d68531-4cf9-11e7-8e1f-000c297c4100
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

10、 整體測試
10.1 主1數據測試,看其他復制同步情況
-- 主1 創建
mysql> create database m1;
Query OK, 1 row affected (0.11 sec)
-- 主2 查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| binarylog |
| m1 |
| mm_repl |
| mysql |
| performance_schema |
| relaylog |
| repl |
| test |
+--------------------+
9 rows in set (0.00 sec)
-- 從1 查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| binarylog |
| m1 |
| mm_repl |
| mysql |
| performance_schema |
| relaylog |
| repl |
| test |
+--------------------+
9 rows in set (0.05 sec)

10.2 主2 創建數據,看其他復制同步情況
-- 主2 創建
mysql> use m1;
Database changed
mysql> create table andy(id int);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into andy values(1);
Query OK, 1 row affected (0.00 sec)
-- 主1 查看
mysql> use m1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from andy;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
-- 從1 查看
mysql> use m1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from andy;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec) >成功,雙主一從搭建成功!

mysql之 mysql 5.6不停機雙主一從搭建(活躍雙主一從基於日誌點復制)