How do I load a sql.gz file to my database? (importing)

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.


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


  • 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.

Use the following command:

gunzip < databasefile.sql.gz | mysql -u root -p dbname