Create MySql Database Backup in Linux Using MariaDB

If you need to do a MySQL database backup in linux, this is the basic command structure you want to use:

# mysqldump -u [username] -p [database name] > [filename]-$(date +%F).sql

This will prompt the password when you hit enter.

It should look something like this:

mysqldump -u admin -p admin_db > admin_db-$(date +%F).sql

This will create a file called : admin_db-2020-04-09.sql if it was created on April 9th, 2020.

The syntax above is extremely important. The new file will be output to the directory you were in when you initiated the mysqldump command.

If you need to upload this backup into a new databadse, the syntax is very similar:

mysql -u admin -p admin_db < admin_db-2020-04-09.sql

The main difference being which operator is used <vs “>“.

Leave a Reply