天天看點

mysql報ascii 0_導入mysql檔案提示“ASCII '\0' appeared in the statement”

在windows伺服器上導入mysql檔案時,出現以下報錯: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: '?-'.後來百度了一下,發現這樣一個回答:The reference to--binary-mode(introduced

in MySQL 5.6.3) is probably a distraction.

It doesn't sound like you're dealing with a mysqldump output file, there. Try the file utility.

shell> file dumpfile.sql

dumpfile.sql: ASCII text

If you don't get the ASCII text response, you're dealing with either something that isn't a dump file from mysqldump at all, or you're dealing with something that's been compressed (with gzip or bzip2, for example), which you'd need to uncompress before piping

it into mysql.

大意是說,錯誤資訊裡的--binary-mode極具迷惑性。事實上,這并不意味着你的 sql檔案裡包含ASCII字元。可以先通過file指令檢視該檔案的字元類型。

于是将該sql檔案上傳至Linux伺服器上,執行了一下file:

[[email protected] ~]# file dafanshu_db.sql

dafanshu_db.sql: Little-endian UTF-16 Unicode text, with very long lines, with CRLF line terminators

結果很明顯,這裡面并沒有什麼ASCII字元,是以即使将mysql設定成--binary-mode,也無濟于事,是檔案格式的問題。

後來無意中發現,用more檢視這個檔案,無法正常顯示任何内容,用vi卻可以。這更加說明,這個sql檔案絕對不是普通的文本檔案。

最後想起,這個sql檔案是在powershell裡導出來的。于是嘗試在cmd下重新導一次,然後再導入,就正常了。這坑爹的powershell。。。