Learn How to Do-It-Yourself!

How to Import .SQL Dump File into MySQL

Execute SQL Statements from a SQL script file with the MySQL Command Line Client.

Open the MySQL Command Line Client and enter your password.
At the mysql command line type: USE your_db_name to change to the database you want to use for importing a SQL script file into.
Type in the mysql source or \. command, followed by the location of your script file to execute it against your database.

This tutorial goes through the steps of how to import a SQL script file into a MySQL database. The computer setup I'm using for this step-by-step guide includes Windows XP Professional and MySQL 5.0, however you should also be able to use this same process for importing SQL dump files with MySQL 4.1.

1. Open the MySQL Command Line Client and type in your password, and press Enter to login. See Figure 1.

2. Change to the database you want to use for importing the .sql file data into. Do this by typing

USE your_database_name

and press Enter.  See Figure 2.

For example the full line would look like: mysql> USE myTestDatabase

3. Now locate the .sql file you want to execute.  For instance if the file is located in the main local C: drive directory and the .sql script file name is currentSqlTable.sql, (See Figure 3) you would type the following:

\. C:\currentSqlTable.sql

and press Enter to execute the sql script file. 

For example, the full line would look like: mysql> \. C:\ currentSqlTable.sql

Note: You can use either the source or \. command to execute a SQL script file. For instance:

mysql> source file_name
mysql> \. file_name


_______________________________________
Save this  Email this  |  Digg this!  |  del.icio.us  |  RSS 

Related Articles


12 Comments

Finally! by Noodle on 1/28/2007
Wow, I've been looking for this for a while- and it's so simple once I found it!

Thank you very much for this information. I've already run the import, and I am back in business.
Thank you! by Raj on 9/4/2007
I have been looking for this command line stuff and yours was very simple to follow. Thank you for sharing it here.
The Dude by Tim on 9/6/2007
Sweet fancy Moses! Finally someone with some useful information! I had to dig through mountains of useless crap on other forums until I luckily stumbled upon this. Thanks a bunch.
Very useful direction by MV on 11/30/2007
Hi..This is very simple way to do the stuff and its working too...thanks a lot for your help...
Finally indeed! by George on 12/16/2007
I've been searching for this for I don't know how long. THANK YOU!!
Glad to help by kennard on 3/8/2008
Cool, I'm glad the tutorial has been beneficial to everyone!
awesome! by umair on 3/8/2008
i am deeply indebted to you.. thank you so much!
thanks by Ed on 3/27/2008
awesome
THANKS by RAFAEL on 4/18/2008
OOOHHH MYY GOOODD.. thank you.. incredible simple, but i habe been searching this for so long.. i ve found a lot of usuless import comands on net.. tanks for that
finally i found it by Vcaz on 5/2/2008
thanks a lot! this was what i was looking for.
thanks by mahesh on 5/6/2008
Thank you very much.
Thank u by Pradeep on 7/17/2008
Great work!
thank you!

Add your comment

by Anonymous - Already have an account? Login now!
Your Name:  

Title:  

Comment:  
Join now for free to keep track of all your comments and have them appear instantly.

Sponsored Links

Search for keywords: