- 论坛徽章:
- 0
|
给大家普及一下,这个问题老外回答了:
应该用bin-log = MIXED,但是这样会跟使用ROW级别的场景冲突,因此我感觉使用Row级别的场景不能使用binlog来恢复数据。
MySQL binlog format dilemma?
up vote
3
down vote
favorite
MySQL version: 5.5.13
If I set binlog format to STATEMENT, I got the following warnings on the Master:
[Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave...
I also read the limitations of replicate stores procedures and functions: http://dev.mysql.com/doc/refman/ ... ograms-logging.html
But if I switch to MIXED, mysqld.log on the Slave shows:
[Warning] Slave SQL: Could not execute Update_rows event on table hdcn.sessions; Can't find record in 'sessions', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.003834, end_log_pos 602692401, Error_code: 1032
[Warning] Slave SQL: Could not execute Delete_rows event on table reportingdb.102_rpt_clickview; Can't find record in '102_rpt_clickview', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.003834, end_log_pos 725203511, Error_code: 1032
Looks like the MIXED binlog format causes the Master doesn't replicate completely to Slave.
I switched back to STATEMENT format. Can I ignore the unsafe warnings?
mysql-replication
share|improve this question
edited Sep 29 '11 at 4:09
asked Sep 29 '11 at 3:47
quanta
26.7k22687
2 Answers activeoldestvotes
up vote
2
down vote
accepted
I assume you did this on one setup without cleaning up the slave and setting it up from scratch.
As the error message for the statement based replication tells you your application used some commands which can't be replicated using statement based replication. An example is a query like
INSERT INTO t (t) VALUES(NOW())
where NOW() will return different values when executed on the master and on the slave.
By doing this you have different data on the master and slave. Which is bad as depending on your slave your clients will read different data and subsequent writes will change other data, so you end up with data which is even more different.
Now you switch over to mixed replication, which might use row-based replication for some statements. With RBR you really need the exact same data as it has a hard time to identify the rows which were changed and update them.
So what should you do? - Configure your master to use mixed logging and then setup the slave using a consistent snapshot.
share|improve this answer
answered Sep 29 '11 at 9:03
johannes
33019
I have a question: what is the safest way to switch replication format at runtime? How do I know if there is any temporary tables exist? – quanta Sep 29 '11 at 9:11
The safest way is to configure the master accordingly, create a consistent dump and create the slaves from that. – johannes Sep 29 '11 at 9:13
up vote
1
down vote
You must eliminate all chance of Inserts, Updates, open temp tables, etc...
on Slave(s):
stop slave;
flush tables with read lock;
on Master:
flush tables with read lock;
set global binlog_format='MIXED';
unlock tables;
on Slave(s):
unlock tables;
start slave; |
|