MySQL创建Function时报的1418错误代号解决办法

本文介绍了解决MySQL中出现的1418错误的方法。该错误通常发生在启用了二进制日志记录并尝试创建未声明为确定性、不包含SQL或只读取SQL数据的函数时。文章提供了通过设置log_bin_trust_function_creators变量来禁用此限制的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下是引用片段:
ErrorCode:1418
ThisfunctionhasnoneofDETERMINISTIC,NOSQL,orREADSSQLDATAinitsdeclarationandbinaryloggingisenabled(you*might*wanttousethelesssafelog_bin_trust_function_creatorsvariable)

(0mstaken)


解决方法如下:

  1. mysql> SET GLOBAL log_bin_trust_function_creators = 1;

  2. 系统启动时 --log-bin-trust-function-creators=1

  3. 在my.ini(linux下为my.conf)文件中 [mysqld] 标记后加一行内容为 log-bin-trust-function-creators

如果在create function的时候有 1418的错语的时候:那么只需要执行set global log_bin_trust_routine_creators=1;

然后怎么create function 都不会有问题(当然,你的function必段正确哦),这是mysql的一个bug,搞不懂为什么,反正这样做就OK了.

另外,也可以直接在配置文件my.cnf中添加如下行[mysqld] log_bin_trust_routine_creators=1;

这个命令可以在sql editor的环境中运行,并不需要重新启动服务哦。

MySQL自5.0之後終於支援SP( Store Procedures ),
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) Assessment of the nature of a function is based on the “honesty” of the creator: MySQL does not check that a function declared DETERMINISTIC is free of statements that produce non-deterministic results.

To relax the preceding conditions on function creation (that you must have the SUPER privilege and that a function must be declared deterministic or to not modify data), set the global log_bin_trust_function_creators system variable to 1. By default, this variable has a value of 0, but you can change it like this:

mysql> SET GLOBAL log_bin_trust_function_creators = 1;
You can also set this variable by using the --log-bin-trust-function-creators=1 option when starting the server.
1. mysql> SET GLOBAL log_bin_trust_function_creators = 1;
2. 系統啟動時,加上--log-bin-trust-function-creators 參數為1
3. 直接在my.ini的[mysqld]區段加上log-bin-trust-function-creators=1
當然我想大多數人會用第三種方法,
ok...繼續我的SP學習,good luck..

二、mysql ERROR 1418 (HY000)

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)

应该是我们开启了bin-log, 我们就必须指定我们的函数是否是
1 DETERMINISTIC 不确定的
2 NO SQL 没有SQl语句,当然也不会修改数据
3 READS SQL DATA 只是读取数据,当然也不会修改数据
4 MODIFIES SQL DATA 要修改数据
5 CONTAINS SQL 包含了SQL语句


其中在function里面,只有   DETERMINISTIC, NO SQL 和   READS SQL DATA 被支持。如果我们开启了 bin-log, 我们就必须为我们的function指定一个参数。

我们可以通过设置如下的参数来关掉这个。

SET GLOBAL log_bin_trust_function_creators = 1;

(you *might* want to use the less safe log_bin_trust_function_creators
variable)


### 解决调用未定义过程或函数的问题 #### PHP 中调用未定义函数的情况及其解决方法 当在PHP脚本中尝试调用一个尚未被定义的函数时,会触发致命错误。例如,在给定的例子中有如下代码片段: ```php <?php // 尝试调用了名为undefinedFunction的未定义函数 undefinedFunction(); ?> ``` 上述情况会导致执行中断并抛出异常信息指出`undefinedFunction()`并未事先声明[^1]。 为了防止此类问题的发生,应当确保所有要使用的自定义功能都已提前正确定义好。如果确实存在外部依赖,则需确认对应的库文件已经被正确引入到当前环境中。 对于像`mysql_connect()`这样的内置API接口过期而引发找不到对应实现的情形,建议升级至PDO或者mysqli扩展来替代旧版MySQL API,并相应调整连接数据库的方式[^4]。 #### JavaScript 中父级作用域访问子级成员失败的原因分析与对策 JavaScript里若出现上级试图获取下层定义的方法时报错“function is not defined”,往往是因为加载时机不对或者是闭包机制引起的可见性障碍所致[^2]。 一种常见修复手段是通过事件委托模式或是DOMContentLoaded监听器等方式延迟初始化操作直到整个页面文档结构完全构建完毕之后再进行处理;另一种则是利用IIFE立即执行表达式创建局部封闭空间从而规避命名冲突风险的同时也保障了内部逻辑对外部环境变化具备更高的容忍度。 #### Excel VBA 使用 Xlwings 执行宏命令注意事项 借助于Python第三方库Xlwings可以在VBA项目里面动态调用由插件提供的公共例行程序而不局限于单一的工作表对象内[^3]。不过需要注意的是,目标Sub/Function的名字格式应该严格遵循官方文档所规定的语法标准以免造成解析歧义进而影响正常运作流程。 综上所述,针对不同编程语言环境下发生的“调用未定义的过程或函数”的状况,采取针对性措施可以有效降低这类编译时期报错的概率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值