溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MYSQL SOURCE報錯ERROR: ASCII怎么辦

發(fā)布時間:2021-11-06 15:42:55 來源:億速云 閱讀:2522 作者:小新 欄目:MySQL數(shù)據(jù)庫

這篇文章將為大家詳細講解有關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: ''.


以前沒見過這個錯誤,于是仔細看了一下。先根據(jù)報錯查看--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才會用到吧。




下面是重現(xiàn)方式,簡單的代碼:
#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即可,就可以重現(xiàn)了。下面是一個ASCII部分控制字符的截圖
MYSQL SOURCE報錯ERROR: ASCII怎么辦

關于“MYSQL SOURCE報錯ERROR: ASCII怎么辦”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI