Backup and Restore MySQL Databases

To export a MySQL database into a dump file:

$ mysqldump -u username -ppassword db_name > db_name.sql

(No, that’s not a typo; there is no space between -p and password.)

Data, tables, structures and database of database_name will be backed up into a SQL text file named db_name.sql.

To import a MySQL database, upload the dump file to the MySQL server, and use the following command to import the databases back into the MySQL server:

$ mysql -u username -ppassword db_name < db_name.sql