How do I load a sql.gz file to my database? (importing)
is this right?
mysql -uroot -ppassword mydb < myfil开发者_JAVA百科e.sql.gz
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
Use the following command:
gunzip < databasefile.sql.gz | mysql -u root -p dbname
- 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.
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.
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>
On windows you can do this:
First step! Install gzip for windows. I recommend using chocolatey to do it: (https://chocolatey.org/install)
choco install gzip -y
Now you can descompress your gz file and send it to mysql:
gzip -cd backup.sql.gz > mysql -uUSER -pPASSWORD -hLOCALHOST DATABASE
Good luck!
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.
精彩评论