How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Export and Import All MySQL Databases at Once
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > 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.
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

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

MySQL remove string from column — REPLACE and REGEXP_REPLACE patterns
Web Development

How to Remove a Specific String from a Column in MySQL

6 Min Read
CyberPanel too many redirects Laravel error fixed by restarting LiteSpeed
Server Management

Fix CyberPanel Too Many Redirects (ERR_TOO_MANY_REDIRECTS) for Laravel Subdomain

7 Min Read
Install Node.js on Ubuntu — terminal with NodeSource setup_22.x curl command and Node.js hexagon icon
Web Development

How to Install Node.js on Ubuntu (22.04 & 24.04): Step-by-Step

11 Min Read
Laravel foreign key constraint linking posts.user_id to users.id in a schema diagram
Web Development

How to Add Foreign Keys in Laravel Migration

6 Min Read
How7o

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

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?