Mysql database offline-online synchronization

MySQLmysqlbinlog

I need to synchronize database on server with database of local server upon active internet connection.

For its implementation I execute mysqlbinlog utility to read transaction logs and write the transaction queries into a sql file

Thereafter I execute sql file on database server to apply transaction updates on database on server

But I need to fetch only latest transaction logs within specific time interval across multiple binary log files . Please assist me in its implementation

Best Answer

As per your requirement you're suggesting leads to this solution:

mysqlbinlog --start-datetime=<START_DATETIME> --stop-datetime=<STOP_DATETIME> binlog.xxx > binlog.xxx.sql

Though this is very much prone to corrupt your data and/or introduce inconsistency! Not recommended!

There can be multiple solutions to one problem, if you could share the scenario you would get a better solution.

For eg:

  • If you're planning to make application specific changes on development (local) server and want to push that to live, use version control to manage the SQLs and exec to live.

  • If it is only specific database, you can setup replication and only move replicate changes to that db (or even tables).