主人的快照是由以下创build的:
mysql> FLUSH TABLES WITH READ LOCK; shell> mysqldump --all-databases --master-data > dbname_`date +%F`.sql
这个转储文件被导入到从站(以--skip-slave-start选项--skip-slave-start ),没有错误:
shell> pv dbname_`date +%F`.sql | mysql -u root -p
但是在执行mysql> start slave;时候出现了以下错误mysql> start slave; :
Last_SQL_Errno: 1062 Last_SQL_Error: Error 'Duplicate entry '115846' for key 'PRIMARY'' on query. Default database: 'db'. Query: 'INSERT INTO request_posted (id, user_id, channel, message, link, picture, name, ...
主站上只有一个ID为115846的logging:
mysql> select count(*) from request_posted where id=115846; Current database: db +----------+ | count(*) | +----------+ | 1 | +----------+ 1 row in set (0.01 sec)
尝试跳过一些查询:
mysql> STOP SLAVE; mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; mysql> START SLAVE;
没有帮助。 我不想通过添加以下内容来跳过这些错误:
slave-skip-errors = 1062
到my.cnf文件,因为它可能会带来奴隶不一致。
什么可能是这个错误的原因?
UPDATE
这不是我通常安装mySQL复制的方式
您认为我不遵循该文档的哪些步骤?
我想知道如果你要设置整个configuration,而不是传递mysqldump命令,你是否会遇到同样的问题。
不,如果我也将主设备更改为相应的坐标,则正常工作。
我会尝试删除从站上的数据库,确保binlogs清除,然后重新启动。 还要检查主服务器上的问题表,以确保索引没有错误。
是删除(移动)所有的datadir足够? 我这样做,并得到相同的结果。
回复@Dmytro Leonenko
'在从站上显示从站状态\ G',以确保它正确configuration,MASTER_LOG_POS为0
导入后只显示“slave slave statug \ G”,但在“启动slave”之前。 可以给我们答案
我备份了datadir,全部删除并运行mysql_install_db ,导入转储文件,执行change master to这里的结果:
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Master_Host: xxxx Master_User: xx Master_Port: 3306 Connect_Retry: 60 Master_Log_File: Read_Master_Log_Pos: 4 Relay_Log_File: mysqld-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 0 Relay_Log_Space: 106 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: 1 row in set (0.00 sec)
我想知道为什么Master_Log_Pos是4?
什么尝试解决你的问题:
还要检查什么:
这个问题是由于在执行转储之前在运行中的生产服务器上设置主服务器(据我所知)。 所以,在master_log中写入的查询已经在驻留在从站上的数据上执行了。 我从来没有真正看到在MySQL网站或邮件列表上的解决scheme。 所以,我想出了以下解决scheme,解决了我的问题。
在奴隶:
mysql> STOP SLAVE; mysql> FLUSH PRIVILEGES; # dump likly included users too
主人:
mysql> RESET MASTER;
在奴隶:
mysql> RESET SLAVE; mysql> START SLAVE;
顺便说一下,我在奴隶旁边跑了一圈,
mysqldump -uROOTUSER -pROOTPASSWORD -hMYSQLMASTER.EXAMPLE.COM --all-databases --delete-master-logs | mysql -uROOTUSER -pROOTPASSWORD
我希望这可以帮助别人。
如果你不想要REDO的完整程序,一个很好的解决办法就是使用
STOP SLAVE; SET GLOBAL sql_slave_skip_counter=1; START SLAVE;
如果有太多这样的错误,一个好主意就是使用bash脚本自动化它。
参考: 修复重复input错误
我有确切的问题,并帮助xd的链接。 但该链接中的命令有语法错误,这里是我工作的版本:
while [ 1 ]; do if [ `mysql -uroot -ppassword -e"show slave status \G;" | grep "Duplicate entry" | wc -l` -eq 2 ] ; then mysql -uroot -ppassword -e"stop slave; set global sql_slave_skip_counter=1; start slave;"; fi; sleep 1; mysql -uroot -ppassword -e"show slave status\G"; done
它基本上检查是否有重复的input错误,并跳过这个事件从主。 并做一个循环。