MySQL主主互備不同步的解決方法


MySQL主主互備不同步

首先在服務器上執行show slave satus;可以看到很多同步的參數: 

Master_Log_File: SLAVE中的I/O線程當前正在讀取的主服務器二進制日志文件的名稱
Read_Master_Log_Pos: 在當前的主服務器二進制日志中,SLAVE中的I/O線程已經讀取的位置
Relay_Log_File: SQL線程當前正在讀取和執行的中繼日志文件的名稱
Relay_Log_Pos: 在當前的中繼日志中,SQL線程已讀取和執行的位置
Relay_Master_Log_File: 由SQL線程執行的包含多數近期事件的主服務器二進制日志文件的名稱
Slave_IO_Running: I/O線程是否被啟動並成功地連接到主服務器上
Slave_SQL_Running: SQL線程是否被啟動
Seconds_Behind_Master: 從屬服務器SQL線程和從屬服務器I/O線程之間的時間差距,單位以秒計

同步的整個過程反映到從服務器上,對應三套日志信息,可在從服務器上用如下命令查看:

mysql> SHOW SLAVE STATUS;

Master_Log_File & Read_Master_Log_Pos:下一個傳輸的主日志信息。

Relay_Master_Log_File & Exec_Master_Log_Pos:下一個執行的主日志信息。

Relay_Log_File & Relay_Log_Pos:下一個執行的中繼日志信息。

Mysql復制Relay log read failure 的問題

Mysql主從復制模式中,slave上報錯 “relay log read failure”,導致主從同步停止。

Last_SQL_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.

原因

報錯信息為從庫“無法讀取relay log 里的條目”,可能原因為master庫的binglog錯誤,或slave庫的中繼日志錯誤。或者為網絡問題及bug原因。一般是由於網絡故障或slave庫壓力過大,導致relay-log格式錯誤造成的。找到當前已經同步的時間點,重新設置主從同步,就會產生新的中繼日志,恢復正常。

解決方法

1.從"show slave status\G"的輸出中,找到如下信息:

Relay_Master_Log_File: dd-bin.002540 //slave庫已讀取的master的binlog

Exec_Master_Log_Pos: 950583017 //在slave上已經執行的position位置點

2.停掉slave,以slave已經讀取的binlog文件,和已經執行的position為起點,重新設置同步。會產生新的中繼日志,問題解決。(不需要指定host,user,password等,默認使用當前已經設置好的)

mysql>stop slave;

mysql>change master to master_log_file='dd-bin.002540',master_log_pos=950583017;

mysql>start slave;

Slave_IO_Running: No:“Could not find first log file name in binary log index file”的解決辦法

數據庫主從出錯:

Slave_IO_Running: No 一方面原因是因為網絡通信的問題也有可能是日志讀取錯誤的問題。

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

解決辦法:

1.從機器停止slave:mysql> slave stop;

2.到master機器登陸mysql:

​ 記錄master的bin的位置,例如:mysql> show mster status;
+-------------------+----------+--------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+-------------------------------------------+
| mysqld-bin.000010 | 106 | information_schema,mysql |
+-------------------+----------+--------------+-------------------------------------------+
日志為mysqld-bin.000010

3.刷新日志:mysql> flush logs;

4.因為刷新日志file的位置會+1,即File變成為:mysqld-bin.000011

5.馬上到slave執行

mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysqld-bin.000011',MASTER_LOG_POS=106;

mysql> slave start;

mysql> show slave status\G;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM