Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sruthi's avatar

Database sync

How to synchronize local database with hosted database on button click in laravel?

0 likes
3 replies
Tray2's avatar

Depending on your setup there are a few ways to do this.

  • Use mysqldump to export the local database and then import it on the hosted.
  • Use binary loggin on the local machine and apply the logs to the hosted machine.
  • Set up mysql for replication

The code to do any of these with a button click you have to write your self.

If it's a onetime thing I'd do the mysqldump if you need to sync a few times a day you could use the binary method.

If you need to keep them synced all the time you need to use replication. http://www.clusterdb.com/mysql-cluster/get-mysql-replication-up-and-running-in-5-minutes

sruthi's avatar

@Tray2 thank you for the reply..how to do that binary loggin in laravel?

Tray2's avatar

It's something you setup in MySQL so that it stores the changes in a log. See the mysql manual on how to do this.

If these logs are stored in place where laravel can get to them then you should be able to push them onto your remote server. Then you can run some queue job on the remote machine to sync the machine.

This is highly experimental and nothing I've ever tried doing so it might not be possible.

This will only transfer changes done after you started logging so the old data needs to be exported with mysqldump and imported so you have the data in sync.

Please or to participate in this conversation.