Backup and Restore MySQL from the command line (CLI)

I use MySQL.  I like MySQL... but I don't trust MySQL. 

Actually, I don't trust anything computer-based, its nothing against MySQL at all... so I like to back up my databases from time to time.

Now because I have my own server, I can use the command line to do most of my management, which I prefer,  but try as I might the backup and restore commands escape me every time I go to use them... so here they are, just for me (and you too)

to back up:

mysqldump -u username -p databasename > backupfile.sql

To restore:

mysql -u username -p databasename < backupfile.sql

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <python>. The supported tag styles are: <foo>, [foo], [[foo]].
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, css, jscript, java, php, python.

More information about formatting options

This question is to prevent automated spam submissions. Upper or lower case does not matter. If you can't read it properly, just submit what you believe it says and if its wrong you will be presented with a new captcha image.
Enter the characters shown in the image.