久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

MYSQL SOURCE報錯ERROR: ASCII怎么辦

146次閱讀
沒有評論

共計 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 怎么辦”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-26發表,共計1844字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 岢岚县| 龙岩市| 贵南县| 察哈| 渭源县| 资阳市| 山东省| 和田市| 宿迁市| 巫溪县| 会泽县| 万盛区| 霍山县| 肥东县| 库尔勒市| 茂名市| 三原县| 新余市| 三都| 姚安县| 潜山县| 琼中| 灵丘县| 惠安县| 登封市| 娱乐| 安溪县| 海门市| 济南市| 徐州市| 大理市| 锡林浩特市| 体育| 锡林郭勒盟| 大城县| 渑池县| 冷水江市| 那坡县| 丹东市| 靖江市| 兴国县|