19

I need to install or import a .sql file into an empty database that I've created. The .sql file will install all the tables etc.

When I click MySQL Command line Client prompt, I add my credentials and then...(to install / import the .sql file)?

Thanks guys!!

2
  • Ok, I've managed to install / import the .sql file. One thing I'd like to add to the answers below is when you type in the file name, eg: script.sql - make sure you include the path so that the command knows where to find the file, so you would put \. C:\yourdomains\thedomain\wwwroot\script.sql Commented Jan 16, 2012 at 17:29
  • Since you managed to solve your problem, please accept one of the answered that helped you - this will let people reading this page in the future know what helped. :) Commented Aug 2, 2012 at 17:24

5 Answers 5

29

Something like this:

shell> mysql db_name < script.sql

...specify your options: --user, --password, --host, --port...

More information - mysql — The MySQL Command-Line Tool.

Sign up to request clarification or add additional context in comments.

Comments

21

From the MySql prompt, type:

\. file_name.sql 

1 Comment

This is good to know, but it's slower than the mysql < file_name.sql when it contains 1000s of queries/inserts. For each insert, it will output: Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.02 sec) Query OK, 1 row affected (0.03 sec) , which can really slow things down.
7

What worked for me was- on command prompt:

mysql -u root -p < filename.sql

I read somewhere that to make things easier I should keep the file in the same root directory as my command prompt was in. After running the above command, it asked me for the password. Typed the password, hit enter and I was back on my command prompt. Got pissed, opened mysql prompt, checked, the imported DB was present. Happy!

2 Comments

u might want to include database name also: "mysql -u root -DBASE <database_name> -p < filename.sql"
I found that you don't need the -DBASE parameter and may simply write "mysql -u root <dbname> -p < filename.sql"
2

This is another way to do it in Linux

mysql databaseName -uUSERNAME -pPASSWORD -e "source LOCATION_OF_FILE"

Example:

mysql studentDB -ustudent1 -pstuden1Pass -e "source /tmp/studentInserts.sql"

Comments

1

just thought of perfecting the great answers from wise users. before importing a .sql database

  1. Create a new database or use existing database.
  2. if your .sql file is saved in F as script.sql provide command as . F:\script.sql enjoy...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.