MySQL Backup, Restore, Import, and Export Cheatsheet

mysqldump, mysql restore, load data infile, select into outfile, mysqlimport, and MySQL Shell dump/load workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

mysqldump and restore

Portable logical backups with mysqldump and reload patterns.

Dump one database

Export schema and data from one database.

bashANYmysqldumpbackupdatabase
bash
mysqldump -u root -p --databases app_db > app_db.sql

A standard logical backup command for development, migration, and restore workflows.

Dump one table

Export a single table only.

bashANYmysqldumptable
bash
mysqldump -u root -p app_db users > users.sql

Useful for debugging, selective migrations, or sharing one dataset slice.

Dump schema only

Export DDL without row data.

bashANYmysqldumpschema-only
bash
mysqldump -u root -p --no-data app_db > app_db-schema.sql

Common when you want table definitions for code review or environment bootstrapping.

Dump data only

Export rows without CREATE statements.

bashANYmysqldumpdata-only
bash
mysqldump -u root -p --no-create-info app_db > app_db-data.sql

Handy when the schema already exists and you only need data.

Restore from a SQL dump

Load a dump file into MySQL.

bashANYrestoresqlimport
bash
mysql -u root -p app_db < app_db.sql

This replays the SQL statements in the dump file against the target database.

imports, exports, and mysql shell utilities

CSV import/export and higher-throughput dump tooling patterns.

Export query results to CSV-like output

Write rows to a server-side file.

sqlANYoutfilecsvexport
sql
SELECT id, email
INTO OUTFILE '/var/lib/mysql-files/users.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '
'
FROM users;

Requires file privileges and uses a path writable by the server.

Load CSV data into a table

Import delimited files efficiently.

sqlANYload-datacsvimport
sql
LOAD DATA INFILE '/var/lib/mysql-files/users.csv'
INTO TABLE users_staging
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '
'
IGNORE 1 LINES
(email, full_name);

Much faster than many single-row inserts for bulk imports.

Import delimited text with mysqlimport

Use the mysqlimport command-line utility.

bashANYmysqlimportcsv
bash
mysqlimport -u root -p --local --fields-terminated-by=, app_db users.csv

`mysqlimport` is a wrapper around `LOAD DATA` semantics.

Dump an instance with MySQL Shell

Use MySQL Shell utilities for scalable dumps.

bashANYmysqlshdump-instancebackup
bash
mysqlsh root@localhost -- util dump-instance /backups/mysql-instance

MySQL Shell dump utilities support advanced dump and load workflows beyond classic mysqldump.

Load a MySQL Shell dump

Restore a dump created by MySQL Shell utilities.

bashANYmysqlshload-dumprestore
bash
mysqlsh root@localhost -- util load-dump /backups/mysql-instance

Useful for parallelized and more automation-friendly restore workflows.

Recommended next

No recommendations yet.