понедельник, 21 декабря 2015 г.

MySQL Replication issues.

1) MySQL Skip Duplicate Replication Errors


Normally MySQL replication will stop whenever there is an error running a query on the slave. This happens in order for us to be able to identify the problem and fix it, and keep the data consistent with the mater that has sent the query. You can skip such errors, even if this is not recommended, as long as you know really well what are those queries and why they are failing, etc.
For example you can skip just one query that is hanging the slave using:
1
mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;
There might be cases where you will want to skip more queries. For example you might want to skip all duplicate errors you might be getting (output from show slave status;):
1
"1062 | Error 'Duplicate entry 'xyz' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO ..."
If you are sure that skipping those errors will not bring your slave inconsistent and you want to skip them ALL, you would add to your my.cnf:
1
slave-skip-errors = 1062
As shown above in my example 1062 is the error you would want to skip, and from here we have: _ Error: 1062 SQLSTATE: 23000 (ER_DUP_ENTRY) Message: Duplicate entry ‘%s’ for key %d_
You can skip also other type of errors, but again don’t do this unless you understand very well what those queries are and what impact they have on your data:
1
slave-skip-errors=[err_code1,err_code2,...|all]
and for the error codes you can see them all here … (you will see them in your _show slave statu_s; also).
 
2)  Binlog has bad magic number (mysql error) 

My MySql server had the following lines in the error log:
 
121119 22:50:57  mysqld started
121119 22:50:57  InnoDB: Started; log sequence number 0 43655
121119 22:50:57 [ERROR] Binlog has bad magic number;  It's not a binary log file that can be used by this version of MySQL
121119 22:50:57 [ERROR] Can't init tc log
121119 22:50:57 [ERROR] Aborting

I fixed the problem by renaming the mysql-bin.index file:
 
mv mysql-bin.index mysql-bin.index-corrupt

This essentially takes the corrupt mysql-bin.index file out of service, causing mysql to create new one. All I can figure is that the original one got corrupted somehow. I really don’t have time to poke around and find out why today. Hope this helps somebody.
 

Комментариев нет:

Отправить комментарий

Примечание. Отправлять комментарии могут только участники этого блога.