PHPackages                             druidfi/mysqldump-php - 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. druidfi/mysqldump-php

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

druidfi/mysqldump-php
=====================

PHP version of mysqldump cli that comes with MySQL

2.0.3(5mo ago)35659.1k—0.8%10[3 issues](https://github.com/druidfi/mysqldump-php/issues)[1 PRs](https://github.com/druidfi/mysqldump-php/pulls)7GPL-3.0-or-laterPHPPHP ^8.1CI passing

Since Aug 19Pushed 3w ago4 watchersCompare

[ Source](https://github.com/druidfi/mysqldump-php)[ Packagist](https://packagist.org/packages/druidfi/mysqldump-php)[ Docs](https://github.com/druidfi/mysqldump-php)[ RSS](/packages/druidfi-mysqldump-php/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (8)Versions (22)Used By (7)

mysqldump-php
=============

[](#mysqldump-php)

[![Run tests](https://github.com/druidfi/mysqldump-php/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/druidfi/mysqldump-php/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/9f0271d513ca68a132c8d3d37e6d670cc37e4cc4863f024e21f397d72457482f/68747470733a2f2f706f7365722e707567782e6f72672f647275696466692f6d7973716c64756d702d7068702f646f776e6c6f616473)](https://packagist.org/packages/druidfi/mysqldump-php)[![Monthly Downloads](https://camo.githubusercontent.com/c9fd4d3d1faa02b1e64ce207c49a52a92442be477d0c44b1e33eddb0382f7c85/68747470733a2f2f706f7365722e707567782e6f72672f647275696466692f6d7973716c64756d702d7068702f642f6d6f6e74686c79)](https://packagist.org/packages/druidfi/mysqldump-php)[![Daily Downloads](https://camo.githubusercontent.com/e4fc3f504b63862b77401865e5c2eeab4ccb5537f81c0bc5a2dbf075b460a82b/68747470733a2f2f706f7365722e707567782e6f72672f647275696466692f6d7973716c64756d702d7068702f642f6461696c79)](https://packagist.org/packages/druidfi/mysqldump-php)[![Latest Stable Version](https://camo.githubusercontent.com/80208751ba3e60728c1133a036b79a85cc40b8c00a71a3765427cef176188612/68747470733a2f2f706f7365722e707567782e6f72672f647275696466692f6d7973716c64756d702d7068702f762f737461626c652e706e67)](https://packagist.org/packages/druidfi/mysqldump-php)

This is a PHP version of `mysqldump` cli that comes with MySQL. It can be used for interacting with the data before creating the database dump. E.g. it can modify the contents of tables and is thus good for anonymize data.

Out of the box, `mysqldump-php` supports backing up table structures, the data itself, views, triggers and events.

`mysqldump-php` supports:

- output binary blobs as hex
- resolves view dependencies (using Stand-In tables)
- output compared against original mysqldump
- 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 cloud storage (Google Cloud Storage, Amazon S3, ...) over [PHP stream wrappers](#dumping-to-cloud-storage-and-other-streams)

Requirements
------------

[](#requirements)

- PHP 8.4 or newer with PDO - [see supported versions](https://www.php.net/supported-versions.php)
- MySQL 8.0 or newer (and compatible MariaDB)

Versions
--------

[](#versions)

VersionBranchPHPStatusTests3.x`main`8.4+In development[![Run tests](https://github.com/druidfi/mysqldump-php/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/druidfi/mysqldump-php/actions/workflows/tests.yml?query=branch%3Amain)2.x`2.x`8.1+Maintenance[![Run tests](https://github.com/druidfi/mysqldump-php/actions/workflows/tests.yml/badge.svg?branch=2.x)](https://github.com/druidfi/mysqldump-php/actions/workflows/tests.yml?query=branch%3A2.x)1.x`1.x`7.4 / 8.0LegacyUpgrading from 2.x to 3.x
-------------------------

[](#upgrading-from-2x-to-3x)

The dump output and the day-to-day API — constructor, `start()`, the transform/info hooks, `setTableWheres()`/`setTableLimits()` and the dump settings with their defaults — are unchanged from 2.x. The following changes may require action:

- **PHP 8.4 or newer is required** (2.x supports PHP 8.1+).
- **Connections are no longer persistent by default.** 2.x always set `PDO::ATTR_PERSISTENT => true`. If you relied on persistent connections, pass `PDO::ATTR_PERSISTENT => true` in the `$pdoOptions` constructor argument.
- **`Mysqldump::addTypeAdapter()` no longer affects other instances.** In 2.x the adapter class was stored statically and leaked into every `Mysqldump` instance in the same process. Call `addTypeAdapter()` on each instance that needs a custom adapter.
- **`CompressManagerFactory::$methods` was removed.** Use the `CompressMethod` enum, or the unchanged class constants such as `CompressManagerFactory::GZIP`.
- **The `Druidfi\Mysqldump\Attribute\Deprecated` attribute class was removed.** Deprecations now use the native PHP 8.4 `#[\Deprecated]` attribute.
- **`ConfigValidator::checkDeprecated()` return value changed.** The `reason` and `alternative`keys were replaced by a single `message` key (`deprecated` and `since` are unchanged).
- **`DumpSettings::get()` returns the setting's actual type.** In 2.x every value was cast to `string`; now arrays, booleans and integers come back unchanged, and unknown options return `null` instead of the string `""`. Prefer the typed getters (`getWhere()`, `getNetBufferLength()`, ...) where one exists.
- **`TypeAdapterInterface` gained `quoteIdentifier()`.** Identifiers (table, view, column, ... names) are now escaped wherever they are interpolated into SQL, so names containing backticks dump correctly. Custom type adapters must implement the new method.
- **`compress-level` is validated per method.** Levels up to the method maximum are accepted (Gzip 1-9, Lz4 1-12, Zstd 1-22) where 2.x rejected everything above 9, and a level above the method maximum now throws with a method-specific message.
- **The protected `Mysqldump::tableColumnTypes()` accessor was removed.** Column type maps are now freed as soon as each table or view has been dumped, so memory no longer grows with the number of tables; the accessor had nothing meaningful to return anymore.
- **Exceptions are now typed.** The library throws subclasses of `Druidfi\Mysqldump\Exception\MysqldumpException` instead of bare `Exception`. No action is needed — the base class extends `Exception`, so existing `catch (\Exception $e)` blocks keep working — but you can now catch more specific types, see [Error handling](#error-handling).

Also fixed in 3.x with no action needed: 2.x settings validation rejected the `Zstd`, `Lz4` and `Gzipstream` compression methods due to a mismatch between the allowed values and the factory; they now validate correctly.

Installing
----------

[](#installing)

Install using [Composer](https://getcomposer.org/):

```
composer require druidfi/mysqldump-php
```

Getting started
---------------

[](#getting-started)

```
