SQL syntax error near gunzip when restoring a data

2020-05-26 15:07发布

问题:

I am trying to restore a mysql db using a .sql.gz file. I am using mySql console to run a command because file size is too large for phpMyAdmin. Command I am using is

gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd

where root is the user id. There is no password for root. bd is the database to which I am trying to import. mysql is running on my local machine (Windows 8). I have a wamp setup.

This is the error I am getting:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'gunzip C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql | mysql -u root -p' at line 1.

回答1:

If you type gunzip and you get a SQL syntax error that complaints about gunzip, you are already logged into the mysql console. The mysql console is not a general purpose shell!

You are using Windows and I suspect you haven't installed gzip in your computer (it isn't a builtin utility). It's a classical Unix tool but you can find binaries for Windows. Install it and run your original command with a couple of tweaks:

  1. Make sure you're in Windows prompt (C:\>)

  2. Redirect gunzip result to stdout rather than a file:

    gunzip --stdout C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
    

Alternatively, you can run the dump from within MySQL promt (mysql>) if you uncompress it first (you don't need specifically command-line gzip, most GUI archivers such as 7-Zip support this format):

mysql> \. C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql


回答2:

You need -c option (output to stdout)

gunzip -c xxx.sql.gz |mysql -u root -p


回答3:

While Kisoft´s answer is the correct one, I just wanted to point out that you don´t need the -c, it works just fine as it is. this command will unzip the database dump and import it into the database at the same time.

gunzip < output.sql.gz | mysql -u <username> -p<password> <database>


回答4:

Your answer is already here

phpMyAdmin: Can't import huge database file, any suggestions?

Under php.ini file, normally located in c:\xampp\php or wampp whatever you called

post_max_size=128M
upload_max_filesize=128M

Changing value there will get you what you want.Good luck Dont forget to restart , apache and mysql .



回答5:

you do not need to gunzip just: zcat myfile.gz | mysql -uuser -ppassword mydatabase it is faster this way



回答6:

Try this following steps to restore db using .gz files:

1. Run command : gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz

This will uncompress the .gz file and will just store beed_2013-04-06.sql in the same location.

2. Type the following command to import sql data file:
      mysql -u username -p bd < C:/Vik/Gya/Source/beed_2013-04-06.sql