Mysql读写分离主库新增表插入数据成功 从库失败

2020-11-18 17:01发布

问题:

Mysql读写分离配置完后,在主库已存在的表新增 插入删除数据 ,从库正常同步;但是如果在主库新增一个表,然后再此表中新增一条数据,从库不新增。
mysql版本:5.7
系统:linux 3.10.0-514.el7.x86_64

数据库配置文件my.inf内容如下:

......
[mysqld]
character_set_server=utf8 init_connect='SET NAMES utf8'
skip-name-resolve
slave_skip_errors=all
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
relay-log=mysql-relay-bin
server-id=65
symbolic-links=0
log-bin=mysql-bin
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
max_connections=1000
......

建表语句以及插数据语句如下:

--drop table test_tb;
create table test_tb(id VARCHAR(12));
INSERT INTO test_tb VALUES('11111');

日志报错如下:

2020-10-13T07:32:53.314874Z 59 [Warning] Slave SQL for channel '': Error executing row event: 'Unknown error 1146', Error_code: 1146
2020-10-13T07:33:03.349435Z 59 [Warning] Slave SQL for channel '': Error executing row event: 'Unknown error 1146', Error_code: 1146
2020-10-13T07:33:13.306841Z 59 [Warning] Slave SQL for channel '': Error executing row event: 'Unknown error 1146', Error_code: 1146
2020-10-13T07:33:23.326045Z 59 [Warning] Slave SQL for channel '': Error executing row event: 'Unknown error 1146', Error_code: 1146
2020-10-13T07:33:33.330658Z 59 [Warning] Slave SQL for channel '': Error executing row event: 'Unknown error 1146', Error_code: 1146
2020-10-13T07:38:06.289980Z 59 [Warning] Slave SQL for channel '': , Error_code: 1677
2020-10-13T07:38:35.495749Z 59 [Warning] Slave SQL for channel '': , Error_code: 1677
2020-10-13T07:43:32.364440Z 59 [Warning] Slave SQL for channel '': , Error_code: 1677
请问,这是什么原因导致的?该如何解决?

回答1:

使用mysqlbinlog 查看这个relay-log=mysql-relay-bin 目录下的日志文件。应该能看到更明细的异常日志



回答2:

从库执行sql drop table test_tb 报错,因为从库不存在 test_tb这个表