PHPackages                             camcima/php-mysql-diff - 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. camcima/php-mysql-diff

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

camcima/php-mysql-diff
======================

1.2.1(8y ago)14842.6k↓50%48[15 issues](https://github.com/camcima/php-mysql-diff/issues)[2 PRs](https://github.com/camcima/php-mysql-diff/pulls)MITPHPPHP &gt;5.6

Since Apr 10Pushed 4y ago7 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (15)Used By (0)

PHP MySQL Diff
==============

[](#php-mysql-diff)

MySQL Schema Diff - Comparison / Migration Script Generation

[![Travis-CI](https://camo.githubusercontent.com/a7987fa6ab1fb3461b6558958d8af26ea0318d0a14df4565fb8e0d52077fd31d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63616d63696d612f7068702d6d7973716c2d646966662f6d61737465722e737667)](https://travis-ci.org/camcima/php-mysql-diff)

##### Why not `mysqldiff` from MySQL Utilities?

[](#why-not-mysqldiff-from-mysql-utilities)

MySQL Utilities includes a similar tool, `mysqldiff`, that is absolutely **horrible**! The purpose of this project is to provide a tool that is simple to use, reliable and fast.

Installation
------------

[](#installation)

To install PHP MySQL Diff, install Composer and issue the following command:

```
$ ./composer.phar global require camcima/php-mysql-diff

```

Then, make sure you have ~/.composer/vendor/bin in your PATH, and you're good to go:

```
export PATH="$PATH:$HOME/.composer/vendor/bin"

```

Update
------

[](#update)

You can update PHP MySQL Diff through this command:

```
$ ./composer.phar global update camcima/php-mysql-diff

```

Usage
-----

[](#usage)

### Database Creation Scripts

[](#database-creation-scripts)

PHP MySQL Diff works with database creations scripts created by `mysqldump`, which is part of the MySQL distribution. In order to generate a database creation script, use the following command:

```
$ mysqldump -h hostname -u username -p -d dbname > outputfile.sql

```

This tool may not work with creation scripts generated by other means because it relies on finely tuned regular expressions that could not work if the file format is different.

I chose to work with database creation scripts instead of working by connecting to the databases directly because it's more portable that way and you can work offline. In the future, I might develop the option to fetch the information directly from the database `INFORMATION_SCHEMA` table.

### Diff

[](#diff)

```
$ php-mysql-diff diff   [-i ]

```

where `from` is the path to the initial database creation script and `to` is the path to the target database creation script.

**Ignore Tables**

Use the `-i` option to ignore tables during comparison. The file format is a list of regular expressions to match the table names to be ignored, one per line.

Example:

```
/^employee.+/
/^catalog$/
/^test[\d]$/

```

**Output File**

The output will be like this:

```
PHP MySQL Diff 1.0.0
----------------------------------------

• Parsing initial database ...... ✓
• Parsing target database ....... ✓
• Comparing databases ........... ✓

FROM tests\fixtures\sakila.sql
  TO tests\fixtures\sakila_new.sql

▲ table "test3" is in the TO database but not in the FROM database
▼ table "test1" is in the FROM database but not in the TO database
► table "test2" has a different schema
    ▲ column "new_field" is in the TO database but not in the FROM database
    ► column "id" has a different definition
        FROM `id` int(11) NOT NULL AUTO_INCREMENT
          TO `id` int(10) NOT NULL AUTO_INCREMENT
    ► column "fk" has a different definition
        FROM `fk` int(10) NOT NULL
          TO `fk` int(10)
    ► column "val" has a different definition
        FROM `val` decimal(10,2) NOT NULL
          TO `val` decimal(11,3) NOT NULL
    ► column "texto" has a different definition
        FROM `texto` varchar(60) DEFAULT NULL
          TO `texto` char(60) NOT NULL DEFAULT 'default'
    ► primary key has a different definition
        FROM PRIMARY KEY (`id`)
          TO PRIMARY KEY (`id`,`new_field`)
    ▲ foreign key "FK__test3" is in the TO database but not in the FROM database
    ▼ foreign key "FK__test1" is in the FROM database but not in the TO database
    ► index "FK__test1" has a different definition
        FROM KEY `FK__test1` (`fk`)
          TO UNIQUE KEY `FK__test1` (`datade`)

Diff completed!

```

▲ = only present in the TO database

► = different definitions between FROM and TO databases

▼ = only present in the FROM database

### Migration Script

[](#migration-script)

```
$ php-mysql-diff migrate   [-o ] [-i ] [-p]

```

where `from` is the path to the initial database creation script and `to` is the path to the target database creation script.

**Ignore Tables**

Use the `-i` option to ignore tables during comparison. The file format is a list of regular expressions to match the table names to be ignored, one per line.

Example:

```
/^employee.+/
/^catalog$/
/^test[\d]$/

```

**Output File**

If the `-o` option is not used, the migration script will be output to the `stdout`.

The output (with the `-o` option) will be like this:

```
PHP MySQL Diff 1.0.0
----------------------------------------

• Parsing initial database ...... ✓
• Parsing target database ....... ✓
• Comparing databases ........... ✓
• Generating migration script ... ✓
• Writing output file ........... ✓

Migration script generated!

```

and the migration script will look like this:

```
# Disable Foreign Keys Check
SET FOREIGN_KEY_CHECKS = 0;
SET SQL_MODE = '';

# Deleted Tables

-- deleted table `test1`

DROP TABLE `test1`;

# Changed Tables

-- changed table `test2`

ALTER TABLE `test2`
  DROP PRIMARY KEY,
  DROP FOREIGN KEY `FK__test1`,
  DROP INDEX `FK__test1`,
  CHANGE COLUMN `id` `id` int(10) NOT NULL AUTO_INCREMENT FIRST,
  CHANGE COLUMN `fk` `fk` int(10) AFTER `id`,
  CHANGE COLUMN `val` `val` decimal(11,3) NOT NULL AFTER `fk`,
  CHANGE COLUMN `texto` `texto` char(60) NOT NULL DEFAULT 'default' AFTER `val`,
  ADD COLUMN `new_field` int(10) AFTER `datade`,
  ADD PRIMARY KEY (`id`,`new_field`),
  ADD UNIQUE KEY `FK__test1` (`datade`),
  ADD CONSTRAINT `FK__test3` FOREIGN KEY (`fk`) REFERENCES `test3` (`id`);

# New Tables

-- new table `test3`

CREATE TABLE `test3` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

# Disable Foreign Keys Check
SET FOREIGN_KEY_CHECKS = 1;
```

**Display Progress**

For long running migrations, it is recommended to use the `-p` option to display the progress of the running migration.

Contribute
----------

[](#contribute)

Feel free to send your contributions as PR. Make sure you update/write new tests to support your contribution. Please follow PSR-2.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 64% 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 ~44 days

Recently: every ~137 days

Total

14

Last Release

3118d ago

### Community

Maintainers

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

---

Top Contributors

[![camcima](https://avatars.githubusercontent.com/u/1918601?v=4)](https://github.com/camcima "camcima (16 commits)")[![sascha432](https://avatars.githubusercontent.com/u/30159319?v=4)](https://github.com/sascha432 "sascha432 (6 commits)")[![sstrigler](https://avatars.githubusercontent.com/u/23786?v=4)](https://github.com/sstrigler "sstrigler (2 commits)")[![ccerrillo](https://avatars.githubusercontent.com/u/348026?v=4)](https://github.com/ccerrillo "ccerrillo (1 commits)")

---

Tags

diffmigrationdatabasegeneratormysqlscript

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/camcima-php-mysql-diff/health.svg)

```
[![Health](https://phpackages.com/badges/camcima-php-mysql-diff/health.svg)](https://phpackages.com/packages/camcima-php-mysql-diff)
```

###  Alternatives

[odan/phinx-migrations-generator

Migration generator for Phinx

235847.8k23](/packages/odan-phinx-migrations-generator)[awssat/laravel-sync-migration

Laravel tool helps to sync migrations without refreshing the database

10923.2k](/packages/awssat-laravel-sync-migration)[hzhihua/yii2-dump

Generate the schema from an existing database

1828.5k1](/packages/hzhihua-yii2-dump)[smrtr/mysql-version-control

A crude version control system for mysql written in php

221.4k](/packages/smrtr-mysql-version-control)

PHPackages © 2026

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