Import/Export MySQL Database using command line

People often use phpMyAdmin to work with MySQL. It is a nice GUI tool to manipulate database very easily. But sometimes, it won’t work with some lengthy operations such as importing and exporting large databases. In such cases, we need to use command line interface to import/export mysql database.

Import database into MySQL

To import a sql file into a databasse, use below command.

Here, {username} is your mysql username, {password} is your mysql password, {db_name} is the database name on which you want to perform this opration, and {path_to_file.sql} is the absolute path to your sql file.

For example, if we want to import sql file to our database test_db,

You can also specify .zip and .tar.gz files if your sql dump file is compressed with zip or gzip.

Export database from MySQL

For example, if we want to export test_db to db_dump.sql file,

You can also export particular tables by specifying their name in above command. For example, to export only users table from test_db,

You may also like...