Backup Restore or Transfer Mysql/Maria
How To Backup, Restore or Transfer
MySQL/MariaDB Databases on Ubuntu
Created October 18, 2019
Author Alex
Category Backup
Today, Backup is a significant procedure and a very important part of working
with databases. Regardless of whether you use a corporate website or just host
WordPress, it is important to back up your databases. The backup storage is
necessary in order to be able to restore information in a very quick and
convenient way, in the event that a working copy of the information may be lost
for any reason: restoration of documents, settings, certain programs and other
things.
Backup process
We recommend a way to back up a MySQL or MariaDB database using the mysqldump
dump command.
echo "SHOW DATABASES;" | sudo mysql
This command displays a list of your databases. Make sure you know which .sql
file you need, and then simply run the following command to backup to the file.
sudo mysqldump example_database > $(date +"%F").sql
The command described above will back up the example_database to a file with a
date ending in .sql. It is also possible to change the name of this file to any
other, although saving the file name as a date will be useful if you
accidentally delete an important row or column. Use date –help to learn about
other ways to style your date.
Recovery
Here you need to find the .sql file that you created and run the following:
sudo mysql example_database < filename.sql
Migrating to MariaDB from MySQL
The first thing to do is back up each of your databases:
sudo mysqldump example_database > example_database.sql
After that, you will need to install MariaDB, which will replace MySQL, and
restore your databases by following these steps for each database.
sudo mysql example_database < example_database.sql