Backing up and Restoring MySQL with mysqldump

| devops | databases |

I backup and restore databases across servers every few months, but each time I have to resort to reading this very verbose documentation. The steps below are a no fuss way to do this each time.

Backup Server

SSH into the server with the database that you wish to backup run the following command.
mysqldump -u root -p $DB_NAME > $DB_NAME.sql

Copy the File to Destination Server

Using scp, we can securely transfer the backup
scp $DB_NAME.sql $USER@$SERVER:

Restore on Destination Server

SSH into the server with the database that you wish to restore. From the the previous step the backup file should now be located in the root directory.
  1. Create new database
    mysql -u root -p -e 'CREATE DATABASE $DB_NAME'
    
  2. Restore your backup
    mysql -u root -p $DB_NAME < $DB_NAME.sql

Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.

Check out some more stuff to read down below.

Most popular posts this month

Recent Favorite Blog Posts

This is a collection of the last 8 posts that I bookmarked.

Articles from blogs I follow around the net

I was inconsiderate but now I’m everywhere

When I was in the music business, there was a record producer who lived in New Jersey, but refused to come into New York City. Anyone that wanted to meet with him had to drive all the way down to his little town. I thought, “What’s his problem? Is he lazy o…

via Derek Sivers blog March 12, 2026

Pluralistic: AI "journalists" prove that media bosses don't give a shit (11 Mar 2026)

Today's links AI "journalists" prove that media bosses don't give a shit: In case there was ever any doubt. Hey look at this: Delights to delectate. Object permanence: Eggflation x excuseflation; Haunted Mansion stretch portraits; "Los…

via Pluralistic: Daily links from Cory Doctorow March 11, 2026

Generative AI vegetarianism

For some spicier takes! Anthony Moser’s “I Am An AI Hater”, Jenny Zhang’s “choosing friction”, Rusty Foster’s “A.I. Isn’t People”, or Ed Zitron’s “The Case Against Generative AI” if you have most of an afternoon to read it. Emily Bender and Alex Hanna’s p…

via Sean Boots March 11, 2026

Generated by openring