indicolite / mysql-sync

☠ Syncs two mysql databases by only inserting/deleting/updating the necessary records.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mysql-sync

Syncs two mysql databases by only inserting/deleting/updating the necessary records.

Useful in cases where mysqldump generates gigabytes of data

##Usage:

mysql-sync [source-dsn] [target-dsn]

dsn being username:password@hostname:port/database_name

Example: mysql-sync root:password@localhost:port/source_db root:password@localhost:port/dest_db

If the remote mysql port is not open, tunnel it via SSH i.e ssh -L 3308:localhost:3306 -o TCPKeepAlive=no -o ServerAliveInterval=15 user@host then mysql-sync root:password@localhost:3308/voeb root:password@localhost:3306/v

What the script does

  • lists all tables on the remote and local host
  • compares the checksum of each mysql table
  • syncs the tables where checksum is invalid
  • verifies the sync was successful via another checksum

The databases must have the same schema. Therefore, the script will stop if

  • the number of tables is not similar
  • the structure of a table is not similar i.e describe my_table

About

☠ Syncs two mysql databases by only inserting/deleting/updating the necessary records.


Languages

Language:Perl 94.2%Language:Shell 5.7%Language:PHP 0.2%