Skip to content

The MySQL Synchroniser is a simple script written in PHP that can assist and automate the synchronisation of differences in table structures between two database servers.

Notifications You must be signed in to change notification settings

sqonk/mysql-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL Synchroniser

Minimum PHP Version License

The MySQL Synchroniser is a simple script written in PHP that can assist and automate the synchronisation of differences in table structures between two database servers.

Synchronisation is performed between a source database and a destination.

Install

Via Composer

$ composer require sqonk/mysql-sync

Disclaimer - (Common Sense)

Always backup the destination database prior to making any changes, this should go without saying.

Usage

Method 1: Using a JSON config file

First duplicate the sample json sync file provided the conf folder, call it something meanginful and enter the database details for both the source and destination databases.

{
	"source" : {
		"host" : "",
		"user" : "",
		"password" : "",
		"database" : "",
		"port" : "3306"
	},
	"dest" : {
		"host" : "",
		"user" : "",
		"password" : "",
		"database" : "",
		"port" : "3306"
	},
    "ignoreColumnWidths" : false
}

Then from your terminal run the following the command:

vendor/bin/mysql-sync path/to/my/config-file.json

Method 2: Using in-memory PHP array

Create a new PHP script, load the composer includes and pass your config array accordingly.

require 'vendor/autoload.php'

mysql_sync([
	"source" => [
		"host" => "",
		"user" => "",
		"password" => "",
		"database" => "",
		"port" : "3306"
	],
	"dest" => [
		"host" => "",
		"user" => "",
		"password" => "",
		"database" => "",
		"port" : "3306"
	],
    "ignoreColumnWidths" : false
]);

Ignoring Column Widths

If you are in a situation in which the configuration of the destination database differs from that of the source environment in such a way that column widths do not match up then you can set the option ignoreColumnWidths to true in the sync configuration.

This will adjust the comparison to ignore column width/length.

Process

A dry-run will first be performed and any differences will be displayed, including:

  • New tables to create in the destination.
  • Old tables to drop no longer present on the source.
  • Tables present in both but with differing columns (including new, old and modified)

Once done, you will be prompted if you wish to apply the changes for real.

Credits

  • Theo Howell
  • Oliver Jacobs

License

The MIT License (MIT). Please see License File for more information.

About

The MySQL Synchroniser is a simple script written in PHP that can assist and automate the synchronisation of differences in table structures between two database servers.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages