How to import and export a mysql database via ssh Print

  • 54

A mysql database can be easily imported and exported via SSH:

1) You can export a MYSQL database with following command:

mysqldump -u username -p database_name > mysqlfile.sql
- replace 'username' with the username that has permission to export the database
- replace 'database_name' with the name of the database that you are exporting
- replace 'mysqlfile.sql' with a name of choice
 
Once you have filled in the details and pressed enter, it will ask for a password. Fill in the mysql password there from the 'username' and press enter again.

2)  You can import a MySQL database with following command:

mysql -u username -p database_name < mysqlfile.sql
- replace 'username' with the username that has permission to import the database
- replace 'database_name' with the name of the database that you are importing
- replace 'mysqlfile.sql' with the name of the .sql file you are importing
 
Once you have filled in the details and pressed enter, it will ask for a password. Fill in the mysql password there from the 'username' and press enter again.

Was this answer helpful?

« Back