Change sql_mode in MySQL 5.6

user-pic
Vote 0 Votes

MySQL 5.6 default sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
這是嚴格模式, 會造成舊版升上來的用戶一些困擾,
例如:
欄位 id 是 int, insert test (id) values ''; 會有錯誤, 因為空字串沒有值, 非嚴格模式會自動變成 0
(Incorrect integer value: '' for column 'id' at row 1)
一個 table 有多個欄位, 若只 insert 其中部份欄位的值, 其他欄位沒有設 default value, 會有錯誤,
非嚴格模式會自動帶入空字串或 0
(In strict mode, the statement is rejected if any of the omitted columns have no default value)

若想要拿掉 sql_mode, 在 /etc/my.cnf 加一行 sql_mode=
若無效的話表示還有其他地方有 my.cnf, 若是裝官方的 rpm, 會是在 /usr/my.cnf, comment 掉
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

改完重啟看是否拿掉了
show variables like 'sql_mode'

About this Entry

This page contains a single entry by Pank published on April 11, 2013 12:37 AM.

111.111.111.111 was the previous entry in this blog.

MySQL Illegal mix of collations for operation 'like' is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives