MySQL Backup and Restore (mysqldump)

Just for my own quick reference

Official Document: https://mariadb.com/kb/en/mariadb/mysqldump/

Backup ALL databases, including mysql (i.e. logins):

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

Backup one database:

mysqldump -u root -p database_name > database_name.sql

Backup multiple database:

mysqldump -u root -p --databases database_name another_database > database_name.sql

Backup one table:

mysqldump -u root -p database_name table_name > table_name.sql

Restore ALL databases, including logins:

mysql -u root -p < alldb.sql

(Usually you should FLUSH PRIVILEGES after restore)

Restore one database:

mysql -u root -p database_name < database_name.sql

Restore one database as another name:

mysql -u root -p -A new_database < database_name.sql

Restore one database from --all-databases dump:

mysql -u root -p --one-database database_name < alldb.sql

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.