mysql5.6主从复制出现报错有什么解决办法
本文主要给大家简单讲讲mysql5.6主从复制出现报错有什么解决办法,相关专业术语大家可以上网查查或者找一些相关书籍补充一下,这里就不涉猎了,我们就直奔主题吧,希望mysql5.6主从复制出现报错有什么解决办法这篇文章可以给大家带来一些实际帮助。
mysql5.6主从复制报错解决方法
1.Mysql数据库slave同步报错信息1366:
1.原因是数据库表的字符集和表中的字段的字符集不一致导致的
下面四分析过程和解决办法:
17030310:07:33 [ERROR] Error reading packet from server: Lost connection to MySQLserver during query ( server_errno=2013)
17030310:07:33 [Note] Slave I/O thread killed while reading event
17030310:07:33 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000009',position 398229335
17030310:07:38 [Note] Slave SQL thread initialized, starting replication in log'mysql-bin.000002' at position 54629541, relay log './mht-relay-bin.000004'position: 54629687
17030310:07:38 [ERROR] Slave SQL: Error 'Incorrect string value:'\xC2\xB7\xE5\x93\x88\xE5...' for column 'author' at row 1' on query. Defaultdatabase: 'mahtu'. Query: 'update `dr_mh_book` set `author` = '阿萨夫·哈努卡' ,`intro` = '<p> 现实主义者漫画,现实主义者主要是一部自传形式的故事。描述身为一名父亲和丈夫在一个饱受战争蹂躏的国家中抚养和照顾自己的家庭与孩子的难处。作者的叙事技巧十分出色,能够以一幅画完整说出别人整本书想表达的故事。同时画技也十分了得,画面中隐藏着很多幽默的小细节,但又不会给给人以凌乱感,往往能以意想不到的手法描绘出一个小故事。作品以一种幽默的的表达手法令读者感受到战争的残酷。作者很喜欢以美丽而无声的插图来展示身处一个受到战火摧残的国家之中所要面对的危险。这部作品恰似一扇明窗,让我们可以透过它来了解以色列这个我们并不熟悉的国家的现实状况,以
17030310:07:38 [Warning] Slave: Incorrect string value: '\xC2\xB7\xE5\x93\x88\xE5...'for column 'author' at row 1 Error_code: 1366
17030310:07:38 [ERROR] Error running query, slave SQL thread aborted. Fix theproblem, and restart the slave SQL thread with "SLAVE START". Westopped at log 'mysql-bin.000002' position 54629541
17030310:07:38 [Note] Slave I/O thread: connected to master'rep1@221.195.1.254:3306',replication started in log 'mysql-bin.000009' atposition 398229335
参考文档:http://www.cnblogs.com/zhoujinyi/p/4568663.html
表字段字符集和表字符集不一致导致mysql主从同步报错:1366
mysql>show create table dr_mh_book\G
***************************1. row ***************************
Table: dr_mh_book
CreateTable: CREATE TABLE `dr_mh_book` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
`url` varchar(100) DEFAULT NULL,
`fengmian` varchar(100) DEFAULT NULL,
`updatetime` varchar(20) DEFAULT NULL,
`tag` varchar(20) DEFAULT NULL,
`diqu` varchar(20) DEFAULT NULL,
`intro` text,
`pingyin` varchar(200) DEFAULT NULL,
`fpingyin` varchar(5) DEFAULT NULL,
`updatestatus` varchar(10) DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`author` varchar(50) CHARACTER SET gb2312DEFAULT NULL,
`createtime` int(11) DEFAULT NULL,
`fabutime` int(11) DEFAULT NULL,
`chapternum` int(11) DEFAULT NULL,
`isdown` int(2) unsigned zerofill DEFAULTNULL,
PRIMARY KEY (`id`),
KEY `index_name` (`name`)
)ENGINE=InnoDB AUTO_INCREMENT=34182 DEFAULT CHARSET=utf8mb4
1 row inset (0.00 sec)
修改表字段字符集:
参考资料:
http://www.2cto.com/database/201308/235153.html
在主库操作:
mysql>SELECT * FROM dr_mh_book WHERE `author`= '阿萨夫·哈努卡';
ERROR1267 (HY000): Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)for operation '='
mysql>alter table dr_mh_book change `author` `author` varchar(50) character setutf8mb4 DEFAULT NULL;
Query OK,6238 rows affected (0.20 sec)
Records:6238 Duplicates: 0 Warnings: 0
mysql>flush privileges;
Query OK,0 rows affected (0.00 sec)
mysql>SELECT * FROM dr_mh_book WHERE `author`= '阿萨夫·哈努卡';
Empty set(0.01 sec)
在从库操作:
mysql>SELECT * FROM dr_mh_book WHERE `author`= '阿萨夫·哈努卡';
ERROR1267 (HY000): Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and(utf8_general_ci,COERCIBLE) for operation '='
mysql>alter table dr_mh_book change `author` `author` varchar(50) character setutf8mb4 DEFAULT NULL;
Query OK,6238 rows affected (0.20 sec)
Records:6238 Duplicates: 0 Warnings: 0
mysql>flush privileges;
Query OK,0 rows affected (0.00 sec)
mysql>SELECT * FROM dr_mh_book WHERE `author`= '阿萨夫·哈努卡';
Empty set(0.01 sec)
到此出,数据库同步正常
http://blog.csdn.net/dqchouyang/article/details/50012203
2.mysql数据库slave同步报错1061
原因是主库上某表的索引已经在slave对应表上存在,主库继续同步到slave上,会提示slave上某表索引已经存在而导致同步报错。
下面是解决办法:
接下来又出现,主库上某表已经创建索引,但是从库已经创建了同样的索引,导致复制报错1061
在主库查看索引:
mysql>show index from mahtu.dr_mh_book;
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation |Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|dr_mh_book | 0 | PRIMARY | 1 | id | A | 5888 | NULL | NULL | | BTREE | | |
|dr_mh_book | 1 | index_name| 1 | name | A | 5888 | NULL | NULL | YES | BTREE | | |
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
从库报错:
Last_Errno: 1061
Last_Error: Error 'Duplicatekey name 'index_name'' on query. Default database: 'mahtu'. Query: 'ALTER TABLE`dr_mh_book`
ADD INDEX`index_name` (`name`)'
Last_Errno: 1061
Last_Error: Error 'Duplicatekey name 'index_book_name'' on query. Default database: 'mahtu'. Query: 'ALTERTABLE `dr_mh_chapter`
ADD INDEX`index_book_name` (`bookid`, `name`)'
在从库操作删除表索引:
mysql> drop index index_name on mahtu.dr_mh_book;
Query OK,0 rows affected (0.00 sec)
Records:0 Duplicates: 0 Warnings: 0
mysql>flush privileges;
mysql>show index from mahtu.dr_mh_book;
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation |Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|dr_mh_book | 0 | PRIMARY | 1 | id | A | 4170 | NULL | NULL | | BTREE | | |
|dr_mh_book | 1 | index_name | 1 | name | A | 245 | NULL | NULL | YES | BTREE | | |
+------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
到此同步正常,接下来又出现1366报错:
解决:
mysql 主库:
mysql>show create table dr_mh_chapter\G
***************************1. row ***************************
Table: dr_mh_chapter
CreateTable: CREATE TABLE `dr_mh_chapter` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`bookid` int(11) DEFAULT NULL,
`name` varchar(100) CHARACTER SET gbk DEFAULTNULL,
`url` varchar(100) DEFAULT NULL,
`imgstr` longtext,
`pingyin` varchar(200) DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`createtime` int(11) DEFAULT NULL,
`updatetime` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_book_name` (`bookid`,`name`)
)ENGINE=InnoDB AUTO_INCREMENT=574818 DEFAULT CHARSET=utf8mb4
1 row inset (0.00 sec)
mysql> alter table dr_mh_chapter change `name` `name` varchar(100) characterset utf8mb4 DEFAULT NULL;
Query OK,163079 rows affected (9.44 sec)
Records:163079 Duplicates: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show create table dr_mh_chapter\G
*************************** 1. row***************************
Table:dr_mh_chapter
Create Table: CREATE TABLE `dr_mh_chapter` (
`id` int(11) NOTNULL AUTO_INCREMENT,
`bookid` int(11)DEFAULT NULL,
`name` varchar(100)DEFAULT NULL,
`url` varchar(100)DEFAULT NULL,
`imgstr` longtext,
`pingyin`varchar(200) DEFAULT NULL,
`status` int(11)DEFAULT NULL,
`createtime` int(11)DEFAULT NULL,
`updatetime` int(11)DEFAULT NULL,
PRIMARY KEY (`id`),
KEY`index_book_name` (`bookid`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=574820 DEFAULTCHARSET=utf8mb4
1 row in set (0.00 sec)
从库上操作:
mysql> show create table dr_mh_chapter\G
*************************** 1. row***************************
Table: dr_mh_chapter
Create Table: CREATE TABLE `dr_mh_chapter` (
`id` int(11) NOTNULL AUTO_INCREMENT,
`bookid` int(11)DEFAULT NULL,
`name` varchar(100)CHARACTER SET gbk DEFAULT NULL,
`url` varchar(100)DEFAULT NULL,
`imgstr` longtext,
`pingyin`varchar(200) DEFAULT NULL,
`status` int(11)DEFAULT NULL,
`createtime` int(11)DEFAULT NULL,
`updatetime` int(11)DEFAULT NULL,
PRIMARY KEY (`id`),
KEY`index_book_name` (`bookid`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=494977 DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec)
mysql> alter tabledr_mh_chapter change `name` `name`varchar(100) character set utf8mb4 DEFAULT NULL;
Query OK, 126243 rows affected (12.34 sec)
Records: 126243 Duplicates: 0 Warnings: 0
mysql> show create table dr_mh_chapter\G
*************************** 1. row***************************
Table:dr_mh_chapter
Create Table: CREATE TABLE `dr_mh_chapter` (
`id` int(11) NOTNULL AUTO_INCREMENT,
`bookid` int(11)DEFAULT NULL,
`name` varchar(100)DEFAULT NULL,
`url` varchar(100)DEFAULT NULL,
`imgstr` longtext,
`pingyin`varchar(200) DEFAULT NULL,
`status` int(11)DEFAULT NULL,
`createtime` int(11)DEFAULT NULL,
`updatetime` int(11)DEFAULT NULL,
PRIMARY KEY (`id`),
KEY`index_book_name` (`bookid`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=494977 DEFAULTCHARSET=utf8mb4
1 row in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
参考文档:
http://blog.itpub.net/15456724/viewspace-682681/
3.mysql主从复制报错:1060
原因是slave上表字段重复
mysql从库报错:
[ERROR]Slave SQL: Error 'Duplicate column name 'isdown'' on query. Default database:'mahtu'. Query: 'ALTER TABLE `dr_mh_book`
ADD COLUMN`isdown` int(2) NULL AFTER`chapternum`', Error_code: 1060
17030312:27:09 [Warning] Slave: Duplicate column name 'isdown' Error_code: 1060
在主库查看此字段:desc dr_mh_book 此表字段存在
但是在从库查看词表此段desc dr_mh_book,此字段也存在
所以,报错原因是从库也有此字段,所以删除此表的字段
altertable mh_ecms_list drop column isdown;
flushprivileges;
主从同步正常
4.mysql同步报错1396
mysql 数据库主从同步报错
Last_Errno: 1396
Last_Error:Error 'Operation DROP USER failed for 'mhtuser'@'124.207.48.234'' on query.Default database: ''. Query: 'drop user 'mhtuser'@'124.207.48.234''
原因是主库删除从库上不存在的数据库用户导致的
解决办法:
mysql>stop slave;
mysql> set global sql_slave_skip_counter=1
mysql>start slave;
6.mysql主从复制报错1007
slave 上报错:
Last_SQL_Errno: 1007
Last_SQL_Error: Error 'Can'tcreate database 'wjw02'; database exists' on query. Default database: 'wjw02'.Query: 'create database wjw02'
Replicate_Ignore_Server_Ids:
原因是:
slave上早已经存在master上同名的的库,所以master上再次创建库,slave上会提示库已经存在,导致报错;
解决办法:
mysql>stop slave;
Query OK,0 rows affected (0.01 sec)
mysql>set global sql_slave_skip_counter=1;
Query OK,0 rows affected (0.00 sec)
mysql>start slave;
Query OK,0 rows affected (0.01 sec)
7.mysql主从复制报错1008
slave上提示:
Last_SQL_Errno:1008
Last_SQL_Error: Error 'Can'tdrop database 'wjw02'; database doesn't exist' on query. Default database:'wjw02'. Query: 'drop database wjw02'
原因是从库提前删除数据库wjw02,然后在master上再次删除wjw02库,slave上提示为wjw02库不存在,导致复制报错:
解决方法:
在slave上执行:
mysql>stop slave;
Query OK,0 rows affected (0.02 sec)
mysql>set global sql_slave_skip_counter=1;
Query OK,0 rows affected (0.05 sec)
mysql>start slave;
Query OK,0 rows affected (0.02 sec)
8.将slave_skip_errors=参数写入配置文件
.将slave_skip_errors=参数写入slave上的配置文件my.cnf
[root@localhost ~]# grep slave_skip_errors /etc/my.cnf
slave_skip_errors=1007,1008
[root@localhost ~]# /etc/init.d/mysqld restart
这样可以直接忽略slave同步报错信息
####注意:生产环境考虑到主从库数据的一致性,是不允许不分情况的set global sql_slave_skip_counter=1; slave_skip_errors 操作这样的参数来忽略错误的,如果遇到主从同步失败的话,就让他卡到那了,人工介入进行手动恢复故障
9.slave_exec_mode参数可以动态自动处理同步复制错误
注意:此参数的设置只能忽略错误1032和1062的错误。
mysql>show variables like 'slave_exec_mode';
+-----------------+--------+
|Variable_name | Value |
+-----------------+--------+
|slave_exec_mode | STRICT |
+-----------------+--------+
此参数默认是STRICT严格模式;
将该参数设置为IDEMPOTENT模式,slave同步出现1032错误(记录没找到)和1062错误(主键重复),就会自动跳过次错误,并且记录到错误日志里面,其实此参数和slave_skip_errors作用是一样的。
只不过slave_skip_errors参数必须写入配置文件my.cnf,重启mysql,然而IDEMPOTENT默认不需要重新启动slave的mysql服务。
mysql>set global slave_exec_mode='IDEMPOTENT';
Query OK,0 rows affected (0.05 sec)
mysql>show variables like 'slave_exec_mode';
+-----------------+------------+
|Variable_name | Value |
+-----------------+------------+
|slave_exec_mode | IDEMPOTENT |
+-----------------+------------+
1 row inset (0.00 sec)
mysql>stop slave;
Query OK,0 rows affected (0.00 sec)
mysql>start slave;
演示:
slave上操作:
mysql>select * from dr_user_info;
+----+----------------------------------+-------------+------------+--------+
| id |dev_id |tel | updatetime | pwd |
+----+----------------------------------+-------------+------------+--------+
| 20 |CFD0CCDA603705F35C8EE74427C9CC45 | 13713340729 | 1488174916 | 111111 |
| 21 |11713EA0EDAFC1113E9AB016471BBDCF | 18341732393 | 1487632768 | 111111 |
| 22 |C9DEBE883FF6C05A19D5C0487E9C9D63 | 18600271207 | 1488521317 | 111111 |
| 23 |D73C9DADAB3611D82B7D5CA11B62DBA1 | 18974748447 | 1491177725 | 111111 |
| 24 |qwertyuiop |18234123308 | 1491177726 | 666666 |
+----+----------------------------------+-------------+------------+--------+
5 rows inset (0.00 sec)
mysql>delete from dr_user_info where id=24;
在master上操作:
mysql>select * from dr_user_info;
+----+----------------------------------+-------------+------------+----------+
| id |dev_id | tel | updatetime | pwd |
+----+----------------------------------+-------------+------------+----------+
| 20 |CFD0CCDA603705F35C8EE74427C9CC45 | 13713340729 | 1488174916 | 111111 |
| 21 |11713EA0EDAFC1113E9AB016471BBDCF | 18341732393 | 1487632768 | 111111 |
| 22 |C9DEBE883FF6C05A19D5C0487E9C9D63 | 18600271207 | 1488521317 | 111111 |
| 23 |D73C9DADAB3611D82B7D5CA11B62DBA1 | 18974748447 | 1491177725 | 111111 |
| 24 |qwertyuiop |18234123308 | 1491177726 | 33333333 |
+----+----------------------------------+-------------+------------+----------+
5 rows inset (0.00 sec)
mysql>select * from dr_user_info;
+----+----------------------------------+-------------+------------+--------+
| id | dev_id | tel | updatetime | pwd |
+----+----------------------------------+-------------+------------+--------+
| 20 |CFD0CCDA603705F35C8EE74427C9CC45 | 13713340729 | 1488174916 | 111111 |
| 21 |11713EA0EDAFC1113E9AB016471BBDCF | 18341732393 | 1487632768 | 111111 |
| 22 |C9DEBE883FF6C05A19D5C0487E9C9D63 | 18600271207 | 1488521317 | 111111 |
| 23 |D73C9DADAB3611D82B7D5CA11B62DBA1 | 18974748447 | 1491177725 | 111111 |
+----+---------
在
mysql> show slave status\G
但是在slave上查看此时同步时,mysql的错误日志:
[root@localhost logs]# tail -1/data/mysql/logs/mysql-error.log
2017-05-1405:22:55 4707 [Warning] Slave SQL: Could not execute Delete_rows event on tabledr_brower_db.dr_user_info; Can't find record in 'dr_user_info', Error_code:1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master logmysql-bin.000010, end_log_pos 5298692, Error_code: 1032
10.mysql同步报错1062(主键重复)
slave上表记录重复,导致slave复制报错1062主键重复
查看某表的建表语句
mysql>show create table dr_user_info\G
***************************1. row ***************************
Table: dr_user_info
CreateTable: CREATE TABLE `dr_user_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dev_id` varchar(100) DEFAULT NULL,
`tel` varchar(20) DEFAULT NULL,
`updatetime` int(11) DEFAULT NULL,
`pwd` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
)ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8
mysql>select * from dr_user_info;
+----+----------------------------------+-------------+------------+--------+
| id |dev_id |tel | updatetime | pwd |
+----+----------------------------------+-------------+------------+--------+
| 20 |CFD0CCDA603705F35C8EE74427C9CC45 | 13713340729 | 1488174916 | 111111 |
| 21 |11713EA0EDAFC1113E9AB016471BBDCF | 18341732393 | 1487632768 | 111111 |
| 22 |C9DEBE883FF6C05A19D5C0487E9C9D63 | 18600271207 | 1488521317 | 111111 |
| 23 |D73C9DADAB3611D82B7D5CA11B62DBA1 | 18974748447 | 1491177725 | 111111 |
slave上表中插入一条记录
mysql> insert into dr_user_info(id,dev_id,tel,updatetime,pwd) values(24,'qwertyuiop','18234131383','1491177726','111111');
mysql>select * from dr_user_info;
+----+----------------------------------+-------------+------------+--------+
| id |dev_id |tel | updatetime | pwd |
+----+----------------------------------+-------------+------------+--------+
| 20 |CFD0CCDA603705F35C8EE74427C9CC45 | 13713340729 | 1488174916 | 111111 |
| 21 |11713EA0EDAFC1113E9AB016471BBDCF | 18341732393 | 1487632768 | 111111 |
| 22 |C9DEBE883FF6C05A19D5C0487E9C9D63 | 18600271207 | 1488521317 | 111111 |
| 23 |D73C9DADAB3611D82B7D5CA11B62DBA1 | 18974748447 | 1491177725 | 111111 |
| 24 | qwertyuiop | 18234131383 |1491177726 | 111111 |
在master上插入这个表同样的一条表记录:
insert into dr_user_info (id,dev_id,tel,updatetime,pwd)values (24,'qwertyuiop','18234131383','1491177726','111111');
在slave上擦看报错:
Last_SQL_Errno:1062
Last_SQL_Error: Could notexecute Write_rows event on table dr_brower_db.dr_user_info; Duplicate entry '24' for key 'PRIMARY', Error_code:1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master logmysql-bin.000010, end_log_pos 5295916
是主键重复导致的
解决办法是删除slave上表dr_user_info重复的id为24的记录
mysql>delete from dr_user_info where id=24;
mysql>stop slave;
Query OK,0 rows affected (0.01 sec)
mysql>start slave;
mysql>show slave status\G
解决主键重复,slave同步正常
11.在master上更新一条表记录然而在slave上找不到这条记录报错1032
演示:
slave上查看表记录
mysql> select * from dr_user_info;
+----+----------------------------------+-------------+------------+--------+
| id | dev_id | tel | updatetime | pwd |
+----+----------------------------------+-------------+------------+--------+
| 20 | CFD0CCDA603705F35C8EE74427C9CC45 | 13713340729 |1488174916 | 111111 |
| 21 | 11713EA0EDAFC1113E9AB016471BBDCF | 18341732393 |1487632768 | 111111 |
| 22 | C9DEBE883FF6C05A19D5C0487E9C9D63 | 18600271207 |1488521317 | 111111 |
| 23 | D73C9DADAB3611D82B7D5CA11B62DBA1 | 18974748447 |1491177725 | 111111 |
| 24 | qwertyuiop | 18234131383 |1491177726 | 111111 |
+----+----------------------------------+-------------+------------+--------+
5 rows in set (0.00 sec)
slave上删除记录24
mysql> delete from dr_user_info where id=24;
然后在master上删除dr_user_info表记录24
此时slave上同步报错:1032,提示slave上找不到表记录
Last_SQL_Errno:1032
Last_SQL_Error: Could notexecute Delete_rows event on table dr_brower_db.dr_user_info; Can't find recordin 'dr_user_info', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; theevent's master log mysql-bin.000010, end_log_pos 5296175
解决办法:
在master上查看mysql-bin.000010日志上的sql语句,分析出错处5296175,sql语句在干嘛
[root@localhost binlog]# mysqlbinlog --no-defaults -v -v--base64-output=DECODE-ROWS mysql-bin.000010 |grep -A '20' 5295947
#17051318:37:41 server id 1230445 end_log_pos5295947 CRC32 0x3abbe149 Xid =2363
COMMIT;
# at5295947
#17051318:56:31 server id 1230445 end_log_pos 5296027CRC32 0x4acf5867 Query thread_id=23 exec_time=0 error_code=0
SETTIMESTAMP=1494672991;
BEGIN
;
# at5296027
#17051318:56:31 server id 1230445 end_log_pos5296100 CRC32 0xd1d14129 Table_map: `dr_brower_db`.`dr_user_info` mapped to number 158
# at5296100
#17051318:56:31 server id 1230445 end_log_pos5296175 CRC32 0xf6405bec Delete_rows: table id 158 flags: STMT_END_F
### DELETE FROM `dr_brower_db`.`dr_user_info`
### WHERE
### @1=24
### @2='qwertyuiop'
### @3='18234131383'
### @4=1491177726
### @5='111111'
# at5296175
#17051318:56:31 server id 1230445 end_log_pos5296206 CRC32 0x8307d44e Xid =2390
COMMIT;
DELIMITER;
# End oflog file
红色字体提示在master上执行delete了删除表记录:24
所以此处的报错可以在slave上忽略跳过这个错误
mysql>stop slave;
Query OK,0 rows affected (0.01 sec)
mysql>set global sql_slave_skip_counter=1;
Query OK,0 rows affected (0.00 sec)
mysql>start slave;
Query OK,0 rows affected (0.01 sec)
解决此问题
####注意:如果是执行的update语句,此时slave同步报错1032的话,是不允许set global sql_slave_skip_counter=1;进行忽略这个错误的,建议查看binlog日志看下是卡在什么地方,然后在slave库上把这条不存在的记录insert,然后在start slave开启同步;
12.slave的中继日志relay-log损坏导致mysql同步报错
原因是当slave意外宕机时,有可能会损坏中继日志relay-log,再次开启同步复制时,报错信息如下:
解决办法:找到同步的binlog日志和pos点。然后重新同步,
提示:在mysql5.5版本及以上版本,已经考虑到slave宕机导致relay-log损坏的问题造成mysql同步失败。
即在slave的my.cnf配置文件中加入参数relay_log_recovery=1,就可以了
13. master上的server-id等于slave上的server-id
人为的失误在配置mysql主从复制时,的数值等于slave上的server-id的数值。
解决办法是:保证server-id的数值不一样
14.mysql主从复制报错:2003
Last_IO_Errno:2003
Last_IO_Error: error connectingto master 'rep@10.0.0.201:3306' - retry-time: 60 retries: 2
原因有多种,可能是slave上防火墙开启限制了3306端口,也可能是在slave上执行change master to 时,指定的连接复制数据库的账户和密码不对导致的。也可能是对端的master开启防火墙做了3306端口的的限制等,也有可能是云服务器之间网络的问题导致的
还有就是master上的my.cnf配置文件使用参数:binlog_ignore_db=mydb1,slave上的my.cn配置文件使用参数:replicate-ignore-db =mydb1,也可以导致mysql同步报错2003
master上:[root@localhost~]# grep wjw01 /etc/my.cnf
binlog_ignore_db= wjw01
[root@localhost~]# /etc/init.d/mysqld restart
slave上:
[root@localhost~]# grep wjw01 /etc/my.cnf
replicate-ignore-db= wjw01
[root@localhost~]# /etc/init.d/mysqld restart
Shuttingdown MySQL.... SUCCESS!
StartingMySQL... SUCCESS!
slave上的mysql错误日志:
[root@localhost~]# tail -3 /data/mysql/logs/mysql-error.log
2017-05-1415:59:54 5335 [Warning] Storing MySQL user name or password information in themaster info repository is not secure and is therefore not recommended. Pleaseconsider using the USER and PASSWORD connection options for START SLAVE; seethe 'START SLAVE Syntax' in the MySQL Manual for more information.
2017-05-1415:59:54 5335 [ERROR] Slave I/O: error reconnecting to master'rep@10.0.0.201:3306' - retry-time: 60 retries: 1, Error_code: 2003
2017-05-1416:00:54 5335 [Note] Slave: connected to master'rep@10.0.0.201:3306',replication resumed in log 'mysql-bin.000014' at position628
15.binlog_ignore_db引起的同步复制故障
一个网友的案例:
在mysql的master上采用binlog_ignore_db命令忽略了一个库以后,使用mysql –e 执行的所有的语句就不写入binlog了,原因是在进行主从复制时,有一个库不复制,查看了一下他的配置,binlog格式为row模式,跟他要了当时的sql语句:
mysql -e ‘create table db.tb like db.tb1’;
查看mysql的手册知道忽略某个数据库的复制有两个参数,一个是binlog_ignore_db,另一个是replicate-ignore-db,他们是有区别的:
binlog_ignore_db参数是设置在master上的,例如:binlog_ignore_db=test,那么针对test库下的所有的操作(增删改)都不会记录下来,这样slave上接受主库上的binlog时文件量就会减少,这样做好处是可以减少网络io,减少slave端I/O线程的I/O量,从而最大程度的优化复制性能,。但是也存在一个隐患,在下面会提到。
replicate-ignore-db是设置在slave上的replicate-ignore-db=test1,那么针对test1库下的所有的操作(增删改)都不会被sql线程执行,
结论:如果想在slave上忽略一个库的复制,最好不要采用binlog_ignore_db这个参数,使用replicate-ignore-db= db来代替
16.mysql5.5.19/mysql5.5.20同步的一个bug
当我们使用低版本的mysql5.1.43(slave)向高版本的mysql5.5.19(master)同步复制时,会遇到主机master上的mysql一直在重启。后面经过排查,得知低版本的mysql向高版本的mysql同步复制,只要同步的复制点指错,主机master的mysql服务就会一直重启,但是版本一致的就没有这样的现象。比如:master上的binlog和pos点是mysql-bin.000010 ,107
那么你在slave上执行如下操作:
change master TO master_LOG_FILE=’mysql-bin.000010’.master_LOG_POS=106,这样就会促发这个样的bug.,目前mysql5.5.25a版本以后这样的问题已经修复了
注释:mysql手册上介绍,mysql支持从高版本向低版本同步(即,低版本是master,高版本是slave,那么slave向master同步复制时是兼容的,没问题的)
但是反过来,就会出现问题。有其是字符集设置这一块。
mysql5.6主从复制出现报错有什么解决办法就先给大家讲到这里,对于其它相关问题大家想要了解的可以持续关注我们的行业资讯。我们的板块内容每天都会捕捉一些行业新闻及专业知识分享给大家的。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341