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 <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部分控制字元的截圖
詳細見我轉的文章:
http://blog.itpub.net/7728585/viewspace-2129010/
今天在群裡面有一個朋友給出一個錯誤:
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部分控制字元的截圖
詳細見我轉的文章:
http://blog.itpub.net/7728585/viewspace-2129010/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7728585/viewspace-2129019/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在 fish 終端下報錯 source: Error while reading file “xxx” 等問題ErrorWhile
- 安裝benchmarksql報java:143: error: unmappable character for encoding ASCIISQLJavaErrorAPPEncodingASCII
- mysql 5.7.21 CMake Error: The source directory "/data/server/mysql" does not appear to contain CMakMySqlErrorServerAPPAI
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile
- MySQL error 錯 誤 碼MySqlError
- MySQL建立觸發器時報錯Error Code: 1064MySql觸發器Error
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- Mysql資料庫報ERROR 1045 (28000)報錯及MySQL忘記密碼找回MySql資料庫Error密碼
- mysql匯入sql檔案報錯 ERROR 2013 2006 2002MySqlError
- MySQL8.0.28命中[ERROR][MY-013183]報錯案例分析MySqlError
- MySQL 5.6複製報錯Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;MySqlError
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- MySQL 報錯 ERROR 1290 (HY000): running with the --secure-file-privMySqlError
- mysql登入報錯提示:ERROR 1045 (28000)的解決方法MySqlError
- MYSQL5.7.22全庫備份匯入MYSQL8.0.20報錯ERROR3554MySqlError
- 【MySQL】ERROR 1290 (HY000): --secure-file-priv--匯出報錯MySqlError
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- 網站報錯:“Database Server Error”網站DatabaseServerError
- pip install scrapy報錯:error: UnableError
- mysql 5.6.25報錯ERROR 1372 (HY000): Password hash 的一點思考MySqlError
- idea報錯-source 1.5 中不支援 try-with-resourcesIdea
- MySQL主從同步報error 1236MySql主從同步Error
- MySQL 5.7 建立使用者報錯 ERROR 1805 (HY000): Column count of mysql.user is wrongMySqlError
- mysql 索引長度 767 錯誤 ERROR 1071MySql索引Error
- Centos7-mysql執行報錯ERROR1820(HY000):YoumustresetyourpasswordusingALTERUSERstatementbeforeexecutingthisstatement.CentOSMySqlError
- MySQL 5.7初始化報錯error while loading shared libraries: libnuma.so.1MySqlErrorWhile
- Ubuntu 系統 apt 報錯:relocation errorUbuntuAPTError
- weblogic報錯: OPatch failed with error code 73WebAIError
- ogg報錯error 11, Resource temporarily unavailableErrorAI
- 反序列 unserialize(): Error 報錯問題Error
- SyntaxError: Non-ASCII character 與 Cannot decode using encoding "ascii" 錯誤解決ErrorASCIIEncoding
- MySQL中的source命令MySql
- Mysql連線錯誤ERROR 2003 (HY000)MySqlError
- 2、MySQL錯誤日誌(Error Log)詳解MySqlError
- DZ論壇MySQL Query Error Errno:1046錯誤MySqlError
- Mysql啟動報錯:Job for mysqld.service failed because the control process exited with error code.MySqlAIError
- MySQL主從複製報錯:Got fatal error 1236 from master when reading data fromMySqlGoErrorAST
- MySQL建立使用者報錯 ERROR 1396 (HY000): Operation CREATE USER failed for 'afei'@'%'MySqlErrorAI