您好,登錄后才能下訂單哦!
本文主要給大家簡單講講mysql5.6主從復(fù)制出現(xiàn)報(bào)錯(cuò)有什么解決辦法,相關(guān)專業(yè)術(shù)語大家可以上網(wǎng)查查或者找一些相關(guān)書籍補(bǔ)充一下,這里就不涉獵了,我們就直奔主題吧,希望mysql5.6主從復(fù)制出現(xiàn)報(bào)錯(cuò)有什么解決辦法這篇文章可以給大家?guī)硪恍?shí)際幫助。
1.原因是數(shù)據(jù)庫表的字符集和表中的字段的字符集不一致導(dǎo)致的
下面四分析過程和解決辦法:
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> 現(xiàn)實(shí)主義者漫畫,現(xiàn)實(shí)主義者主要是一部自傳形式的故事。描述身為一名父親和丈夫在一個(gè)飽受戰(zhàn)爭蹂躪的國家中撫養(yǎng)和照顧自己的家庭與孩子的難處。作者的敘事技巧十分出色,能夠以一幅畫完整說出別人整本書想表達(dá)的故事。同時(shí)畫技也十分了得,畫面中隱藏著很多幽默的小細(xì)節(jié),但又不會(huì)給給人以凌亂感,往往能以意想不到的手法描繪出一個(gè)小故事。作品以一種幽默的的表達(dá)手法令讀者感受到戰(zhàn)爭的殘酷。作者很喜歡以美麗而無聲的插圖來展示身處一個(gè)受到戰(zhàn)火摧殘的國家之中所要面對(duì)的危險(xiǎn)。這部作品恰似一扇明窗,讓我們可以透過它來了解以色列這個(gè)我們并不熟悉的國家的現(xiàn)實(shí)狀況,以 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
表字段字符集和表字符集不一致導(dǎo)致mysql主從同步報(bào)錯(cuò):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) 到此出,數(shù)據(jù)庫同步正常
http://blog.csdn.net/dqchouyang/article/details/50012203
原因是主庫上某表的索引已經(jīng)在slave對(duì)應(yīng)表上存在,主庫繼續(xù)同步到slave上,會(huì)提示slave上某表索引已經(jīng)存在而導(dǎo)致同步報(bào)錯(cuò)。
下面是解決辦法:
接下來又出現(xiàn),主庫上某表已經(jīng)創(chuàng)建索引,但是從庫已經(jīng)創(chuàng)建了同樣的索引,導(dǎo)致復(fù)制報(bào)錯(cuò)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 | | | +------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
從庫報(bào)錯(cuò):
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 | | | +------------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
到此同步正常,接下來又出現(xiàn)1366報(bào)錯(cuò):
解決:
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/
原因是slave上表字段重復(fù)
mysql從庫報(bào)錯(cuò): [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,此字段也存在 所以,報(bào)錯(cuò)原因是從庫也有此字段,所以刪除此表的字段 altertable mh_ecms_list drop column isdown; flushprivileges; 主從同步正常
mysql 數(shù)據(jù)庫主從同步報(bào)錯(cuò) 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'' 原因是主庫刪除從庫上不存在的數(shù)據(jù)庫用戶導(dǎo)致的 解決辦法: mysql>stop slave; mysql> set global sql_slave_skip_counter=1 mysql>start slave;
slave 上報(bào)錯(cuò):
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上早已經(jīng)存在master上同名的的庫,所以master上再次創(chuàng)建庫,slave上會(huì)提示庫已經(jīng)存在,導(dǎo)致報(bào)錯(cuò);
解決辦法:
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)
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'
原因是從庫提前刪除數(shù)據(jù)庫wjw02,然后在master上再次刪除wjw02庫,slave上提示為wjw02庫不存在,導(dǎo)致復(fù)制報(bào)錯(cuò):
解決方法:
在slave上執(zhí)行:
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)
.將slave_skip_errors=參數(shù)寫入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同步報(bào)錯(cuò)信息
####注意:生產(chǎn)環(huán)境考慮到主從庫數(shù)據(jù)的一致性,是不允許不分情況的set global sql_slave_skip_counter=1; slave_skip_errors 操作這樣的參數(shù)來忽略錯(cuò)誤的,如果遇到主從同步失敗的話,就讓他卡到那了,人工介入進(jìn)行手動(dòng)恢復(fù)故障
注意:此參數(shù)的設(shè)置只能忽略錯(cuò)誤1032和1062的錯(cuò)誤。
mysql>show variables like 'slave_exec_mode'; +-----------------+--------+ |Variable_name | Value | +-----------------+--------+ |slave_exec_mode | STRICT | +-----------------+--------+
此參數(shù)默認(rèn)是STRICT嚴(yán)格模式;
將該參數(shù)設(shè)置為IDEMPOTENT模式,slave同步出現(xiàn)1032錯(cuò)誤(記錄沒找到)和1062錯(cuò)誤(主鍵重復(fù)),就會(huì)自動(dòng)跳過次錯(cuò)誤,并且記錄到錯(cuò)誤日志里面,其實(shí)此參數(shù)和slave_skip_errors作用是一樣的。
只不過slave_skip_errors參數(shù)必須寫入配置文件my.cnf,重啟mysql,然而IDEMPOTENT默認(rèn)不需要重新啟動(dòng)slave的mysql服務(wù)。
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上查看此時(shí)同步時(shí),mysql的錯(cuò)誤日志:
[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
slave上表記錄重復(fù),導(dǎo)致slave復(fù)制報(bào)錯(cuò)1062主鍵重復(fù)
查看某表的建表語句
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上插入這個(gè)表同樣的一條表記錄:
insert into dr_user_info (id,dev_id,tel,updatetime,pwd)values (24,'qwertyuiop','18234131383','1491177726','111111');
在slave上擦看報(bào)錯(cuò):
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
是主鍵重復(fù)導(dǎo)致的
解決辦法是刪除slave上表dr_user_info重復(fù)的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 解決主鍵重復(fù),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 | 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
此時(shí)slave上同步報(bào)錯(cuò):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語句,分析出錯(cuò)處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 /* INT meta=0 nullable=0is_null=0 */ ### @2='qwertyuiop' /*VARSTRING(300) meta=300 nullable=1 is_null=0 */ ### @3='18234131383' /*VARSTRING(60) meta=60 nullable=1 is_null=0 */ ### @4=1491177726 /* INTmeta=0 nullable=1 is_null=0 */ ### @5='111111' /* VARSTRING(60)meta=60 nullable=1 is_null=0 */ # at5296175 #17051318:56:31 server id 1230445 end_log_pos5296206 CRC32 0x8307d44e Xid =2390 COMMIT/*!*/; DELIMITER; # End oflog file
紅色字體提示在master上執(zhí)行delete了刪除表記錄:24
所以此處的報(bào)錯(cuò)可以在slave上忽略跳過這個(gè)錯(cuò)誤
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)
解決此問題
####注意:如果是執(zhí)行的update語句,此時(shí)slave同步報(bào)錯(cuò)1032的話,是不允許set global sql_slave_skip_counter=1;進(jìn)行忽略這個(gè)錯(cuò)誤的,建議查看binlog日志看下是卡在什么地方,然后在slave庫上把這條不存在的記錄insert,然后在start slave開啟同步;
原因是當(dāng)slave意外宕機(jī)時(shí),有可能會(huì)損壞中繼日志relay-log,再次開啟同步復(fù)制時(shí),報(bào)錯(cuò)信息如下:
解決辦法:找到同步的binlog日志和pos點(diǎn)。然后重新同步,
提示:在mysql5.5版本及以上版本,已經(jīng)考慮到slave宕機(jī)導(dǎo)致relay-log損壞的問題造成mysql同步失敗。
即在slave的my.cnf配置文件中加入?yún)?shù)relay_log_recovery=1,就可以了
人為的失誤在配置mysql主從復(fù)制時(shí),的數(shù)值等于slave上的server-id的數(shù)值。
解決辦法是:保證server-id的數(shù)值不一樣
Last_IO_Errno:2003 Last_IO_Error: error connectingto master 'rep@10.0.0.201:3306' - retry-time: 60 retries: 2
原因有多種,可能是slave上防火墻開啟限制了3306端口,也可能是在slave上執(zhí)行change master to 時(shí),指定的連接復(fù)制數(shù)據(jù)庫的賬戶和密碼不對(duì)導(dǎo)致的。也可能是對(duì)端的master開啟防火墻做了3306端口的的限制等,也有可能是云服務(wù)器之間網(wǎng)絡(luò)的問題導(dǎo)致的
還有就是master上的my.cnf配置文件使用參數(shù):binlog_ignore_db=mydb1,slave上的my.cn配置文件使用參數(shù):replicate-ignore-db =mydb1,也可以導(dǎo)致mysql同步報(bào)錯(cuò)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錯(cuò)誤日志:
[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
一個(gè)網(wǎng)友的案例:
在mysql的master上采用binlog_ignore_db命令忽略了一個(gè)庫以后,使用mysql –e 執(zhí)行的所有的語句就不寫入binlog了,原因是在進(jìn)行主從復(fù)制時(shí),有一個(gè)庫不復(fù)制,查看了一下他的配置,binlog格式為row模式,跟他要了當(dāng)時(shí)的sql語句:
mysql -e ‘create table db.tb like db.tb1’;
查看mysql的手冊知道忽略某個(gè)數(shù)據(jù)庫的復(fù)制有兩個(gè)參數(shù),一個(gè)是binlog_ignore_db,另一個(gè)是replicate-ignore-db,他們是有區(qū)別的:
binlog_ignore_db參數(shù)是設(shè)置在master上的,例如:binlog_ignore_db=test,那么針對(duì)test庫下的所有的操作(增刪改)都不會(huì)記錄下來,這樣slave上接受主庫上的binlog時(shí)文件量就會(huì)減少,這樣做好處是可以減少網(wǎng)絡(luò)io,減少slave端I/O線程的I/O量,從而最大程度的優(yōu)化復(fù)制性能,。但是也存在一個(gè)隱患,在下面會(huì)提到。
replicate-ignore-db是設(shè)置在slave上的replicate-ignore-db=test1,那么針對(duì)test1庫下的所有的操作(增刪改)都不會(huì)被sql線程執(zhí)行,
結(jié)論:如果想在slave上忽略一個(gè)庫的復(fù)制,最好不要采用binlog_ignore_db這個(gè)參數(shù),使用replicate-ignore-db= db來代替
當(dāng)我們使用低版本的mysql5.1.43(slave)向高版本的mysql5.5.19(master)同步復(fù)制時(shí),會(huì)遇到主機(jī)master上的mysql一直在重啟。后面經(jīng)過排查,得知低版本的mysql向高版本的mysql同步復(fù)制,只要同步的復(fù)制點(diǎn)指錯(cuò),主機(jī)master的mysql服務(wù)就會(huì)一直重啟,但是版本一致的就沒有這樣的現(xiàn)象。比如:master上的binlog和pos點(diǎn)是mysql-bin.000010 ,107
那么你在slave上執(zhí)行如下操作:
change master TO master_LOG_FILE=’mysql-bin.000010’.master_LOG_POS=106,這樣就會(huì)促發(fā)這個(gè)樣的bug.,目前mysql5.5.25a版本以后這樣的問題已經(jīng)修復(fù)了
注釋:mysql手冊上介紹,mysql支持從高版本向低版本同步(即,低版本是master,高版本是slave,那么slave向master同步復(fù)制時(shí)是兼容的,沒問題的)
但是反過來,就會(huì)出現(xiàn)問題。有其是字符集設(shè)置這一塊。
mysql5.6主從復(fù)制出現(xiàn)報(bào)錯(cuò)有什么解決辦法就先給大家講到這里,對(duì)于其它相關(guān)問題大家想要了解的可以持續(xù)關(guān)注我們的行業(yè)資訊。我們的板塊內(nèi)容每天都會(huì)捕捉一些行業(yè)新聞及專業(yè)知識(shí)分享給大家的。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。