Mysql不能创建函数的处理方法,错误代码1418
一、问题描述
创建自定义函数:
DELIMITER $$
CREATE
FUNCTION `pcloud_outEmployees`.`getChild`(deptId VARCHAR(255))
RETURNS VARCHAR (255)
BEGIN
DECLARE ptemp VARCHAR (255);
SET ptemp = deptId;
RETURN ptemp;
END$$
DELIMITER ;
执行异常信息如下:
1 queries executed, 0 success, 1 errors, 0 warnings
查询:CREATE FUNCTION `pcloud_outEmployees`.`getChild`(deptId VARCHAR(255)) RETURNS VARCHAR (255) BEGIN DECLARE ptemp VARCHAR (255); S...
错误代码: 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)
执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.001 sec
二、原因及解决方案
Mysql函数不能创建,原因是未开启功能。
show variables like '%func%'
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
1 row in set (0.00 sec)
执行下面的语句,开启创建函数功能
set global log_bin_trust_function_creators=1
开启后,再次执行创建自定义函数就OK了。