Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last MySQL binary log entry

Tags:

mysql

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 Answers

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>
like image 89
Gary Pendergast Avatar answered Feb 14 '26 23:02

Gary Pendergast



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!