前幾天幫同事解決一個(gè)案例,在主從復(fù)制環(huán)境下,從庫(kù)上的MySQL版本號(hào)是5.5.5,遇到下面的錯(cuò)誤:
#其他非相關(guān)信息我都隱藏掉了
[(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'
第一感覺(jué)是遇到保留關(guān)鍵字了,不過(guò)看到這么長(zhǎng)的字符串,不應(yīng)該是保留關(guān)鍵字才對(duì)。
經(jīng)過(guò)嘗試,最后發(fā)現(xiàn)是字符串中的 “e” 這個(gè)字符如果存在就可能會(huì)報(bào)錯(cuò),看起來(lái)應(yīng)該是bug才對(duì)了。
在MySQL的bug系統(tǒng)里確實(shí)找到了這個(gè)bug,不過(guò)看bug描述,在5.5版本中應(yīng)該是已經(jīng)修復(fù)了才對(duì),看來(lái)太不靠譜了呀~~
關(guān)于這個(gè)bug:Savepoint identifier is occasionally considered as floating point numbers
其實(shí)除了升級(jí)版本外,解決方法也很簡(jiǎn)單,把savepoint后面的 identifier 字符串用反引號(hào)(波浪號(hào)的下檔鍵,英文叫做 backticks 鍵)引用起來(lái)就行。
例如:
savepoint `6e86db84_14847168f19__8000`;
這樣就可以了。
這個(gè)案例也提示我們,在寫(xiě)SQL時(shí),涉及到數(shù)據(jù)庫(kù)、表、字段、identifier 等名稱時(shí),最好是都能用反引號(hào)引用,確保可用。
曾經(jīng)看到線上數(shù)據(jù)表有個(gè)字段名是 check ,這個(gè)名字在MySQL里很早就已經(jīng)是保留關(guān)鍵字,幸好開(kāi)發(fā)同學(xué)比較靠譜,都加上了反引號(hào)。
關(guān)于savepoint的2個(gè)bug:
Savepoint Identifier should be enclosed with backticks
Savepoint identifier is occasionally considered as floating point numbers
更多建議: