I have a big sql file (~ 60MB) exported from local development site, and I want to import to my server (running CentOS 5).

Lets say

  • the dump file is dump.sql, uploaded to the server.
  • the database name is mydb.

I want to do with via ssh, what is the shell command to do so?

Thanks!

link|improve this question

feedback

1 Answer

up vote 6 down vote accepted

You can import (execute) an SQL file using the following command:

$ mysql -u user -p mydb < dump.sql

If you exported your data using some tool other than mysqldump, you may have troubles restoring your dump file. I ran into such a problem when I exported the database using phpmyadmin and imported it using the command line. To export your database, you can use:

$ mysqldump -u user -p mydb > dump.sql

For more options, you can see the help of each one of these tools.

link|improve this answer
thanks. is the command OS-dependent? I mean: if I dump mysql from my MacOS use the above mysqldump command, then import to my Linus server my the mysql. Would this be fine? – gilzero Jan 8 at 11:27
1  
It should work. The exported file is a text file. It is not binary. So, it should be OK. However, you have to confirm you got a text file with the correct encoding. – Khaled Jan 8 at 11:29
Out of curiosity, what was your compatibility problem with phpmyadmin? I've never had one but frequently export and import MySQL tables in that manner. – user68912 Jan 8 at 15:49
@Tim: I can't remember exactly, but either I could not import the file because of errors or I got corrupted text (encoding error). – Khaled Jan 8 at 16:06
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.