How to Import .SQL Dump File into a MySQL database

Execute SQL Statements from a SQL script file with the MySQL Command Line Client.
by Updated January 29, 2009

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

 


0
22

22 Comments

anonymous 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.
anonymous by Raj on 9/4/2007
Thank you! I have been looking for this command line stuff and yours was very simple to follow. Thank you for sharing it here.
anonymous 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.
anonymous 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...
anonymous by George on 12/16/2007
Finally indeed! I've been searching for this for I don't know how long. THANK YOU!!
Doug by Doug on 3/8/2008
Cool, I'm glad the tutorial has been beneficial to everyone!
anonymous by umair on 3/8/2008
awesome! i am deeply indebted to you.. thank you so much!
anonymous by Ed on 3/21/2008
thanks! awesome
anonymous by RAFAEL on 4/18/2008
THANKS 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
anonymous by Vcaz on 4/24/2008
finally i found it. thanks a lot! this was what i was looking for.
anonymous by mahesh on 5/2/2008
Thank you very much.
anonymous by Pradeep on 5/27/2008
Great work!
thank you!
anonymous by syum on 10/22/2008
It was really helpful for me. I've been looking almost all over the net to find out this.
It is pretty cool and works fine.
Thanks
anonymous by Jay on 10/27/2008
Simple yet effective. very well done with the tutorial.
anonymous by Ernest fakudze on 11/12/2008
Thank you sir. This saved me a great deal of time. Please keep up the good work.
anonymous by Eldar MAMMADOV on 11/14/2008
Very goood method to import sql file into database!
I was looking for this a long time.
Thank a lot bro!
You are the best!
anonymous by Tony Dunsworth on 11/23/2008
Thanks for the simple answer, much appreciated
anonymous by Anil on 1/4/2009
Hi man thanks for the info.
It helps me alot.
anonymous by Raja on 1/15/2009
Amazing Thanks a lot mate..
anonymous by Andrew on 2/1/2009
Man! This is freaking amazing, thank you for saving all these's people's jobs :D:D:D
anonymous by smudge on 3/6/2009
This is great. It would be great if you can add the link to upload from a non-local source, lets say you're uploading a dump-backup on your remote server via SSH for example.

Alternatively, how to 'LOAD' it via phpmyadmin would be handy. Many thanks.
anonymous by pranali on 3/14/2013
thanks..a lot..its really help me a lot

Add your comment

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

Comment:
Enter the text you see in the image below
What do you see?
Can't read the image? View a new one.
Your comment will appear after being approved.

Related Posts


This step-by-step goes through the process of importing delimited text files into a SQL Server 2005 database. The example should help you better understand how to import different types of flat files into SQL Server 2005.  more »