Open Laboratory for Technocrats

Grab the developer role, learn concepts & prepare with senior software engineers to get solutions for problems in a software job. Coding and Programming Solutions crafted for you.

Mysql - Import Sql data from file - CommandLine


For this we must have a DOT SQL file which holds the data to be imported to the database/ table.
Lets call the
    DOT SQL file as importdata.sql
    DB Username as dbuser
    Database Name as testDB
Open the command line interface or terminal first.
Move to the folder where the file importdata.sql is present.
Assuming that it is present at this location
/home/developer/Downloads/importdata.sql
Move to file folder
cd /home/developer/Downloads/
Now we will have to check if the database is existing or not.
If its existing then run command
mysql -u dbuser -p testDB < importdata.sql
It will ask you for the password for database user.
If we need to make a new database then first create the database as
CREATE DATABASE testDB;
Now above command can be run to import the data as
 mysql -u dbuser -p testDB < importdata.sql
It will ask you for the password for database user.
Now the data from the sql file is imported to Mysql.

Happy Coding :)






Top #3 Articles

Most Read