I managed to do this by examining the log files using mysqlbinlog
.
Given the following master log position on mysql2
:
Master log file = mysql-bin.003151
Master log pos = 46678888
I opened the log file:
mysql2> mysqlbinlog mysql-bin.003151 | less
And searched for the position (46678888).
# at 46678861
#170301 12:15:33 server id 2 end_log_pos 46678888
Xid = 12652204449 COMMIT/*!*/;
# at 46678888
#170301 12:15:36 server id 2 end_log_pos 46678967
Query thread_id=414919 69 exec_time=1 error_code=0
SET TIMESTAMP=1488370536/*!*/; BEGIN /*!*/;
# at 46678967
The nearby line of SET TIMESTAMP=1488370536
looked like a good candidate to search for in the corresponding log on mysql1
. So I opened up the master log file on mysql1
(there were multiple to choose from, but I went with the one with the closest timestamp to that on the slave, you might have to try a few files):
mysql1> mysqlbinlog mysql-bin.002966 | less
And searched for SET TIMESTAMP=1488370536
. This is what I found:
# at 46236234
#170301 12:15:33 server id 2 end_log_pos 46236261
Xid = 88972150 COMMIT/*!*/;
# at 46236261
#170301 12:15:36 server id 2 end_log_pos 46236325
Query thread_id=414919 69 exec_time=1 error_code=0
SET TIMESTAMP=1488370536/*!*/; BEGIN /*!*/;
# at 46236325
I checked surrounding lines to ensure I'd got the right place and then used the corresponding end_log_pos
(in this case 46236261) as the new log position. Therefore my master log position on mysql1
is:
Master log file = mysql-bin.002966
Master log pos = 46236261
It's probably possible to automate this process somewhat, but to be honest it was very quick and easy to do it manually (and I don't expect to have to do again much if at all) - it's taken longer to write up the process than actually do it.