tags:

views:

215

answers:

1

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!

+1  A: 

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>
Gary Pendergast