From : http://www.uini.net/2010/03/mysql-create-function-problem.html
http://blog.csdn.net/wuhuiran/archive/2007/12/14/1935220.aspx
今天在整理資料時,又碰到MySQL函數不能建立的問題,以前也遇到過多次,解決是解決了,但是解決辦法總是記不住,也沒有很好地寫下來,以至於每次都要再次Google,耗時耗力,這次終於受不了了,還是選擇寫出來:
出錯資訊大致類似:
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
建立不了函數,是未開啟功能:
mysql> show variables like '%func%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
1 row in set (0.00 sec)
mysql> set global log_bin_trust_function_creators=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%func%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | ON |
+---------------------------------+-------+
1 row in set (0.00 sec)
我們也可以在my.ini檔案中的mysqld中加入下面這一句
[mysqld]
log-bin=C:\Program Files\MySQL\MySQL Server 5.1\log\log-bin.log --產生記錄檔
log-bin-trust-function-creators=1 --function功能開啟