mysqldump 导出来的文件,使用 source还原时报错“ASCII '\0' appeared in the statement, but this is not allowed unless option”

发布时间 2023-10-08 14:21:19作者: darling331

导出语句:mysqldump -uroot -pword --databases db1 --tables table1 > ./sqldumps/archive-table1-`date +"%Y%m%d_%H%M%S"`.sql
导出后,使用source还原 报错:ASCII '\0' appeared in the statement, but this is not allowed unless option
我开始以为是我导出的编码格式有问题,换了新的导出语句,指定导出的编码格式
mysqldump --default-character-set=utf8 -uroot -pword --databases db1 --tables table1 > ./sqldumps/archive-table1-`date +"%Y%m%d_%H%M%S"`.sql
使用source 还原,还是报一样的错,后来发现是,链接mysql的时候,需要增加参数。--binary-mode=1
mysql --binary-mode=1 -uroot -p
如果是windows系统部署的mysql 可以使用下面的命令
进入到mysql的部署目录,然后,执行mysql.exe文件,带参数
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql.exe -u root -p --binary-mode=1
输入密码
show databases;
use db1;
source 绝对路径的SQL文件
即可进行数据还原