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 :)






ERROR 2002 (HY000): Can't connect to MySQL

ERROR 2002(HY000):Can't connect to local MySQL



This is error can come to you anytime but with a reason behind it. When you face this issue generally everyone goes to search engine and try to solve the issue and finally after some time its got solved.

Now while going through a upgrade or update from one level to another level this kind of things happens.

Solution that easily come up with this search -

  • Check that you have client or server of mysql version
  • If not server then install it by running the command on your linux [Ubuntu] Terminal
  sudo apt-get install mysql-server

If that's not the case try the following steps to figure out as I have also figured out same as


  • 1. Log in as a super user or use sudo
  • 2. Open the mysql's config file as /etc/mysql/my.cnf
  • 3. Find bind-address and then change the address to IP of the machine of Database for me it was localhost
  • 4. Save and close
  • 5. Restart the mysql by going to terminal and run command

  sudo service mysql restart


If everything is same as above written then just go to terminal and restart the mysql and it will work fine.

If anything just comment below to get out of your situation which is irritating you.

Top #3 Articles

Most Read