Open In App

How To Export and Import a .SQL File From Command Line With Options?

Structured Query Language is a computer language that we use to interact with a relational database.SQL is a tool for organizing, managing, and retrieving archived data from a computer database. In this article , we will learn to export and import .SQL files with command line options.

Export:

You can export the database along with its structure into .SQL file using a command line tool called mysqldump as follows , 



Syntax :

mysqldump -h localhost -u username -p database > filename.sql



where,

For example, the complete command looks something like the below and creates a file by the name filename.sql.

Query:

mysqldump --column-statistics=0 -h 
localhost -u root -p --events 
--triggers --routines company  
> filename.sql

Output :

 

 

This has created the sql file with the given name.

Import :

You can import the database along with its structure into .SQL file using a command line tool called  mysql as follows , 

Syntax :

mysql -h localhost -u username -p database < input.sql

where,

For example, here we will import the filename.sql that was exported above:

Query:

mysql -h localhost -u root 
-p company < filename.sql

Output :

 

Now you can find the database company on the server.

Article Tags :
SQL