Ubuntu Terminal: How to Quickly Create a SQL Dump File from a MySQL Database

Backing up your MySQL database or generating a copy of it to shift around is quite a simple affair thanks to the powerful mysqldump command that ships with MySQL.

To generate a backup sqldump, simply execute:

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

Note the lack of a space between -p and the password! Obviously if you don’t have a password assigned, simply omit the -p switch.

And that is it, all done! :)

Note, restoring a database from a mysqldump is as simple as: mysql -u [MySQL user, e.g. root] -p[database password] < sqldump.sql

You might also enjoy:

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in Software & Websites, Tutorials and tagged , , , , , , , . Bookmark the permalink.
  • http://blog.sven.co.za Sven Welzel

    Just as a quick note — --opt replaces and automatically sets (by default, by the way) --add-drop-table, --add-locks, --quick, --lock-tablesand auto-adds --create-options and --set-charset (which is quite useful), so a rewrite would be:

    mysqldump -h HOST -u USER -pPASSWORD -c --opt --all DATABASE > sqldump.sql

  • http://www.craiglotter.co.za Craig Lotter

    Fantastic. Thanks for the heads up on the shortened form then Mr. Sven! :)

blog comments powered by Disqus