PHPackages                             sqonk/mysql-sync - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. sqonk/mysql-sync

ActiveLibrary[Database &amp; ORM](/categories/database)

sqonk/mysql-sync
================

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

0.8.2(1y ago)16614↓33.3%3[1 PRs](https://github.com/sqonk/mysql-sync/pulls)MITPHPPHP ^8

Since May 1Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/sqonk/mysql-sync)[ Packagist](https://packagist.org/packages/sqonk/mysql-sync)[ RSS](/packages/sqonk-mysql-sync/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

MySQL Synchroniser
==================

[](#mysql-synchroniser)

[![Minimum PHP Version](https://camo.githubusercontent.com/db2abc4c99337a799d57b191c749e512b551eaebf6ce7c37e0ea9eac2eb1b9f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e342d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/e3d584625d5a65f768ca34cf2e2486fe3578f7f9f7f6c1c07548809f8ca8c0f2/68747470733a2f2f73716f6e6b2e636f6d2f6f70656e736f757263652f6c6963656e73652e737667)](license.txt)

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
-------

[](#install)

Via Composer

```
$ composer require sqonk/mysql-sync
```

Disclaimer - (Common Sense)
---------------------------

[](#disclaimer---common-sense)

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

Usage
-----

[](#usage)

### Method 1: Using a JSON config file

[](#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
	},
}
```

*Note that the above is a baseline config. See the sample json file for a full set of possible options.*

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

[](#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

[](#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 top level of your sync configuration.

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

#### Dealing with Collation differences on tables

[](#dealing-with-collation-differences-on-tables)

If the source and destination databases have different character encoding sets you can instruct the synchroniser to either remove or substitute encoding sets *when creating new tables in the destination*.

##### Omitting COLLATE syntax entirely

[](#omitting-collate-syntax-entirely)

Add a key `omitCollate` to the top level of your json config with a value of `true` or `false`. Setting it to true will remove all `COLLATE=` commands on the end of `CREATE TABLE` lines.

##### Substituting collation

[](#substituting-collation)

You can also elect to replace occurances of multiple table collations on your source database to another set that is present on the destination database.

To do so, add the following to the top level of your config, replacing the values of 'from' and 'to':

```
  collateSubstitutions : [
  	{
  	   "from" : "collationOnSource1",
  	   "to": "collationOnDestination1"
  	}
  ]
```

Because the `collateSubstitutions` is an array, you can add as many substiution sets as required.

##### Using both options together

[](#using-both-options-together)

Setting `omitCollate` to `true` and adding substitution sets will function as expected; Substitutions will be replace occurances and any collations not matching one of the sets will be removed.

### Process

[](#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
-------

[](#credits)

- Theo Howell
- Oliver Jacobs

License
-------

[](#license)

The MIT License (MIT). Please see [License File](license.txt) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance62

Regular maintenance activity

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~281 days

Recently: every ~351 days

Total

7

Last Release

519d ago

PHP version history (4 changes)0.5PHP ^7.3

0.6PHP ^7.3 || ^8.0.0

0.6.1PHP ^7.3 || ^7.4 || ^8.0

0.8PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/d613b1fb90e5ed5b8207818496ae9c90b7d3b54890803f0af3279c2e7fbd9771?d=identicon)[sqonk](/maintainers/sqonk)

---

Top Contributors

[![sqonk](https://avatars.githubusercontent.com/u/55817417?v=4)](https://github.com/sqonk "sqonk (61 commits)")[![Jako](https://avatars.githubusercontent.com/u/148371?v=4)](https://github.com/Jako "Jako (1 commits)")

---

Tags

mysqlsyncmigratesynchronise

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sqonk-mysql-sync/health.svg)

```
[![Health](https://phpackages.com/badges/sqonk-mysql-sync/health.svg)](https://phpackages.com/packages/sqonk-mysql-sync)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[awssat/laravel-sync-migration

Laravel tool helps to sync migrations without refreshing the database

10923.2k](/packages/awssat-laravel-sync-migration)[cytopia/mysqldump-secure

Secure mysqldump script with encryption, compression, logging, blacklisting and Nagios monitoring integration

1474.7k1](/packages/cytopia-mysqldump-secure)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
