mysqldump command - how to dump (backup) a MySQL database

MySQL backup FAQ - How do I backup/dump a MySQL database schema?

Answer: Use the mysqldump database utility.

MySQL dump examples using the mysqldump utility

On a DOS/Windows pc with no name/password protection, you can dump a database named my_db with the following command, but don't do this just yet:

mysqldump my_db

Note that this gets you not only the database schema, but also the current data in the table.

The reason I said not to run that command yet is because it prints its output to your screen. It is usually much more helpful to redirect your mysqldump output to a file:

mysqldump my_db > my_db.sql

In a more complex example where you must know the username and password to dump the database this command will work:

mysqldump --opt --user=root --password my_db > my_db.sql

Note that MySQL will prompt you for the database password.

More MySQL database backup tutorials

If this quick mysqldump tutorial wasn't helpful, fear not, I have plenty of other MySQL dump and backup tutorials on this website. Just use the search form to find them, or look for the "Related" block near this article to find those other MySQL dump and backup tutorials.

Update: This MySQL database dump/backup shell script may be the most helpful of anything I've written lately. It is a complete mysqldump shell script, showing several variations of the mysqldump command.