How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Export and Import All MySQL Databases at Once
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Export and Import All MySQL Databases at Once
Server Management

How to Export and Import All MySQL Databases at Once

how7o
By how7o
Last updated: May 10, 2026
6 Min Read
mysqldump all databases — export and import commands
SHARE

The standard mysqldump all databases pair exports every database to a single SQL file with mysqldump, and imports it back with mysql. Handy for snapshotting a whole server, migrating between hosts, or running regular backups. This guide covers the basic commands, the --skip-lock-tables / --single-transaction options for live servers, and compression for when the dump is large.

Contents
  • TL;DR
  • Export
  • Compress while dumping
  • Scheduling nightly backups
  • Import
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on MySQL 8.0 and MariaDB 10.11. Originally published 2022-12-06, rewritten and updated 2026-04-23.

TL;DR

# Export everything
mysqldump -u root -p --all-databases > alldb.sql

# Production-safe variant (InnoDB): transactional, no table locks
mysqldump -u root -p --all-databases --single-transaction --quick > alldb.sql

# Import
mysql -u root -p < alldb.sql

Export

mysqldump -u root -p --all-databases > alldb.sql

Dumps every database on the server including system databases (mysql, sys) and their user accounts, stored procedures, events. The output is a single plain-text SQL file you can open and read. Size depends on data volume — expect roughly 1-2× the actual data size.

For production servers with live traffic, the default mysqldump locks tables during the dump. Two options to avoid the freeze:

# MyISAM-heavy or mixed — skip locks, accept slight inconsistency
mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql

# InnoDB-only — transactional consistency, no locks
mysqldump -u root -p --all-databases --single-transaction --quick > alldb.sql

--single-transaction is the right default for modern InnoDB tables: the dump runs inside a long-running transaction, so you get a consistent snapshot without blocking other traffic. Pair with --quick to stream rows instead of buffering them — keeps memory use low on big tables.

mysqldump all databases — export with --all-databases, import with mysql < file

Compress while dumping

# Gzip on the fly — typical 5-10× compression
mysqldump -u root -p --all-databases | gzip > alldb.sql.gz

# Restore from compressed
gunzip -c alldb.sql.gz | mysql -u root -p

For backup retention, gzip-on-write is almost always worth it. SQL compresses exceptionally well — a 1GB dump typically shrinks to 100-200MB. Decompression-on-import pipes the stream directly into mysql without needing disk space for the uncompressed intermediate.

Scheduling nightly backups

# /etc/cron.d/mysql-backup — keep the last 7 days
0 3 * * * root mysqldump --defaults-file=/root/.my.cnf --all-databases --single-transaction --quick | gzip > /var/backups/mysql/db-$(date +\%Y\%m\%d).sql.gz
15 3 * * * root find /var/backups/mysql -name 'db-*.sql.gz' -mtime +7 -delete

/root/.my.cnf holds the credentials so they’re not on the command line ([client]\nuser=root\npassword=...\n, chmod 600). The find ... -mtime +7 -delete second job rotates old backups. For offsite retention, pipe or rsync the gzipped file to S3, another server, or a cold-storage host.

Import

mysql -u root -p < alldb.sql

Streams the dump file to mysql, which executes each statement in order. --all-databases dumps include the CREATE DATABASE statements, so the target server doesn’t need those databases to exist beforehand. For a fresh destination, the import recreates everything from scratch.

For a single-database import from an --all-databases dump, use sed or grep to extract just that database’s section, or re-dump with --databases <name> from the source if it’s still available.

Frequently asked questions

What’s the one-liner for mysqldump all databases?

mysqldump -u root -p --all-databases > alldb.sql. Captures every database on the server — schema, data, user accounts, stored procedures, events. Import with mysql -u root -p < alldb.sql. Works on any MySQL or MariaDB version.

Why --skip-lock-tables?

Without it, mysqldump locks each table in each database for the duration of its dump. On a production server with traffic, that freezes queries until the dump finishes — potentially minutes. --skip-lock-tables trades a slight consistency risk (rows changing mid-dump could appear in one table but not a related one) for keeping the site responsive. For transactionally-consistent dumps on InnoDB, use --single-transaction instead — best of both worlds for InnoDB tables.

Can I exclude specific databases?

--all-databases doesn’t have an exclude flag, but you can list specific databases with --databases db1 db2 db3. For a scripted “everything except schema X,” query the list dynamically: mysql -Ne "SHOW DATABASES" | grep -vE '^(mysql|sys|information_schema|performance_schema|excluded_db)$' | xargs mysqldump -u root -p --databases > alldb.sql.

How do I compress the dump?

Pipe through gzip: mysqldump -u root -p --all-databases | gzip > alldb.sql.gz. Typical compression ratio is 5-10× for SQL. Import with gunzip -c alldb.sql.gz | mysql -u root -p. For a live backup-over-SSH: mysqldump ... | ssh backup-host 'cat > alldb.sql.gz'.

What’s the right import strategy?

mysql -u root -p < alldb.sql reads the file sequentially and runs each statement. For big dumps this is slow because every insert commits individually. Two speed-ups: disable binary logging during import (SET sql_log_bin = 0; at the top of the dump), and use mysqlpump or mydumper for parallelized restore. For normal 10-100GB dumps, sequential is fine — just let it run.

Related guides

  • How to Install MySQL on Ubuntu — the fresh install that accepts the import.
  • How to Troubleshoot MariaDB Not Starting — when you need the backup to recover.
  • How to Create Users and Grant Privileges in MySQL 8 — –all-databases dumps include user accounts.
  • How to Reset the MySQL Root Password in aaPanel — admin access needed for the dump.

References

MySQL mysqldump: dev.mysql.com/doc/refman/8.0/en/mysqldump.

TAGGED:Bashcronmariadbmysql

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article MySQL 8 create user and grant privileges on Ubuntu How to Create Users and Grant Privileges in MySQL 8 on Ubuntu
Next Article PHP delete array element — unset, array_splice, array_filter, array_search How to Delete an Element from a PHP Array
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Laravel Eloquent ORM — a model class mapping to a database table with query methods
Laravel Eloquent ORM: The Complete Guide to Querying Your Database
June 16, 2026
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026

You Might Also Like

Install and configure Redis on Ubuntu for Laravel and WordPress
Server Management

How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)

10 Min Read
Run a Linux cron job as a non-root user
Server Management

How to Run a Cron Job as a Non-Root User

5 Min Read
Migrating files from cPanel to aaPanel using rsync
Server Management

cPanel to aaPanel Migration with rsync: Fix Permissions, SSH Port, and CSF Firewall

6 Min Read
Disable binary logging in MySQL or MariaDB
Server Management

How to Disable Binary Logging in MySQL or MariaDB

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?