Importing & Exporting MySQL Databases on the Command Line (SSH)
Quite often, it can prove problematic dealing with large MySQL databases in a web interface such as phpMyAdmin. Working directly on the command line is far quicker and less painful if you’re having to import/export large databases.
The below commands only scrape the surface of managing databases directly on the command line but cover import/export.
Exporting MySQL Database
mysqldump -p -u username database_name > filename.sql
You will then be prompted to enter the password for the database user on the database you’re exporting from.
Importing MySQL Database
mysql -p -u username database_name < filename.sql
You will then be prompted to enter the password for the database user on the database you’re exporting into.
Replace the following with your database credentials:-
database_name = The name of the database you wish to export.
username = The name of the database user that has full access to the database you wish to export.
If you’re exporting a database to move from one server to another, you may want to CD into a publicly accessible (in the browser) directory on the server before running the export so that you can then use wget
to grab the .sql file from the other server (or you can just move it afterwards).