How to export or import a MySQL database via SSH

Importing a MySQL database

To import a MySQL database, use the mysql command.

mysql -u USERNAME -p PASSWORD DATABASE < backup.sql

Make sure you replace USERNAME, PASSWORD and DATABASE with the appropriate values for your database. For DATABASE you must use an existing database.

Exporting a MySQL database

To export a MySQL database, use the mysqldump command.:

mysqldump -u USERNAME -p PASSWORD DATABASE > backup.sql

Make sure you replace USERNAME, PASSWORD and DATABASE with the appropriate values for your database. The MySQL database will be exported to a file named "backup.sql" in your current directory.

Leave a Reply

Your email address will not be published. Required fields are marked *