1

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!

gilzero
  • 439
  • 4
  • 9
  • 20

2 Answers2

7

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.

Khaled
  • 36,533
  • 8
  • 72
  • 99
  • 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 08 '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 08 '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. –  Jan 08 '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 08 '12 at 16:06
1

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

mysql> use mydb
mysql> source dump.sql
womble
  • 96,255
  • 29
  • 175
  • 230
Thukten
  • 11
  • 1