Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

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
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 '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
add comment

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

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

Your Answer

 
discard

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.