In this article we will show you how to export and import a MySQL database via SSH. Managing your databases via SSH is especially useful when dealing with large databases (over 50Mb).
HostITSmart customers can find more information on how to connect to and use SSH in our SSH tutorial.
1. Exporting a MySQL database
To export a MySQL database, you need to use the mysqldump command. Here is the full command for exporting your database:
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. The name of the MySQL dump you are exporting to can be whatever you want.
2. Importing a MySQL database
To import a MySQl database, you need to use the mysql command. Here is the full command for importing a MySQL dump into a database:
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.