PHPackages                             benmorel/smartdump - 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. benmorel/smartdump

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

benmorel/smartdump
==================

Dumps selected MySQL tables together with their relationships

0.2.0(5y ago)16190.2k↓26.4%5[2 issues](https://github.com/BenMorel/smartdump/issues)MITPHPPHP ^7.4 || ^8.0

Since Nov 21Pushed 5y ago7 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Smart Dump
==========

[](#smart-dump)

[![](https://raw.githubusercontent.com/BenMorel/smartdump/master/logo.svg)](https://raw.githubusercontent.com/BenMorel/smartdump/master/logo.svg)

Exports a **referentially intact subset** of a MySQL database.

Note: although this tool targets MySQL only for now, it is designed to be able to support other RDBMS in the future.

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

Introduction
------------

[](#introduction)

Did you ever need to export just a couple tables from your MySQL database, but end up with broken foreign key constraints? What if you could import every single foreign row your data depends on as well, and nothing more? This tool does just that.

Let's say you want to dump the `order_items` table below:

[![](https://raw.githubusercontent.com/BenMorel/smartdump/master/diagram.png)](https://raw.githubusercontent.com/BenMorel/smartdump/master/diagram.png)

If you use `mysqldump`, you'll get the whole `order_items` table, with broken foreign key constraints to `orders` and `products`.

If you use `smartdump` instead, you'll get the rows you want from `order_items` (or the whole table, as you wish), **plus** the rows from `orders` and `products` required to satisfy their constraints, **plus**, in turn, the rows from `users` and `countries` required to satisfy the remaining constraints! 💪

The key takeaway here is that `smartdump` **will only import the rows required to satisfy the constraints** of the requested tables/rows.

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

[](#installation)

The only currently supported installation method is through [Composer](https://getcomposer.org/):

```
composer require benmorel/smartdump

```

Usage
-----

[](#usage)

To dump some tables, just run:

```
vendor/bin/smartdump db.table1 db.table2

```

or, if all your tables are in the same database:

```
vendor/bin/smartdump --database db table1 table2

```

To dump only a subset of a table, add extra conditions after the table name:

```
vendor/bin/smartdump "db.table:LIMIT 100"

```

Or even:

```
vendor/bin/smartdump "db.table:WHERE user_id=123 ORDER BY id DESC LIMIT 10"

```

Options
-------

[](#options)

Options that take a value:

OptionDescriptionDefault value`--host`The host namelocalhost`--port`The port number3306`--user`The user nameroot`--password`The password`--charset`The character setutf8mb4`--database`The database name to prepend to table namesOptions that don't take a value:

OptionDescription`--no-create-table`Add this option to not include a `CREATE TABLE` statement`--add-drop-table`Add this option to include a `DROP TABLE IF EXISTS` statement before `CREATE TABLE``--no-schema-name`Add this option to not include the schema name in the output; this allows for importing the dump into a schema name other than that of the source database.`--merge`Add this option to create a dump that can be merged into an existing schema; this removes `CREATE TABLE` statements and uses upserts instead of inserts. Implies `--no-create-table`.Future scope (todo, ideas)
--------------------------

[](#future-scope-todo-ideas)

- standalone PHAR version
- support for other RDBMS
- support for loading *incoming* relationships to the tables (**?**)
    Right now, only the outgoing relationships are followed, it could be interesting to follow incoming relationships to each row we're exporting as well; at least as an option?
- a mode that does not dump, but scans the whole database for broken foreign key constraints

---

Database diagram courtesy [dbdiagram.io](https://dbdiagram.io/).

Logo by [Pixel perfect](https://www.flaticon.com/authors/pixel-perfect).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.1% 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 ~0 days

Total

4

Last Release

2002d ago

PHP version history (2 changes)0.1.0PHP ^7.4 || ^8.1

0.1.1PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (41 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (4 commits)")

###  Code Quality

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/benmorel-smartdump/health.svg)

```
[![Health](https://phpackages.com/badges/benmorel-smartdump/health.svg)](https://phpackages.com/packages/benmorel-smartdump)
```

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2592.8M263](/packages/ssch-typo3-rector)[guikingone/scheduler-bundle

A Symfony bundle that allows to schedule and create repetitive tasks

114217.4k](/packages/guikingone-scheduler-bundle)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)[psx/sql

Generate type-safe PHP classes from your database

1773.4k4](/packages/psx-sql)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)

PHPackages © 2026

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