views:

426

answers:

3

It seems MySQL does not support the flag "NO_ WRITE_ TO_ BINLOG" for TRUNCATE. So I have to wait until delay is 0, then stop the replication, make the TRUNCATE of the table/s, reset the master, and then start replication again. Really painful. Any other suggestion?

A: 

TRUNCATE is pretty heavy-handed. Can you get by with just a DELETE query?

Neall
No, I have 6 DBs with more than 40 tables each and some tables have more than 5 million rows. Delete is just almost impossible. Thanks
+2  A: 

You can use the command to disable binary logging for a session to do what you want.

SET SQL_LOG_BIN = 0;
TRUNCATE TABLE ;
SET SQL_LOG_BIN = 1;

This does require that you have the SUPER privilege since you are effectively breaking replication by not sending the TRUNCATE to the slave.

Harrison Fisk
Great, Thanks much! You rock!
A: 

TRUNCATE is not to be used lightly, since it essentially just drops the data on the floor without logging the fact that it did it. It's transactionally unsafe and impossible to recover from, and as a result it's not compatible with replication. Even if you manage to use TRUNCATE in a replication setup, your replicated data will be corrupt, or at best invalid.

skaffman
Yes I know, Truncate is not a common sentence to use within replication. However in this particular case it works charming. Thanks!