共計 1844 個字符,預計需要花費 5 分鐘才能閱讀完成。
這篇文章將為大家詳細講解有關 MYSQL SOURCE 報錯 ERROR: ASCII 怎么辦,丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
由 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 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 –binary-mode to 1 if ASCII \0 is expected. Query: .
也許這種方式只有在導入 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 怎么辦”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。