Monday, March 7, 2011

Get last MySQL binary log entry

I'm using MySQL replication, and I'd like a status script running on the slave to report the last statement that was replicated over to the slave.

I can use "SHOW SLAVE STATUS" to get the current read and execute positions. But how do I use that information with mysqlbinlog to read the last entry? Assuming the slave is caught up with the master, the following statement returns nothing useful:

mysqlbinlog.exe -R --start-position=<READ_MASTER_LOG_POS> <MASTER_LOG_FILE> -h <MASTER_HOST>

I can't seem to minus one from the log position to get the previous statement, and I don't see any way to give a negative offset meaning to read from the end in reverse order. Is there any way to do this?

Thanks!

From stackoverflow
  • Are you after the last statement that was sent to the slave, or the last statement that was executed on the slave? You mention that you're assuming the slave is caught up with the master, in which case you simply need to read the last statement in the relay log instead, with the information available in SHOW SLAVE STATUS:

    mysqlbinlog.exe --start-position=<RELAY_LOG_POS> <RELAY_LOG_FILE>
    

0 comments:

Post a Comment