【MySQL】解決mysql的 1594 錯誤
對於主從架構的mysql,當發生主機斷電或者其他原因異常crash的時候, slave的容易發生讀取binlog出錯的問題,最常見的是
show slave status \G;
Master_Log_File: mysql-bin.000029
Read_Master_Log_Pos: 3154083
Relay_Log_File: relay-bin.000478
Relay_Log_Pos: 633
Relay_Master_Log_File: mysql-bin.000027
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1594
Last_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.
Skip_Counter: 0
Exec_Master_Log_Pos: 234663436
依據錯誤描述提示,顯然slave sql 程式讀取不到relay log。
解決該問題之前先了解幾個引數:
mysql的主從複製的原理可知,slave 的sql執行緒理論上來說是延遲於IO執行緒,show slave status 查詢時 Relay_Master_Log_File和Master_Log_File檔案顯示的不是同一個檔案。
Master_Log_File
The name of the master binary log file from which the I/O thread is currently reading.
slave的IO執行緒當前正在讀取的master二進位制日誌檔名。
Relay_Master_Log_File
The name of the master binary log file containing the most recent event executed by the SQL thread.
slave的Sql執行緒最近執行的master二進位制日誌檔名。(該檔案有可能是滯後於IO執行緒正在讀取的二進位制日誌檔案)
Read_Master_Log_Pos
The position in the current master binary log file up to which the I/O thread has read.
Exec_Master_Log_Pos
The position in the current master binary log file to which the SQL thread has read and executed, marking the start of the next transaction or event to be processed. You can use this value with the CHANGE MASTER TO statement's MASTER_LOG_POS option when starting a new slave from an existing slave, so that the new slave reads from this point. The coordinates given by (Relay_Master_Log_File, Exec_Master_Log_Pos) in the master's binary log correspond to the coordinates given by (Relay_Log_File, Relay_Log_Pos) in the relay log.
slave的Sql執行緒已經讀並且執行的master二進位制日誌檔案的位置,標記下一個被執行的事務或事件的開始位置。
你可以將該值應用於兩臺slave演變為主從結構的應用場景中,新的slave可以在change master to語句中使用該值作為master_log_pos選項的值。master二進位制日誌檔案的(Relay_Master_Log_File, Exec_Master_Log_Pos) 的座標對應於slave中繼日誌(Relay_Log_File,Relay_Log_Pos) 座標.
#!/bin/bash
#created by yangyi
[ -z "$1" ] && exit 0 || PORT=$1
repair_1594()
{
local portlist=$1
for my_port in $portlist
do
Last_SQL_Errno=$(mysql -uroot -h127.0.0.1 -P${my_port} -Ae"show slave status \G" 2>/dev/null | grep Last_SQL_Errno | awk '{print $2}' )
echo ${Last_SQL_Errno}
Master_Host=`mysql -uroot -h127.0.0.1 -P${PORT} -Ae"show slave status \G" | grep Master_Host |awk '{print $2}'`
Relay_Master_Log_File=`mysql -uroot -h127.0.0.1 -P${PORT} -Ae"show slave status \G" | grep Relay_Master_Log_File |awk '{print $2}'`
Exec_Master_Log_Pos=`mysql -uroot -h127.0.0.1 -P${PORT} -Ae"show slave status \G" | grep Exec_Master_Log_Pos |awk '{print $2}'`
sql="change master to master_host='${Master_Host}',master_port=$PORT, master_user='rep',master_password='yangyi@rac1',master_log_file='${Relay_Master_Log_File}',master_log_pos=${Exec_Master_Log_Pos};"
mysql -uroot -h127.0.0.1 -P$PORT -e " stop slave ; sleep 1; ${sql} ;start slave ;"
sleep 1
is_OK=`mysql -uroot -h127.0.0.1 -P$PORT -p123456 -e "show slave status \G"| grep Seconds_Behind_Master | awk '{print $2}'`
if [[ ${is_OK} -ge 0 ]];
then
echo "instance : $my_port is recovered !!!!'"
else
echo "instance : $my_port is not OK,PLS CHECK WITH MANUL !!!!'"
fi
done
}
repair_1594 $PORT
#created by yangyi
[ -z "$1" ] && exit 0 || PORT=$1
repair_1594()
{
local portlist=$1
for my_port in $portlist
do
Last_SQL_Errno=$(mysql -uroot -h127.0.0.1 -P${my_port} -Ae"show slave status \G" 2>/dev/null | grep Last_SQL_Errno | awk '{print $2}' )
echo ${Last_SQL_Errno}
Master_Host=`mysql -uroot -h127.0.0.1 -P${PORT} -Ae"show slave status \G" | grep Master_Host |awk '{print $2}'`
Relay_Master_Log_File=`mysql -uroot -h127.0.0.1 -P${PORT} -Ae"show slave status \G" | grep Relay_Master_Log_File |awk '{print $2}'`
Exec_Master_Log_Pos=`mysql -uroot -h127.0.0.1 -P${PORT} -Ae"show slave status \G" | grep Exec_Master_Log_Pos |awk '{print $2}'`
sql="change master to master_host='${Master_Host}',master_port=$PORT, master_user='rep',master_password='yangyi@rac1',master_log_file='${Relay_Master_Log_File}',master_log_pos=${Exec_Master_Log_Pos};"
mysql -uroot -h127.0.0.1 -P$PORT -e " stop slave ; sleep 1; ${sql} ;start slave ;"
sleep 1
is_OK=`mysql -uroot -h127.0.0.1 -P$PORT -p123456 -e "show slave status \G"| grep Seconds_Behind_Master | awk '{print $2}'`
if [[ ${is_OK} -ge 0 ]];
then
echo "instance : $my_port is recovered !!!!'"
else
echo "instance : $my_port is not OK,PLS CHECK WITH MANUL !!!!'"
fi
done
}
repair_1594 $PORT
exit 0
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-759567/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【MySQL】複製1594錯誤(從庫relaylog損壞)MySql
- mysql與php錯誤解決MySqlPHP
- mysql錯誤解決總結MySql
- service mysql start出錯,mysql啟動不了,解決mysql: unrecognized service錯誤MySqlZed
- MYSQL中 TYPE=MyISAM 錯誤的解決方法MySql
- 解決MySQL server has gone away錯誤的解決方案MySqlServerGo
- MySQL入門學習之——MySQL錯誤解決彙總MySql
- MySQL插入資料1366錯誤解決方案MySql
- MySQL錯誤Incorrect file format解決方案薦MySqlORM
- MySQL連線錯誤(10048)的解決方案MySql
- [轉]MySql錯誤程式碼1045的解決方案MySql
- 解決Mysql錯誤[1040]Too many connectionsMySql
- mysql insert語句錯誤問題解決MySql
- mysql master-slave複製錯誤[解決事例]MySqlAST
- Mysql出現連線錯誤解決辦法MySql
- 【Mysql】Last_SQL_Error: 1594MySqlASTError
- mysql 解決字符集錯誤 正確摘錄MySql
- MySQL資料庫常見錯誤及解決方案MySql資料庫
- MySQL常見錯誤分析與解決方法總結MySql
- 連線MySQL出現2013錯誤解決MySql
- mysql 發生系統錯誤1067的解決方法MySql
- 啟動mysql時報錯的解決(mysql 5.0.45 redhat as 43)MySqlRedhat
- Mysql錯誤集MySql
- MySQL 5.6 GTID常見錯誤解決一例MySql
- MySQL資料庫錯誤server_errno=2013的解決MySql資料庫Server
- 解決MySQL啟動時萬惡的1067錯誤(轉)MySql
- 解決MySQL啟動時萬惡的的“1067”錯誤(轉)MySql
- 解決mysql使用GTID主從複製錯誤問題MySql
- 【MySql】複製出現Slave_SQL_Running: No 錯誤解決MySql
- SQLyog連線MySQL8.0報2058錯誤的完美解決方法MySql
- navicat連線MySQL8.0.11報2059錯誤的解決方案MySql
- Mysql5.7錯誤日誌時間不對的解決辦法MySql
- MySQL 主從複製,常見的binlog錯誤及解決方法MySql
- MySQL 錯誤程式碼MySql
- MySQL 常見錯誤MySql
- MySQL error 錯 誤 碼MySqlError
- mysql 一個錯誤MySql
- mysql slave錯誤skipMySql