鍍金池/ 問答/Linux  數(shù)據(jù)庫/ 求教,mysql主從復制,主表插入數(shù)據(jù)后,從表未同步,且狀態(tài)異常

求教,mysql主從復制,主表插入數(shù)據(jù)后,從表未同步,且狀態(tài)異常

問題大概是這樣的:mysql主從復制,配置好之后,查看從表狀態(tài)正常:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
然后在主表插入數(shù)據(jù),從表未同步,狀態(tài)異常:
Slave_IO_Running: Yes
Slave_SQL_Running: No

具體情況如下:
主庫在windows上,從庫在虛擬機上;
主庫配置 my.ini

[mysqld] 
# 主從配置
# 日志文件名以“mysql-bin”作為前綴
log-bin=mysql-bin
server-id=1
binlog-do-db=blog

從庫配置 my.cfg

[mysqld]
server-id = 2
port = 3306
log-bin=mysql-bin
binlog_format=mixed

windows執(zhí)行show master status;顯示如下

+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000035 |     1253 | blog         |                  |                   |
+------------------+----------+--------------+------------------+-------------------+

虛擬機執(zhí)行

stop slave;

CHANGE MASTER TO MASTER_HOST='192.168.1.110', 
MASTER_USER='root', 
MASTER_PASSWORD='root',
MASTER_LOG_FILE='mysql-bin.000035', 
MASTER_LOG_POS=1253;

start slave;

show slave status \G;

顯示如下

clipboard.png

紅色部分這里看著是沒問題的

然后在主表執(zhí)行一條insert語句之后,再執(zhí)行show slave status \G;命令后,
主表數(shù)據(jù)插入成功,從表未同步,且狀態(tài)異常:
Slave_IO_Running: Yes
Slave_SQL_Running: No

clipboard.png

last error 信息

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.

使用 mysqlbinlog relay-log.info查看日志看到如下錯誤
ERROR: File is not a binary log file.
請問可能是哪里出了問題?

回答
編輯回答
話寡

error意思是binlog不是二進制文件,你還是都用windows吧,從庫也在windows上好了。
或者都用docker,配起來快:repl,這個庫里我就放了一主一從。

2017年11月16日 12:57
編輯回答
浪蕩不羈

主庫是windows,從庫是Linux嗎?

2018年7月27日 09:30
編輯回答
悶騷型

修改你從庫的binlog_format=mixed改成row格式,mixed造成的問題比較多,因為沒看到你的版本和主庫的binlog_format信息,所以如果主庫的binlog格式也是mixed或者statment格式,建議都改成row格式。
ps:推薦還是使用linux下的mysql。

2017年7月14日 01:50
編輯回答
負我心

解決了,是因為mysql版本不一致造成的,主庫是windows的5.7版本,從庫是centos的5.5。
我判斷是因為從庫mysql的mysqlbinlog版本太低,無法讀取主庫的binlog日志,導致無法同步

2017年1月4日 04:08