前幾天幫同事解決一個案例,在主從復制環境下,從庫上的MySQL版本號是5.5.5,遇到下面的錯誤:
~~~
#其他非相關信息我都隱藏掉了
[(yejr@imysql.com)]> show slave status \G;
Slave_IO_Running: Yes
Slave_SQL_Running: No
Last_Errno: 1064
Last_Error: Error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '6e86db84_14847168f19__8000' at line 1' on query. Default database: 'act'. Query: 'SAVEPOINT 6e86db84_14847168f19__8000'
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1064
Last_SQL_Error: Error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '6e86db84_14847168f19__8000' at line 1' on query. Default database: 'act_log'. Query: 'SAVEPOINT 6e86db84_14847168f19__8000'
~~~
第一感覺是遇到保留關鍵字了,不過看到這么長的字符串,不應該是保留關鍵字才對。
經過嘗試,最后發現是字符串中的 “e” 這個字符如果存在就可能會報錯,看起來應該是bug才對了。
在MySQL的bug系統里確實找到了這個bug,不過看bug描述,在5.5版本中應該是已經修復了才對,看來太不靠譜了呀~~
關于這個bug:[Savepoint identifier is occasionally considered as floating point numbers](http://bugs.mysql.com/bug.php?id=55962 "Savepoint identifier is occasionally considered as floating point numbers")
其實除了升級版本外,解決方法也很簡單,把savepoint后面的 identifier 字符串用反引號(波浪號的下檔鍵,英文叫做 backticks 鍵)引用起來就行。
例如:
~~~
savepoint `6e86db84_14847168f19__8000`;
~~~
這樣就可以了。
這個案例也提示我們,在寫SQL時,涉及到數據庫、表、字段、identifier 等名稱時,最好是都能用反引號引用,確保可用。
曾經看到線上數據表有個字段名是?check?,這個名字在MySQL里很早就已經是保留關鍵字,幸好開發同學比較靠譜,都加上了反引號。
關于savepoint的2個bug:
[Savepoint Identifier should be enclosed with backticks](http://bugs.mysql.com/bug.php?id=55961 "Savepoint Identifier should be enclosed with backticks")
[Savepoint identifier is occasionally considered as floating point numbers](http://bugs.mysql.com/bug.php?id=55962 "Savepoint identifier is occasionally considered as floating point numbers")
- 前言
- 為什么InnoDB表要建議用自增列做主鍵
- 線上環境到底要不要開啟query cache
- MySQL復制中slave延遲監控
- 如何安全地關閉MySQL實例
- 如何查看當前最新事務ID
- 從MyISAM轉到InnoDB需要注意什么
- 5.6版本GTID復制異常處理一例
- 不同的binlog_format會導致哪些SQL不會被記錄
- Spring框架中調用存儲過程失敗
- 如何將兩個表名對調
- mysqldump加-w參數備份
- 使用mysqldump備份時為什么要加上 -q 參數
- 修改my.cnf配置不生效
- 什么情況下會用到臨時表
- profiling中要關注哪些信息
- EXPLAIN結果中哪些信息要引起關注
- processlist中哪些狀態要引起關注
- MySQL無法啟動例一
- pt-table-checksum工具使用報錯一例
- 為什么要關閉query cache,如何關閉
- MySQL聯合索引是否支持不同排序規則
- SAVEPOINT語法錯誤一例
- 你所不知的table is full那些事
- 大數據量時如何部署MySQL Replication從庫
- 內存溢出案例