1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be consistent
【環境描述】
msyql5.6.14
【報錯資訊】
mysql的slave啟動時,error.log中出現Warning警告:
[Warning] Slave SQL: If a crash happensthis configuration does not guarantee that the relay log info will beconsistent, Error_code: 0
這條Warning資訊對Mysql和MySQL複製功能沒有任何影響。
【報錯原因】
MySQL5.6版本開始支援把master.info和relay-log.info的內容寫入到mysql庫的表中,
master.info--> mysql.slave_master_info
relay-log.info--> mysql. slave_relay_log_info
同時在MySQL5.6版本中,增加了 Slave crash-safe replication功能,為了保證mysql的replication能夠crash-safe,slave_master_info和slave_relay_log_info表必須使用事務型的儲存引擎(InnoDB),不要嘗試去手動修改這兩張表的內容。同時,Slave還要開啟relay_log_recovery功能。
【解決方案】
設定master_info_repository和relay_log_info_repository的值為TABLE,同時開啟relay_log_recovery功能。
修改/etc/my.cnf設定檔,添加以下3項:
master-info-repository=table # 可以使用set global 動態修改
relay-log-info-repository=table # 可以使用setglobal 動態修改
relay-log-recovery=1 # 唯讀參數,必須修改my.cnf重啟mysql
然後重啟mysql執行個體。
【參考資料】
l master.info和relay-log.info日誌
在複製的Slave節點上會建立兩個日誌,分別是master.infor和relay-log.info,位於datadir目錄中。在MySQL5.6和後續的版本中,可以通過設定master-info-file和relay-log-info-file參數來指定寫入到mysql的表中或者寫入檔案。
這兩個檔案中包含一些類似showslave status輸出的資訊,當slave啟動的時候會讀取master.info和relay-log.info檔案來確定從master讀取binary log和讀取relay log的資訊。
Slave的I/O線程負責更新維護master.info檔案,
master.info |
mysql.slave_master_info |
SHOW SLAVE STATUS Column |
Description |
1 |
Number_of_lines |
[None] |
Number of lines in the file |
2 |
Master_log_name |
Master_Log_File |
The name of the master binary log currently being read from the master |
3 |
Master_log_pos |
Read_Master_Log_Pos |
The current position within the master binary log that have been read from the master |
4 |
Host |
Master_Host |
The host name of the master |
5 |
User |
Master_User |
The user name used to connect to the master |
6 |
User_password |
Password (not shown by SHOW SLAVE STATUS) |
The password used to connect to the master |
7 |
Port |
Master_Port |
The network port used to connect to the master |
8 |
Connect_retry |
Connect_Retry |
The period (in seconds) that the slave will wait before trying to reconnect to the master |
9 |
Enabled_ssl |
Master_SSL_Allowed |
Indicates whether the server supports SSL connections |
10 |
Ssl_ca |
Master_SSL_CA_File |
The file used for the Certificate Authority (CA) certificate |
11 |
Ssl_capath |
Master_SSL_CA_Path |
The path to the Certificate Authority (CA) certificates |
12 |
Ssl_cert |
Master_SSL_Cert |
The name of the SSL certificate file |
13 |
Ssl_cipher |
Master_SSL_Cipher |
The list of possible ciphers used in the handshake for the SSL connection |
14 |
Ssl_key |
Master_SSL_Key |
The name of the SSL key file |
15 |
Ssl_verify_server_cert |
Master_SSL_Verify_Server_Cert |
Whether to verify the server certificate |
16 |
Heartbeat |
[None] |
Interval between replication heartbeats, in seconds |
17 |
Bind |
Master_Bind |
Which of the slave's network interfaces should be used for connecting to the master |
18 |
Ignored_server_ids |
Replicate_Ignore_Server_Ids |
The number of server IDs to be ignored, followed by the actual server IDs |
19 |
Uuid |
Master_UUID |
The master's unique ID |
20 |
Retry_count |
Master_Retry_Count |
Maximum number of reconnection attempts permitted Added in MySQL 5.6.1) |
Slave的SQL線程負責維護relay-log.info檔案,在MySQL5.6中relay-log.info包含檔案中的記錄數和複寫延遲的秒數。
relaylog.info |
slave_relay_log_info |
SHOW SLAVE STATUS |
Description |
1 |
Number_of_lines |
[None] |
Number of lines in the file or rows in the table |
2 |
Relay_log_name |
Relay_Log_File |
The name of the current relay log file |
3 |
Relay_log_pos |
Relay_Log_Pos |
The current position within the relay log file; events up to this position have been executed on the slave database |
4 |
Master_log_name |
Relay_Master_Log_File |
The name of the master binary log file from which the events in the relay log file were read |
5 |
Master_log_pos |
Exec_Master_Log_Pos |
The equivalent position within the master's binary log file of events that have already been executed |
6 |
Sql_delay |
SQL_Delay |
The number of seconds that the slave must lag the master |
設定master_info_repository和relay_log_info_repository參數:
SQL> stop slave;
SQL> set global master_info_repository=table;
SQL> set global relay_log_info_repository=table;
SQL> show variables like '%repository';
+--------------------------------------+---------+
| Variable_name | Value |
+--------------------------------------+---------+
| master_info_repository | TABLE |
| relay_log_info_repository | TABLE |
+--------------------------------------+----------+
查看向Master讀取日誌的情況:
SQL> select * from slave_master_info;
查看Slave的Relay日誌應用情況:
SQL> select * from slave_relay_log_info;
注意:
master.info和relay-log.info內的資料會有一定的延遲,取決於mysql把slave資訊刷到硬碟的時間,如果要獲得slave的即時資訊,可以查詢slave_master_info和slave_relay_log_info表,或者執行show slave status查看。
l master-info-repository
master-info-repository={ FILE | TABLE },預設值是FILE,這個參數用於設定Slave節點上把master的資訊寫入到物理檔案中還是寫入到mysql. slave_master_info表中。
如果設定為FILE,也是mysql的預設設定,Slave會在datadir/master.info檔案中記錄master的資訊,從MySQL5.6版本開始,建議使用TABLE模式。
l relay-log-info-reposity
relay-log-info-reposity=file|table,預設值是FILE,這個參數用於設定slave節點上把relay-log.info的資訊寫入到datadir/relay-log.info檔案或者mysql. slave_relay_log_info表。
如果設定為FILE,也是mysql的預設設定,Slave會在datadir/master.info檔案中記錄master的資訊,從MySQL5.6版本開始,建議使用TABLE模式。
l relay-log-recovery
relay-log-recover=0|1,預設值是0不開啟,該參數用於設定是否開啟relay log的自動回復功能。當開啟relay_log_recovery功能,slave資料庫在啟動的時候,會忽略未被執行的relay log,它會重新串連master擷取relay log來進行恢複。
當slave發生宕機的時候,建議開啟該功能,可以有效避免slave執行了relay log裡面的訛誤記錄。
如果開啟relay_log_recovery功能,必須同時把relay_log_info_reposity設定為TABLE模式。