This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Mysql Dumping for PHP.

1.0.0 2018-06-06 12:18 UTC

This package is not auto-updated.

Last update: 2020-01-03 19:38:42 UTC


Mysql Dumper is the only library that supports:

  • Output binary blobs as hex.
  • Resolves view dependencies (using Stand-In tables).
  • Dumps stored procedures.
  • Dumps events.
  • Does extended-insert and/or complete-insert.
  • Supports virtual columns from MySQL 5.7.


  • PHP 7.0.0 or newer
  • MySQL 5.4.0 or newer
  • PDO


Using Composer:

$ composer require niko9911/mysqldump-php:1.*

Or via json file:

"require": {

Using Curl to always download and decompress the latest release:

$ curl --silent --location | grep -i tarball_url | head -n 1 | cut -d '"' -f 4 | xargs curl --location --silent | tar xvz

Getting started

With Autoloader/Composer:


use Niko9911\MysqlDump\Dump;

try {
    $dump = new Dump('mysql:host=localhost;dbname=testdb', 'username', 'password');
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();

Refer to the wiki for some examples and a comparision between mysqldump and mysqldump-php dumps.

Constructor and default parameters

 * Constructor of Mysqldump. Note that in the case of an SQLite database
 * connection, the filename must be in the $db parameter.
 * @param string $dsn        PDO DSN connection string
 * @param string $user       SQL account username
 * @param string $pass       SQL account password
 * @param array  $dumpSettings SQL database settings
 * @param array  $pdoSettings  PDO configured attributes
public function __construct(
    $dsn = '',
    $user = '',
    $pass = '',
    $dumpSettings = array(),
    $pdoSettings = array()

$dumpSettingsDefault = array(
    'include-tables' => array(),
    'exclude-tables' => array(),
    'compress' => Mysqldump::NONE,
    'init_commands' => array(),
    'no-data' => array(),
    'reset-auto-increment' => false,
    'add-drop-database' => false,
    'add-drop-table' => false,
    'add-drop-trigger' => true,
    'add-locks' => true,
    'complete-insert' => false,
    'databases' => false,
    'default-character-set' => Mysqldump::UTF8,
    'disable-keys' => true,
    'extended-insert' => true,
    'events' => false,
    'hex-blob' => true, /* faster than escaped content */
    'net_buffer_length' => self::MAXLINESIZE,
    'no-autocommit' => true,
    'no-create-info' => false,
    'lock-tables' => true,
    'routines' => false,
    'single-transaction' => true,
    'skip-triggers' => false,
    'skip-tz-utc' => false,
    'skip-comments' => false,
    'skip-dump-date' => false,
    'skip-definer' => false,
    'where' => '',
    /* deprecated */
    'disable-foreign-keys-check' => true

$pdoSettingsDefaults = array(

// missing settings in constructor will be replaced by default options
$this->_pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
$this->_dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);

Dump Settings

The following options are now enabled by default, and there is no way to disable them since they should always be used.

PDO Settings


To dump a database, you need the following privileges :

    • In order to dump table structures and data.
    • If any databases has views, else you will get an error.
    • If any table has one or more triggers.
    • If "lock tables" option was enabled.

Use SHOW GRANTS FOR user@host; to know what privileges user has. See the following link for more information:

Which are the minimum privileges required to get a backup of a MySQL database schema?


GitLab CI & Automatic Deployment to Composer


Format all code to PHP-FIG standards.


This project is open-sourced software licensed under the GPL license For commercial licenses, please contact niko-at-ironlions-dot-fi.


After more than 8 years, there is barely anything left from the original source code, but:

Originally based on James Elliott's script from 2009.

Adapted and extended by Michael J. Calkins.

Rewrite based on from Diego Torres.

Currently maintained, developed and improved by Niko Granö.