导入数据时出现问题 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)
时间: 2023-11-06 09:18:03 浏览: 46
这个问题是因为在开启了二进制日志记录(binary logging)的情况下,MySQL中的函数没有被声明为DETERMINISTIC、NO SQL或READS SQL DATA中的任何一种,导致MySQL无法安全地记录这些函数的更改。为了解决这个问题,你可以使用以下两种方法中的一种:
1. 在MySQL中设置log_bin_trust_function_creators变量:
在MySQL命令行中输入以下命令:
```
SET GLOBAL log_bin_trust_function_creators = 1;
```
这将允许具有任何声明类型的函数被记录到二进制日志中。
2. 修改函数声明:
在函数声明中添加DETERMINISTIC、NO SQL或READS SQL DATA中的任何一种。例如:
```
CREATE FUNCTION my_function(param1 INT) RETURNS INT
DETERMINISTIC
BEGIN
-- function body
END;
```
这将使函数被声明为确定性函数(deterministic function),或不涉及SQL语句(no SQL)或只涉及读取SQL数据(reads SQL data),从而使函数能够被记录到二进制日志中。
相关问题
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled
这个错误通常出现在MySQL中创建函数时,表示函数声明中没有包含DETERMINISTIC、NO SQL或READS SQL DATA中的任何一个,同时二进制日志记录也是启用的。这个错误提示建议你使用log_bin_trust_function_creators变量来解决。log_bin_trust_function_creators是一个MySQL系统变量,它控制是否允许创建具有任意定义的函数和过程。如果设置为1,则可以创建具有任意定义的函数和过程,否则将无法创建。可以通过以下命令来设置log_bin_trust_function_creators变量:
```sql
SET GLOBAL log_bin_trust_function_creators = 1;
```
需要注意的是,这个设置可能会导致安全问题,因此在生产环境中应该谨慎使用。
为什么创建自定义函数会出现: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的安全模式下,如果在创建自定义函数时没有指定是否是确定性函数(DETERMINISTIC)、是否有副作用(NO SQL)或者只读(READS SQL DATA),并且MySQL开启了二进制日志(binary logging),则会出现该警告。
这是因为在二进制日志中保存的是对数据库进行操作的二进制数据,如果自定义函数不是确定性的(即不同输入可能会得到不同的输出)或者具有副作用(可能会修改数据库数据),则二进制日志中记录的函数执行结果可能会与实际执行结果不同,从而导致数据不一致。
为了避免这种情况,MySQL提供了一个名为log_bin_trust_function_creators的变量,可以设置为1来关闭该警告。但是需要注意的是,关闭该警告可能会带来一定的安全风险,因此建议在必要时才关闭该警告。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)