Step 1. Export A MySQL Database
It is a good idea to export your data as often as possible for backup or for moving data from localhost to server.From SSH or command shells, execute the following command:
mysqldump -u username -p database_name > dbname.sqlYou will be prompted for a password, type in the password for the username and press Enter. Replace username, password and database_name with your MySQL username, password and database name.
File dbname.sql now holds a backup of your database and is ready for download to your computer or upload to server. If you just want to backup a specific table, use this command:
mysqldump -u username -p database_name table_name > dbname.sqlOne more thing you can do is gzip the file to save the upload/download time, I find gzipping reduces the file size 6 times in my case. From SSH, execute the following command:
gzip dbname.sqlThe final file will has the form dbname.sql.gz
Step 2. Import A MySQL Database
In case you used gzipped file, you need to ungzip in as the importing file must be in .sql format. From SSH, navigate to the directory where your .gz file is and execute the following command:gunzip dbname.sql.gzWhen you have your .sql file, run this command:
mysql -p -u username database_name < file.sql