How to find the latest binlog file name and position in slave mysql?

1.5k Views Asked by At

as the title show, I don't know how to achieve it in an effective way.

the command show slave status only shows the binlog file name and position corresponding to master instead of slave.

One way to do is to use command show binary logs to get the latest row's Log_name, and then use command show binlog events in '{Log_name}' to get the latest row's Pos. But that's isn't effective, because I only to want to get the latest row for above commands.

Are there any more effective ways to achieve it?

1

There are 1 best solutions below

0
Georg Richter On

In MySQL you have to loop over the result set from SHOW BINARY LOGS. The names of the binary logs are stored in an index file, but not in INFORMATION_SCHEMA or PERFORMANCE_SCHEMA.

When executing SHOW BINARY LOGS MySQL reads and process the binary log index file in your data directory. It's usually named hostname-bin.index.

$> cat mozart-bin.index
.\mozart-bin.000001
.\mozart-bin.000002
.\mozart-bin.000003
...
.\mozart-bin.000113

MariaDB stores the latest binary log file and position in status variables binlog_snapshot_file/position, however this is not supported in MySQL.