Mysql – Is it possible to convert thesql binlog from statement format to row format


The mysql server online is of version 4.1, which doesn't support row-based binary log. Nevertheless, I need the row-based binlog. Can I use the binlog generated by old mysql and import it into another mysql of higher version that supports row-base binlog to get the row-based binlog?

Best Answer

You cannot convert a binlog to another version, but you import its SQL as long as have mysqlbinlog for version 4.1.

Simply do the following:

  • Run MySQL 4.1 version of mysqlbinlog against the MySQL 4.1 binlog, saving output to stmts.sql
  • Install MySQL 5.x with these in my.cnf
    • log-bin=mysql-bin
    • binlog-format=ROW
  • Login to MySQL 5.1 and run source stmts.sql

When done, the binlogs you see should be row-based.

Give it a Try !!!

Why can't you just convert ? The BINLOG Magic Number gets displaced with later versions.

I wrote about before

Every time you restart mysql, the next empty binlog is created. Each version of MySQL has a different size:

  • MySQL 5.6 : 120
  • MySQL 5.5 : 107
  • MySQL 5.1 : 106
  • MySQL 5.0 : 98

In light of this, generating binlogs from scratch is the best way to go.

UPDATE : Thanks to Michael's Comment, you have to preload the data the binlog came from into the MySQL 5.1 Instance.