Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
up vote 7 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.

share|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 '12 at 11:27
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 '12 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 '12 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 '12 at 16:06

The other option is to do this from within the MySQL shell:

mysql> use mydb
mysql> source dump.sql
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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