How do I make an sql dump of a MySQL database on the command line?

If your MySQL user has a password:

mysqldump -h localhost -u [MySQL user, e.g. root] -p[database password] -c --add-drop-table --add-locks --all --quick --lock-tables [name of the database] > sqldump.sql

Please note:  there's no space between -p and the password!

If there's no password:

mysqldump -h localhost -u [MySQL user, e.g. root] -c --add-drop-table --add-locks --all --quick --lock-tables [name of the database] > sqldump.sql

Share this page:

2 Comment(s)

Add comment

Comments

From: Reinier Battenberg at: 2009-01-14 08:07:04

If you want to dump all databases in your server (for backup or migrating purposes) you can add the

--all-databases

option. Very useful.

From: Anonymous at: 2010-09-02 19:19:38

Yes, it works. Thanks