How do I dump a MySQL database schema?

By Alvin J. Alexander, devdaily.com

Use the mysqldump utility.

On a dos/windows pc with no name/password protection, you can dump a database named m y_db like this:

  mysqldump my_db

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



It is usually much more helpful to redirect this 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.


devdaily logo