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
- Email FAQ to a friend
- Printable version
- Rss Feed
- Last Updated: 10-3-07

{ 10 comments… read them below or add one }
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)
Worked like a charm! I did have to remove the spaces as Cameron suggested (thanks). I’m running Fedora Core 7.
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
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
Thanks to Cameron James. Removing the spaces did it for me as well. Fought with that sucker for almost 4 hours…
thanx a lot for this script. and thanks cephalex for utf8 option.
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
Very nice tut ! I just moving from another host to a new one. This commands works perfectly :)
Thx a lot ;) Very usefull tips
If Your Using Red Hat Linux,
take the $ out.
and try this,
mysql -u username -p -h localhost data-base-name < data.sql
Thanks