获取最后的MySQL二进制日志条目

时间:2022-01-26 06:59:26

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.

我正在使用MySQL复制,我希望在从服务器上运行的状态脚本报告最后一个被复制到从服务器的语句。

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:

我可以使用“SHOW SLAVE STATUS”来获取当前的读取和执行位置。但是如何在mysqlbinlog中使用该信息来读取最后一个条目?假设从属服务器遇到了主服务器,则以下语句不会返回任何有用的内容:

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 个解决方案

#1


1  

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:

您是在发送到从站的最后一个语句之后,还是在从站上执行的最后一个语句之后?你提到你假设奴隶被赶上了主人,在这种情况下,你只需要读取中继日志中的最后一个语句,并使用SHOW SLAVE STATUS中提供的信息:

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

#1


1  

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:

您是在发送到从站的最后一个语句之后,还是在从站上执行的最后一个语句之后?你提到你假设奴隶被赶上了主人,在这种情况下,你只需要读取中继日志中的最后一个语句,并使用SHOW SLAVE STATUS中提供的信息:

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