MySQL 5.6主從複製第四部分[一些被忽視的操作細節]
1. STOP SLAVE
從伺服器上負責同步的有二類線程:
1) IO thread
2) SQL thread
IO thread負責擷取master上的binary log, 然後多個sql threads負責執行。
IO thread 決定了Retrieved_Gtid_Set
SQL thread 決定了Executed_Gtid_Set
由於IO thread先於SQL thread,Retrieved_Gtid_Set可能會略多於Executed_Gtid_Set。
比如:
mysql [localhost] {msandbox} (test) > SHOW slave STATUS \G
.......
.......
Retrieved_Gtid_Set: 67cd9435-7cae-11e2-aa8d-00241db92e69:1-9
Executed_Gtid_Set: 67cd9435-7cae-11e2-aa8d-00241db92e69:1-7
Auto_Position: 1
所以,在stop slave的時候,正確的操作是:
1) stop slave io_thread;
2) show slave status 確定Executed_Gtid_Set趕上了Retrieved_Gtid_Set
3) stop slave sql_thread.
2.flush tables with read lock 與 show slave status
在一台完全正常的從伺服器上開一個session 1:
mysql> flush tables with read lock;
如果主伺服器有更新,
在此從伺服器上再開一個session2:
mysql> show slave status,將會卡住, 直到在session1中執行unlock tables。
如果show slave status也是在session 1中執行的, 那麼就沒辦法恢複了。。。。
mysql [localhost] {msandbox} (test) > flush tables with read lock;
Query OK, 0 rows affected (0.01 sec)
//這時主伺服器發生了更新操作。
mysql [localhost] {msandbox} (test) > show slave status;
卡在這裡…
當然ctrl+c可以取消,
Ctrl-C — sending “KILL QUERY 1″ to server …
Ctrl-C — query aborted.
Ctrl-C — sending “KILL 1″ to server …
Ctrl-C — query aborted.
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql [localhost] {msandbox} (test) >
即使這時再unlock tables也沒有用。。早已經中斷連線了。。
mysql [localhost] {msandbox} (test) > unlock tables;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 14
Current database: test
Query OK, 0 rows affected (0.01 sec)
而且現在mysqld都無法stop了…
[modify@H209 msb_5_6_10_b]$ ./stop
Warning; Aborted waiting on pid file: ‘/home/modify/sandboxes/msb_5_6_10_b/data/mysql_sandbox5612.pid’ after 190 seconds
Attempting normal termination — kill -15 10858
所以在 flush tables with read lock 之前,要先stop slave…
http://bugs.mysql.com/?id=68460
MySQL 5.6主從複製第一部分[簡介及配置]
MySQL 5.6主從複製第二部分[恢複某一台從伺服器]
MySQL 5.6主從複製第三部分[把從伺服器提升為主伺服器]
MySQL 5.6主從複製第四部分[一些被忽視的操作細節]
MySQL 主從複製事件校正 MySQL Replication Event Checksum
使用pt-table-checksum檢查主從複製是否正常