Export Database Using MySQL Command

Somedays ago, I have posted the way we can import SQL file using MySQL command. Beside importing, we also often need to export a database to a file then import it to other database. For example, if you have two server : one is for development and the other is for production. Say that your development is done and you need to move whole database from development into your production server (although Rails database migration can handle this, so this is just in case). This is how to do it using MySQL command line.


mysqldump -u username database_name > file_name.sql
The above command is the way to export your database to a sql file if your MySQL server is not password protected. If your MySQL is password protected, you should use the following command instead.

mysqldump -u username -p database_name > file_name.sql
That command will prompt you to insert your MySQL server password. Don't forget to change username and database_name into yours.