caharkness.com

Conner Harkness, Software Engineer
Home | Contact | Donate | Directory | Login

Dumping MySQL (And Restoring It)

Dumping MySQL (And Restoring It)

Although Microsoft SQL Server is far beyond any of the competition in regards to language flexibility and features, we are not “dumping” MySQL for another database server. No, I am going to walk you through how to back up your entire MySQL database and restore it. I do want to remind you that this is also compatible with MariaDB as MariaDB is a drop-in replacement for MySQL in complete, open source environments.

Run the following as root in a BASH shell:

cd && mysqldump --all-databases > "$(date +'%Y%m%d%H%M')-mysqldump.sql"

This will bring you to your root user’s home directory and dump the entire database to a uniquely named file with the .sql extension. This file contains all the MySQL statements, in chronological order, that recreates everything you just backed up. You can blow your current MySQL installation to bits and restore everything with this .sql file. To actually restore your new backup, run the following as root:

mysql < timestamp-mysqldump.sql

Where timestamp-mysqldump.sql is the true file name of the backup. The actual name will be prefixed with a unique timestamp, accurate down to the second, hence “uniquely named file” as stated earlier. It’s good practice to keep everything backed up, organized, and as often as possible. You’re welcome!

by caharkness on March 6th, 2022
Permalink Raw