How to export and Import mysql database using command line.


In order to export the database from mysql,Open your terminal and type the following command.

mysqldump -u [your_username] -p[your_database_password] [database_name] > path_to_your_directory/[database name].sql

Incase of database from remote server.

mysqldump -u [your_username] -p[your_database_password] -h [your_host_name] [database_name] > path_to_your_directory/[database_name].sql


In order to import the database to mysql,Open your terminal and first you need to create database.

To create database use following command.

CREATE DATABASE database_name;

Now import the database to newly created database using following command.

mysql -u [username] -p database_name < [database_name].sql

In case for remote database host.

mysql -u [username] -p -h [your_host_name] -D database_name < [your_sql_file].sql

Leave a Reply

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