Use the dump tools to export data, and the client to import it back.
Export a database
MySQL:
MariaDB:
Export specific tables
MySQL:
MariaDB:
Export multiple databases
If you want the dump file to include CREATE DATABASE and USE, add --databases:
Use --databases when you want the dump file to recreate the original database names. Skip it if you want to restore into a differently named database.
Import a database
If the dump file does not contain CREATE DATABASE / USE, create the target database first.
MySQL:
MariaDB:
If the dump file already contains USE db_name, you can omit the database name:
If the dump is compressed:
Notes
mysqldumpis the standard logical backup tool for MySQL.mariadb-dumpis the current dump tool for MariaDB.mysqldumpis an older name kept for compatibility in some environments.mariadb-dumpdoes not include stored procedures or events unless you ask for them with options such as--routinesand--events.mysqlpumpexists in MySQL, but it is deprecated as of MySQL 8.0.34. Do not treat it as the default recommendation.- For large logical backups, tools such as
mydumper/myloadercan be faster because they support parallelism.
Documentation
- MySQL
mysqldump: https://dev.mysql.com/doc/refman/en/mysqldump.html - MySQL
mysqlbatch import: https://dev.mysql.com/doc/refman/en/batch-mode.html - MariaDB
mariadb-dump: https://mariadb.com/docs/server/clients-and-utilities/backup-restore-and-import-clients/mariadb-dump - MariaDB backup and restore overview: https://mariadb.com/docs/server/server-usage/backup-and-restore/backup-and-restore-overview