mysql搭建简单主从时的常见错误

1、主要原因是用户没有授权或masterIP写错

last io error: error connecting to master 'slave@172.25.250.155:3306' - retry-time: 60 retries: 6
slave_ io running: connecting

解决:检查自己的master服务器是否授权给slave用户,检查slave用户能否在其他服务器登录,检查,change 规则是否写错,主要是ip,用户,密码

2、原因是server-id冲突

   Slave_IO_Running: No
   和
   The slave I/O thread stops because master and slave have equal MySQL server ids;

解决:将master或slave服务器中,mysql的配置文件中的server-id值更改并重启服务

3、为数据库或表的建库建表语句冲突,可能是库或表已经存在。

 Last_SQL_Error: Error 'Table 'book' already exists' on query. Default database: 'mybook'. Query: 'create table book(id int,num int)'
 或
 Last_SQL_Error: Error 'Can't create database 'mybook'; database exists' on query. Default database: 'mybook'. Query: 'create database mybook'

解决:方法一:删除数据库或表(不推荐)

          方法二:停止slave后再跳过错误;可能需要执行多次

stop slave;
-- 设置跳过这个冲突语句
set global sql_slave_skip_counter=1;
start slave;

4、由于从库数据不一致时执行删除操作或在从库中执行了增删改操作

  Last_Error: Could not execute Delete_rows event on table mybook.book; Can't find record 
in 'book', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log 
mysqlmaster-bin-log.000003, end_log_pos 1707
或
 Could not execute Delete_rows event on table mysql.user; Can't find record in 'user',
 Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysqlmaster-
bin.000003, end_log_pos 2031

解决:

1、将主服务器的库进行完全备份

2、将备份在从库中恢复

3、重新构建主从

PS:master_log_file="xx",master_log_pos=xxx 来自备份时主服务的 show master status;

stop  slave;
reset slave all;
change master to master_host="主服务器IP",master_user="xxx",master_password="xxx",master_log_file="xx",master_log_pos=xxx;

start slave;