In today’s guide I will be showing you how to backup MySQL databases and backup MariaDB databases. I will also show you how to restore MySQL databases and restore MariaDB databases. This process is actually very easy with only 2 commands, and it is definitely recommended that you backup your databases if you are planning on migrating from MySQL to MariaDB (I almost lost a DB due to unexpected issues).
Backup All Databases – MySQL and MariaDB
The following command will make a mysql backup database in 1 convenient file which you can then import if you need to restore later. You will be prompted for a root password, note that this is not your actual root password but rather your MySQL/MariaDB root password.
mysqldump -u root -p --all-databases > /root/db-backup.sql
Restore All Databases – MySQL and MariaDB
To restore all of your databases from the backup/dump we just created you will run the following command.
mysql -u root -p < /root/db-backup.sql
Verify Restore Of Databases
Provided you don’t have the “show databases” feature disabled in your config (my.cnf), you can use the following commands to check for your databases. Use the first command to login to your SQL server and the second once you are logged in, the semicolon is required for the command to actually execute.
sudo mysql -u root -p show databases;
I hope this guide helped you learn how to backup mysql database, please don’t forget to like, comment, and share for more guides! Thanks!