In previous article, I mentioned how to import csv file in sql server and Error Code: 1175 - You are using safe update mode but now in this article, I will discuss how to Import an SQL file in MySQL using command prompt (CMD) or Powershell or using MySQL workbench.

Using Command Prompt (CMD)

It is very easy to import .sql file in MySQL database using command prompt, simply open CMD in Administrator mode, navigate to the directory where you have MySQL located and then use below command

mysql -u username -p database_name_in_which_data_to_save < fullpath_of_file.sql

where username = login username of MySQL

database_name_in_which_data_to_save = database name, where we need to import data.

If you are importing a large .sql file in MySQL, you need to turn-off Auto-commit using MySQL Command line first

mysql> use database_name;
mysql> SET autocommit=0 ; source your_sqlFile.sql ; COMMIT ;

Note: For the Windows users, if you get the "MySQL is not recognized" as CMD error, you will need to add the Mysql folder into the system environment path. 

In Linux

You will have to run below command in MySQL Shell to import db

shell> mysql -u root -ppassword #note: no space between -p and password
mysql> CREATE DATABASE databasename;
mysql> using databasename;
mysql> source /path/to/backup.sql

In Unix

Use the below command

mysql db_name < backup-file.sql

In Mac Os X

/Applications/xampp/xamppfiles/bin/mysql -u root -p database < database.sql

you can replace xampp with mamp or other web servers.

Using Powershell

You can also import .sql file in MySQL using powershell in Windows, here is the command to use for it.

cmd.exe /c "mysql -u root -p db_name < backup-file.sql"

Using MySQL Workbench

Here are the steps to import .sql file using MySQL Workbench

  • Launch MySQL Workbench.
  • Add a connection to your database, then connect to the database
  • Select Server -> Data Import
  • In "Import from disk"-> select "Import from self-contained file" and then search for .sql file and select it.
    import-sql-file-mysql-using-workbench
  • Click "Start Import" to begin the import process. Use the Import Progress tab to monitor the progress.

That's it, hope you are able to import SQL File in MySQL Easily considering above solutions.

You may also like to read:

Error Code: 1175 - You are using safe update mode

How to add authorization header in postman?

How to detect click outside an element (or div)?