无法将MYSQL备份还原到新数据库 [英] Unable to restore a MYSQL backup to a new Database

查看:146
本文介绍了无法将MYSQL备份还原到新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用

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

和:

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

推荐答案

这可能是由编码系统引起的.
我的转储文件是在Powershell中使用重定向(>")生成的,并且遇到了相同的问题.输出重定向生成了带有UTF-16 Little endian的文件.

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.

但是,可以通过将转储文件转换为utf-8来解决.可以在emacs中完成以下操作:

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

M-x设置缓冲区文件编码系统

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

然后保存文件并再次导入.

Then save the file and import again.

可以使用GNU文件"实用程序检测文件的编码系统,并且该文件也可以在Windows中使用,并且可以在以下位置找到:

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>

这篇关于无法将MYSQL备份还原到新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆