Skip to main content

db:dump

Dump database

info

Requires MySQL or MariaDB CLI tools (mysqldump/mariadb-dump or mydumper). Use the --force option with caution, as it will skip confirmation prompts. The --strip option can remove important data from the dump; review your table groups before using it.

Dumps configured Magento database with mysqldump, mariadb-dump, or mydumper.

  • Requires MySQL or MariaDB CLI tools (either mysqldump/mariadb-dump or mydumper)
n98-magerun2.phar db:dump [options] [--] [<filename>]

Arguments:

ArgumentDescription
filenameDump filename.

Options (selected):

OptionDescription
--connection=CONNECTIONSelect DB connection type for Magento configurations with several databases (default: default)
--add-routinesInclude stored routines in dump (procedures & functions).
--add-time[=ADD-TIME]Append or prepend a timestamp to filename. Values: suffix, prefix, no. (default: no)
-c, --compression=COMPRESSIONCompress the dump file using one of the supported algorithms (e.g., gzip, lz4, zstd).
--dry-runDo everything but the actual dump. Useful to test.
-e, --exclude=EXCLUDETables to exclude entirely from the dump (including structure). Multiple values allowed.
-f, --forceDo not prompt if all options are defined.
--git-friendlyUse one insert statement, but with line breaks instead of separate insert statements.
--human-readableUse a single insert with column names per row. Use db:import --optimize for faster import.
-i, --include=INCLUDETables to include entirely in the dump (default: all tables are included). Multiple values allowed.
--keep-definerDo not replace DEFINER in dump with CURRENT_USER.
--keep-column-statisticsRetains column statistics table in mysqldump.
--mydumperUse mydumper instead of mysqldump for potentially faster dumps.
--no-single-transactionDo not use single-transaction (not recommended, this is blocking).
--no-tablespacesUse this option if you want to create a dump without having the PROCESS privilege.
--only-commandPrint only mysqldump/mariadb-dump/mydumper command. Does not execute.
--print-only-filenameExecute and prints no output except the dump filename.
--set-gtid-purged-offAdds --set-gtid-purged=OFF to mysqldump.
--stdoutDump to stdout.
-s, --strip=STRIPTables to strip (dump only structure of those tables). Multiple values and table groups (e.g. @log) allowed.
--viewsExplicitly include views in the dump. Views are included by default if not otherwise excluded by name or by --no-views.
--no-viewsExclude all views from the dump. This overrides any other view inclusion.
--zstd-level[=ZSTD-LEVEL]ZSTD compression level. (default: 10)
--zstd-extra-args[=ZSTD-EXTRA-ARGS]Custom extra options for zstd.

(For a full list of strip table groups and other options, use n98-magerun2.phar help db:dump)

View Handling in Dumps:

By default, db:dump includes views if their underlying tables are dumped or if the entire database is dumped. The following options provide more control:

  • --views: This option can be used to explicitly state that views should be included. Since views are generally included by default if not otherwise excluded (e.g., by a specific table exclusion pattern that happens to match a view name, or by --no-views), this option is mainly for clarity or to ensure views are included if a very broad exclusion pattern might accidentally exclude them.
  • --no-views: This option ensures that no views are included in the dump. Their definitions will not be present in the SQL file. This option takes precedence over any other rules that might otherwise include a view (e.g., if a view name matches an --include pattern or is part of a table list provided for the dump).

Table Inclusion and Exclusion

The db:dump command provides fine-grained control over which tables are included in or excluded from the database dump using the --include and --exclude options:

  • --include=INCLUDE (or -i): Only the specified tables will be included in the dump. You can specify multiple tables by repeating the option or providing a comma-separated list. Wildcards (*, ?) are supported.
  • --exclude=EXCLUDE (or -e): The specified tables will be excluded from the dump entirely (structure and data). Multiple tables can be specified, and wildcards are supported.

Combining --include and --exclude:

If both options are used together, the following logic applies:

  • The --include option first selects the set of tables to be dumped.
  • The --exclude option then removes any tables from that set that match its patterns.
  • The result is a dump containing only tables that match --include, except those matching --excludeunless a table is explicitly listed in --include, in which case it will always be included, even if it matches an --exclude pattern.

Examples:

Include only admin_user table, but exclude all tables starting with admin_:

n98-magerun2.phar db:dump --include="admin_user" --exclude="admin_*" dump.sql

This will dump the admin_user table, even though it matches the admin_* exclude pattern, because explicit includes always take precedence over excludes.

For example, this will still include admin_user:

n98-magerun2.phar db:dump --include="admin_user" --include="admin_user" --exclude="admin_user" dump.sql

Note: Explicitly included tables always take precedence over exclusions.

Note:

  • If neither option is provided, all tables are included by default.
  • If only --exclude is provided, all tables except those matching the exclude pattern(s) are dumped.
  • If only --include is provided, only the specified tables are dumped.

Examples:

Dump database without any views:

n98-magerun2.phar db:dump --no-views dump_without_views.sql

Explicitly include views (usually default behavior):

n98-magerun2.phar db:dump --views dump_with_views.sql

If my_view_name is a view, and you want to ensure its definition is not dumped, even if it was part of a --strip pattern that would normally dump structure:

n98-magerun2.phar db:dump --strip="my_view_name" --no-views dump_stripped_no_view_def.sql

Only the dump command:

n98-magerun2.phar db:dump --only-command [filename]

Or directly to stdout:

n98-magerun2.phar db:dump --stdout

Use compression (gzip cli tool has to be installed):

n98-magerun2.phar db:dump --compression="gzip"

Use mydumper for faster dumps:

n98-magerun2.phar db:dump --mydumper

Stripped Database Dump

Dumps your database and excludes some tables. This is useful for development or staging environments where you may want to provision a restricted database.

Separate each table to strip by a space. You can use wildcards like * and ? in the table names to strip multiple tables. In addition, you can specify pre-defined table groups, that start with an @ sign.

Example: dataflow_batch_export unimportant_module_* @log

n98-magerun2.phar db:dump --strip="@stripped"

Available Table Groups:

Table GroupDescription
@2fa2FA tables. These tables are used for storing 2FA information for admin users.
@adminAdmin users, roles, sessions, etc.
@aggregatedAggregated tables used for generating reports, etc.
@dotmailerDotmailer data(email_abandoned_cart email_automation email_campaign email_contact).
@customersCustomer data (and company data from the B2B extension).
@developmentRemoves logs, sessions, trade data and admin users so developers do not have to work with real customer data or admin user accounts.
@dotmailerDotmailer module tables
@ee_changelogChangelog tables of new indexer since EE 1.13
@idxTables with _idx suffix and index event tables.
@klarnaKlarna tables containing information about klarna payments and their quotes/orders.
@logLog tables.
@mailchimpMailchimp tables.
@newrelic_reportingNew Relic reporting tables. These tables provide production metric data for New Relic.
@oauthOAuth sessions, tokens, etc.
@quotesCart (quote) data and B2B quotes.
@replicaReplica tables, these are generated from Magento Staging functionality.
@salesSales data (orders, invoices, creditmemos etc).
@searchSearch related tables (catalogsearch_).
@sessionsDatabase session tables.
@strippedStandard definition for a stripped dump (logs and sessions).
@tradeCurrent trade data (customers, orders and quotes). You usually do not want those in developer systems.
@tempIndexer __temp tables.

tip

You can extend the db:dump with own table groups. Have a look here: Extend db:dump Command