is this right?

mysql -uroot -ppassword mydb > myfile.sql.gz
link|improve this question

feedback

3 Answers

up vote 5 down vote accepted

zcat /path/to/file.sql.gz | mysql -u 'root' -p 'password' your_database

> will write the output of the mysql command on stdout into the file myfile.sql.gz which is most probably not what you want.

link|improve this answer
2  
As a good security practice, I would put my password on the command line, I would let mysql ask for it. – Prof. Moriarty May 3 '10 at 8:19
2  
Or even better: create ~/.my.cnf with the credentials. ;) – joschi May 3 '10 at 10:46
feedback

Also check if there is any USE-statement in the SQL file. Specifying the database at the command line doesn't guarantee that the data ends up there if a different destination is specified within the SQL file.

link|improve this answer
feedback

The simplest way is to unzip the database file before importing. Also as mentioned by @Prof. Moriarty you shouldn't be specifying the password in the command (you'll be asked for the password). This command taken from webcheatsheet will unzip and import the database in one go:

gunzip < myfile.sql.gz | mysql -u root -p mydb

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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