Unable to restore a MYSQL backup to a new Database

2019-05-24 03:54发布

问题:

I successfully created a mysqldump file myDump.sql of a myDb1 database using guidelines from this thread. Also I created a second database myDb2, navigated to the directory containing myDump.sql and trying to restore it into the new database myDb2 but failing, Two methods I tried:

> mysql -u root -p myDb2 < myDump.sql;
> -- entered password

and:

> mysql -u root -p
mysql> -- entered password
mysql> USE myDb2;
mysql> SOURCE myDump.sql;

Both have the same error message:

ERROR:
ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in
 non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: ' ■-'.

I'd also like to know if I need to use the same database name as the old db for the new one. I tried with a different and same names, but with this same result error.

回答1:

This is probably caused by coding systems.
My dump file is generated using redirection (">") in powershell and I encountered the same problem. The output redirection generated a file with UTF-16 Little endian.

However, this can be solved by converting the dumpfile into utf-8. This can be done in emacs as:

M-x set-buffer-file-coding-system

Then save the file and import again.

The coding system of a file can be detected using GNU "file" utility, and it also available in windows and can be found here: http://gnuwin32.sourceforge.net/packages/file.htm
For future use, a better dump command like:

mysqldump <dbname> -r <filename>



回答2:

Check the myDump.sql file, it maybe a coding error in the file. These garbage characters cause this problem. Delete the garbage characters to solve the issue.

Open with Sequel Pro shows this

`í}k¯]ÇÝçðWÜ?øy«««_%c�sè;¶`Ìô hãEE¤"8Áü÷ô>ûqzW¯:êmX0`²¸yyëÔºµë¹êGw?û+þ{ð£»g¯ÿçw¯¿ºû/ß¾¹{ö/ï^}÷§oªô__ûöË7_ß'éÁªà¿¿{÷ÍÇ}ôý÷ßOo/ãoßL_¼ùÓG×?ûâÍ«×Óß¼ùãW¯/òÍGË?`