MYSQL 创建函数出错的解决方案_MySQL
在使用MySQL数据库时,有时会遇到MySQL函数不能创建的情况。下面就教您一个解决MySQL函数不能创建问题的方法,供您借鉴参考。
案例一:
目前在项目中,执行创建mysql的函数出错,
mysql 创建函数出错信息如下:
Error Code: 1227. Access denied; you need (at least one of) the SUPER privilege(s) for this operation
首先检查创建函数的功能是否开启,检查是否开启创建功能的SQL如下:
-- 查看是否开启创建函数的功能 show variables like '%func%'; -- 开启创建函数的功能 set global log_bin_trust_function_creators = 1;
执行完SQL之后发现已经开启了,随检查自己的SQL是否写错(因为SQL是别人给的,在别人环境没问题,在自己的环境就有可能)。
突然发现了确实是SQL出现问题,由于他创建的SQL有指定用户,所以导致出现问题,以下是他的SQL:
DROP FUNCTION IF EXISTS `nextval`; DELIMITER ;; CREATE DEFINER=`devop`@`%` FUNCTION `nextval`(`seq_name` VARCHAR(50)) RETURNS varchar(20) CHARSET utf8 BEGIN DECLARE seq_max BIGINT(20); UPDATE sequenceconftable SET `max` = `max` + NEXT WHERE NAME = seq_name; SELECT `max` INTO seq_max FROM sequenceconftable WHERE NAME = seq_name ; RETURN seq_max; END ;; DELIMITER ;
由于CREATE_FUNCTION规范,可以发现就是DEFINER这个参数是可以指定数据库用户的,但是自己的库却不是这个用户,所以导致问题。
目前问题已经解决。
-EOF-
案例二:
在MySQL创建用户自定义函数时,报以下错误:
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)
这是因为有一个安全参数没有开启,log_bin_trust_function_creators 默认为0,是不允许function的同步的,开启这个参数,就可以创建成功了。
mysql> show variables like '%fun%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin_trust_function_creators | ON | +---------------------------------+-------+ 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 '%fun%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin_trust_function_creators | ON | +---------------------------------+-------+ 1 row in set (0.00 sec)
如果是在有master上开启了该参数,记得在slave端也要开启这个参数(salve需要stop后再重新start),否则在master上创建函数会导致replaction中断。
案例三:
Error Code : 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 ms taken)
分析:
根据系统提示,导致该错误的原因可能是一个安全设置方面的配置,查手册log_bin_trust_function_creators参数缺省0,是不允许function的同步的,一般我们在配置repliaction的时候,都忘记关注这个参数,这样在master更新funtion后,slave就会报告错误,然后slave stoped。
处理过程:
登陆mysql数据库
> set global log_bin_trust_function_creators = 1; > start slave;
跟踪mysql的启动日志,slave正常运行,问题解决。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]
