Import MySQL dumpfile, SQL datafile into my database

by Vivek Gite · 21 comments

Q. How can I import a MySQL dumpfile into my database? My old hosting provider gave me data.sql file. I do have access via ssh to server. I'm using CentOS Linux 5 server.

A. You can easily restore or import MySQL data with mysql command itself. First you need to login to your system using ssh or putty (from Windows based system). For example:

Type the following command at the shell prompt:

$ ssh loginname@server.hosting.com

Now type following command to import sql data file:
$ mysql -u username -p -h localhost data-base-name < data.sql

If you have dedicated database server, replace localhost name with actual server name or IP address:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.hosting.com
$ mysql -u username -p -h mysql.hosting.com database-name < data.sql

If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 21 comments… read them below or add one }

1 Cameron James 10.13.06 at 4:31 pm

If you’re having troubles try removing the space between -u and the username (eg: -uusername), -p and the password (eg: -ppassword), -h and the host (eg: -h11.11.11.11)

2 Steven Richards 07.04.08 at 1:59 am

Worked like a charm! I did have to remove the spaces as Cameron suggested (thanks). I’m running Fedora Core 7.

3 mosh 08.12.08 at 5:10 pm

I’m so stupid ;)
I have decicated server and I was using all the time phpMyAdmin … that was terrible….

now I import DB in 2 sek :D

THX a lot for this very important for me command :)

Greetings, mosh

4 Cephalex 11.04.08 at 10:45 pm

if you want to import an UTF8 database you can use this command

$mysql -u databaseuser -p -h localhost –default-character-set=utf8 databasename < sqlfile.sql

5 Maple Syrup 01.16.09 at 8:55 am

Thanks to Cameron James. Removing the spaces did it for me as well. Fought with that sucker for almost 4 hours…

6 kiran and niraj 02.05.09 at 10:17 am

thanx a lot for this script. and thanks cephalex for utf8 option.

7 lady 02.13.09 at 1:24 am

can anyone help me how to start using php in linux?i already installed it but i do not know how to run it using command line.
and one more thing how to convert data from pcap to mysql?
please give me a hint on how to start the program

8 fmuteam 03.24.09 at 5:27 pm

Very nice tut ! I just moving from another host to a new one. This commands works perfectly :)

9 Nordes 06.17.09 at 2:33 am

Thx a lot ;) Very usefull tips

10 Brandon Broga 06.29.09 at 5:18 pm

If Your Using Red Hat Linux,
take the $ out.

and try this,

mysql -u username -p -h localhost data-base-name < data.sql

Thanks

11 Bhargav 07.28.09 at 8:28 pm

tnx … easy to understanc

12 Sandeep Tagore 07.30.09 at 9:39 am

go to mysql folder and execute this command:
[root@localhost mysql]# bin/mysql [Database Name] < /home/sandeep/software/[file-name].sql

13 hammad 09.04.09 at 1:12 am

I installed oracle 11g, but I want to know who do I create database table in it and also describe me about how to type command to see the database table in Sql.

14 bhavesh 10.23.09 at 6:39 am

I want to add a “login” feature to my website, that consists of an email address, password and a unique user ID. The feature should also be able to store the names, send an email verification reply, provide for emailing the user for forgotten passwords, etc.

plz replay me on my mail id.

I am totally new at mysql data base and php script.

bksondagar

15 hary 12.30.09 at 9:25 am

thx a lot, it’s very helpfull for me.

16 Wild_Bill 01.05.10 at 5:24 pm

Thanks alot for these. Its helped me out of a big jam that I was in..

17 Aashish 01.08.10 at 5:26 pm

mysql -u username -p data-base-name < data.sql

the above statement running but tables are not created in database

18 Aashish 01.08.10 at 5:45 pm

mysql -u username -p data-base-name < data.sql
gives error , can u help me
ERROR 1227 (42000) at line 500: Access denied; you need the SUPER privilege for this operation on win

19 sasikala 01.27.10 at 8:01 am

How can I import a MySQL dumpfile into my database?
am using windows..

20 sascha 02.07.10 at 8:28 pm

yeah, everywhere instructions how to import sql file when it is stored in web server, but nowhere when it is stored in desktop. absolutly no one give us command how to upload stupid mysql file from desktop to web server without phpmyadmin.
I use Joomla 1.0.x CMS, and they have plugin to export but there is no import button in plugin and I don’t have command.

21 Vivek Gite 02.08.10 at 5:29 am

Upload file to your server using ftp or sftp client. Once uploaded run above mysql command.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All