38
votes

is this right?

mysql -uroot -ppassword mydb < myfile.sql.gz
6

6 Answers

98
votes

No, it isn't. The right way would be

zcat myfile.sql.gz | mysql -u root -ppassword mydb

Note there can be no space between the -p and password if using the -p syntax, refer http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_password

41
votes

Use the following command:

gunzip < databasefile.sql.gz | mysql -u root -p dbname
4
votes
  • You must not use the password directly in the terminal, use without it like follows
zcat YOUR_FILE.sql.gz | mysql -u YOUR_DB_USERNAME -p YOUR_DATABASE_NAME
  • Hit enter and when terminal asked for your password, type your password and hope everything will work fine.
2
votes

Straight and clear:

gunzip -c myfile.sql.gz | mysql -uroot -ppassword mydb

-c option for gunzip writes to stdout, keeps original files

NOTE: You shouldn't put the password directly in the command. It's better to provide just -p and than enter the password interactively.

0
votes

For Generating dbName.sql.gz

mysqldump -u <YOUR USERNAME> -p<YOUR PASSWORD> <YOUR DBNAME> | gzip > ~/mysqlBackup/dbName_`date +%Y%m%d%H%M`.sql.gz

For Loading dbName.sql.gz

zcat ~/mysqlBackup/<.SQL.GZ file> | mysql -u <YOUR USERNAME> -p<YOUR PASSWORD> <DATABASE NAME IN WHICH YOU WANT TO LOAD>
-1
votes

You have to follow below steps:

  • First check Mysql service should be running.

  • Then if you have compressed file, decompress it first.

  • Then you will find .sql file after decompressing.
  • Then find import data in left corner in Mysql.
  • Select option import from self-contained file and select your .sql file and specify a new schema name.
  • Then click on import data.
  • After importing you will see your new schema in available schema list.