RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
MYSQLSOURCE报错ERROR:ASCII怎么办

这篇文章将为大家详细讲解有关MySQL SOURCE报错ERROR: ASCII怎么办,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

成都创新互联是一家集网站建设,麻阳企业网站建设,麻阳品牌网站建设,网站定制,麻阳网站建设报价,网络营销,网络优化,麻阳网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

由 ASCII '\0' 引起的MYSQL SOURCE错误

有一个朋友给出一个错误:
source test.sql
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 --bin
ary-mode to 1 if ASCII '\0' is expected. Query: ''.


以前没见过这个错误,于是仔细看了一下。先根据报错查看--binary-mode的意思:
  --binary-mode       By default, ASCII '\0' is disallowed and '\r\n' is
                      translated to '\n'. This switch turns off both features,
                      and also turns off parsing of all clientcommands except
                      \C and DELIMITER, in non-interactive mode (for input
                      piped to mysql or loaded using the 'source' command).
                      This is necessary when processing output from mysqlbinlog
                      that may contain blobs.


意思就是ASCII '\0' 是不允许的,除非在binary mode下,为什么会不允许呢?
原因在于一个存文本模式的sql脚本不可能存在'\0','\0'对应ASCII的00,NUL,
我们知道在纯文本模式下,任何字符都对应自己的编码,即使是空格、换行、回车、制表符等
,00 NUL只会在二进制模式的文件中才有,当使用非交互模式的时候,比如
在mysqlbinlog|mysql -u root -p 时候是用会关闭,但是我测试了一下也不行
不管使用pipe管道还是重定向都不行:
[root@testmy ~]# cat test.sql|/mysqldata/mysql5.7/bin/mysql  --socket=/mysqldata/mysql5.7/mysqld3307.sock  
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: ''.
[root@testmy ~]# /mysqldata/mysql5.7/bin/mysql  --socket=/mysqldata/mysql5.7/mysqld3307.sock 也许这种方式只有在导入ROW格式的binlog才会用到吧。




下面是重现方式,简单的代码:
#include
#include




int main(void)
{
   FILE* fd;
   char a='\0';
   
   if(!(fd = fopen("test.sql","a+")))
        {
                perror("error:");
                exit(1);
        }
   fputc(a,fd);
   fputc('\n',fd);
   fclose(fd);
}


向test.sql写入一个\0即可,就可以重现了。下面是一个ASCII部分控制字符的截图
MYSQL SOURCE报错ERROR: ASCII怎么办

关于“MYSQL SOURCE报错ERROR: ASCII怎么办”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


网站栏目:MYSQLSOURCE报错ERROR:ASCII怎么办
网页地址:http://sczitong.cn/article/peijpg.html