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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql報錯ERROR 1093MySqlError
- MySQL報錯 Error_code: 1045MySqlError
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError
- 在 fish 終端下報錯 source: Error while reading file “xxx” 等問題ErrorWhile
- MySQL error 錯 誤 碼MySqlError
- vipca報錯 Error 0PCAError
- mysql 5.7.21 CMake Error: The source directory "/data/server/mysql" does not appear to contain CMakMySqlErrorServerAPPAI
- 安裝benchmarksql報java:143: error: unmappable character for encoding ASCIISQLJavaErrorAPPEncodingASCII
- Mysql資料庫報ERROR 1045 (28000)報錯及MySQL忘記密碼找回MySql資料庫Error密碼
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- MySQL 5.7.17 安裝報錯SSL error: Unable to get private key fromMySqlError
- MySQL 5.5 原始碼安裝報錯"[ERROR] Can't start server"MySql原始碼ErrorServer
- 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 while loading shared librariesMySqlErrorWhile
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- Oracle安裝報錯syntax errorOracleError
- struts2報Error filterStart錯ErrorFilter
- 網站報錯:“Database Server Error”網站DatabaseServerError
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- MySQL5.6:mysql_secure_installation 報錯ERROR 2002 (HY000)MySqlError
- mysql登入報錯提示:ERROR 1045 (28000)的解決方法MySqlError
- MySQL8.0.28命中[ERROR][MY-013183]報錯案例分析MySqlError
- mysql執行sql指令碼報錯ERROR 1366 (HY000) 解決MySql指令碼Error
- MySQL 5.7 多主複製報錯Coordinator stopped because there were error(s)MySqlError
- MySQL 5.7.17 安裝報錯CMake Error at cmake/boost.cmake:81 (MESSAGE)MySqlError
- MySQL 5.5 報錯"ERROR 1075 (42000): Incorrect table definition"MySqlError
- idea報錯-source 1.5 中不支援 try-with-resourcesIdea
- MySQL報錯'ERROR 2002 (HY000): Can't connect to local MySQL server through'MySqlErrorServer
- 一看便知linux下mysql報錯ERROR 1044: Access denied for user: '@localhost' to database 'mysql'LinuxMySqlErrorlocalhostDatabase
- 【MySQL】老版本mysql奇怪的報錯:ERROR 1046 (3D000): No database selected(BUG)MySqlError3DDatabase
- MySQL ERROR 1698 (28000) 錯誤MySqlError
- Ubuntu 系統 apt 報錯:relocation errorUbuntuAPTError
- pip install scrapy報錯:error: UnableError
- 反序列 unserialize(): Error 報錯問題Error
- 【MySQL】ERROR 1290 (HY000): --secure-file-priv--匯出報錯MySqlError
- mysql 5.6.25報錯ERROR 1372 (HY000): Password hash 的一點思考MySqlError
- MySQL 報錯 ERROR 1290 (HY000): running with the --secure-file-privMySqlError