# What's the shell command of importing a sql into a db . (MySQL, CentOS w/ cPanel)

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!

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.

• 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