Backup/Export MySQL DB with CLI & mysqldump: VPS BIBLE




new password?
login
X

Backup a MySQL Database from the Terminal

mysql backup image

This guide shows how to save a MySQL database using a terminal, with a simple syntax command. And faster than using phpMyAdmin, for sure.

Just replace the db name, username and password and paste the code into your terminal.

While this is a handy how-to, probably you’ll want to perform frequent db exports and we’ll cover that later in the series, in the cron job tutorial.

For backing up your web or blog files, refer to Part 10: Backup Sites & Blogs from the Command Line.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

  .. from blank box to cute-as server ..  

with this easy-to-follow copy/paste guide.

22+ parts with video, here’s the index.

Dumping (that’s exporting, not erasing) the data from the MySQL database is the same procedure whether backing up locally or remotely except that, remotely, of course you have first to access the server, as we covered in the VPS Bible, Set Up the Command Line Interface (CLI) using PuTTY.

Once logged into the terminal, don’t bother further logging into the MySQL shell.

Just change directory to where you want to backup to, maybe creating a new folder (mkdir /path/to/new). So goto something like:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

And backup in there, using this syntax:-


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

You’ll be prompted for your db password and, once entered, the backup is created, super-fast, and you’re done.

“mysqldump” Syntax Broken Down

  • sudo gives Super User permissions, so you can perform the action
  • mysqldump is the command. We’re dumping a db into a backup folder
  • databasename is the name of the db
  • -u tells mysqldump we’re about to give the user details, after which we give the user’s name, with no space in between
  • -p tells mysqldump we’ll be authenticating with a password
  • > says the backup is to go in the direction of the file to create
  • some_db_backup_name.sql is the name of the backup file to be created

So, if I’ve got a database called “work”, my username is “guv” and my password is “abc”, I could use something like this below. (The one possible variable is the name of the backup file, which I can call whatever I like) ..


Please sign up for automatic premium content access.

Just $15/year* will save you hours, maybe days!

Alternatively, the vpsBible forum is free and you are welcome.

Prompted, after entering the db password, I’m done.

Setup Unmanaged VPS: The Ubuntu-Nginx Guide

Take your virtual private server from zero to hero

with this easy-to-follow copy/paste guide.

“My local PC runs Windows” Show me for Linux

22+ parts with video, here’s the index ..

Manage Unmanaged VPS: Ubuntu-Nginx Administration

Already set it up? We’d best maintain it then.

Toggle to the ..  Ubuntu-Nginx Admin Index

Manage Unmanaged VPS: Ubuntu-Nginx Administration

Maintain your virtual private server with ..

.. cheatsheets, tutorials, tips & guides.

Head back to the ..  Ubuntu-Nginx Installation Index

Nginx Admin: In the Works ..

This lot’s marked for addition already:-

  • Setup or Edit DNS using Bind
  • Network Tools Troubleshooting Guide
  • The Comprehensive Permissions Guide
  • Configuring Nginx Rewrites
  • Custom Website Error Page
  • Setting up Cron Jobs
  • Rsync for Incremental Remote-to-Local Backup
  • Cron & Rsync for Automatic Backup
  • Cron & mysqldump for Auto DB Backup
  • Safeguard Bandwidth with Hotlink Protection
  • Block Access with Nginx’ IP Deny



Got a Question? Want to Comment?

This site has no comments system. We've got a better system!

Please use the link at the top of the post and goto this topic's forum thread:-

  • to help build community
  • for a superior knowledge base
  • to keep info in one place, not diluted between forum & comments.

For those posts ported from Guvnr.com (pre-Feb/2010), archive comments remain.

Handy info from these comments is in the process of being ported to the forum and attributed to the original author.

If you think this idea sucks, let me know.

Thank you.