* dumps stored routines (functions and procedures).
* dumps events.
* does extended-insert and/or complete-insert.
* supports virtual columns from MySQL 5.7.
* does insert-ignore, like a REPLACE but ignoring errors if a duplicate key exists.
* modifying data from database on-the-fly when dumping, using hooks.
* can save directly to google cloud storage over a compressed stream wrapper (GZIPSTREAM).
## Important
From version 2.0, connections to database are made using the standard DSN, documented in [PDO connection string](https://secure.php.net/manual/en/ref.pdo-mysql.connection.php).
## Requirements
- PHP 5.3.0 or newer
- MySQL 4.1.0 or newer
- [PDO](https://secure.php.net/pdo)
## Installing
Using [Composer](https://getcomposer.org/):
```
$ composer require ifsnop/mysqldump-php
```
Using [Curl](https://curl.haxx.se/) to always download and decompress the latest release:
$dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');
$dump->start('storage/work/dump.sql');
```
Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/Full-usage-example) for some examples and a comparision between mysqldump and mysqldump-php dumps.
You can register a callable that will be used to transform values during the export. An example use-case for this is removing sensitive data from database dumps:
```php
$dumper = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');
To dump a database, you need the following privileges :
- **SELECT**
- In order to dump table structures and data.
- **SHOW VIEW**
- If any databases has views, else you will get an error.
- **TRIGGER**
- If any table has one or more triggers.
- **LOCK TABLES**
- 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?](https://dba.stackexchange.com/questions/55546/which-are-the-minimum-privileges-required-to-get-a-backup-of-a-mysql-database-sc/55572#55572)
## Tests
Current code for testing is an ugly hack. Probably there are much better ways
of doing them using PHPUnit, so PR's are welcomed. The testing script creates
and populates a database using all possible datatypes. Then it exports it
using both mysqldump-php and mysqldump, and compares the output. Only if
it is identical tests are OK. After [this](https://github.com/ifsnop/mysqldump-php/commit/8496fbb1b26dde404804bc8865ec32044da5b813)
commit, some test are performed using phpunit.
Some tests are skipped if mysql server doesn't support them.
A couple of tests are only comparing between original sql code and
mysqldump-php generated sql, because some options are not available in
mysqldump.
## Bugs (from mysqldump, not from mysqldump-php)
After [this](https://bugs.mysql.com/bug.php?id=80150) bug report, a new
one has been introduced. _binary is appended also when hex-blob option is
used, if the value is empty.
## Backporting
mysqldump-php is not backwards compatible with php 5.2 because we it uses
namespaces. However, it could be trivially fixed if needed.
## Todo
Write more tests, test with mariadb also.
## Contributing
Format all code to PHP-FIG standards.
https://www.php-fig.org/
## License
This project is open-sourced software licensed under the [GPL license](https://www.gnu.org/copyleft/gpl.html)
## Credits
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.
https://code.google.com/archive/p/db-mysqldump/
Adapted and extended by Michael J. Calkins.
https://github.com/clouddueling
Currently maintained, developed and improved by Diego Torres.