今天在给MySQL创建一个函数的时候遇到了这样一个错误:
1418 - 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)
起初我以为是我写的函数中有什么语法不对,找了半天愣是没找出哪里不对,mmp。然后将这个错误放到网上去查了下,才知道当MySQL开启了二进制日志以后,为了安全性,默认会禁止用户创建或修改函数和存储过程。
详细解释可以看下这个:https://blog.csdn.net/SELECT_BIN/article/details/87604862
解决办法如下:
先看下 log_bin_trust_function_creators
的设置
mysql> show variables like 'log_bin_trust_function_creators';
结果是OFF,我们需要将其设置为ON
SET GLOBAL log_bin_trust_function_creators = 1;
这样添加了参数以后,如果MySQL重启,原先的设置又会失效,因此可以在my.cnf配置文件添加:
log_bin_trust_function_creators = 1;