search
HomeDatabaseMysql TutorialHow to solve the error in MYSQL creation function

When using the MySQL database, sometimes the MySQL function cannot be created. The following will teach you a method to solve the problem of MySQL function cannot be created for your reference. Hope it helps everyone.

Case 1:

Currently in the project, an error occurs when executing the function that creates mysql.

The error message for the mysql creation function is as follows:

Error Code: 1227 . Access denied; you need (at least one of) the SUPER privilege(s) for this operation

First check whether the creation function is enabled. The SQL to check whether the creation function is enabled is as follows:

-- 查看是否开启创建函数的功能
show variables like '%func%';
-- 开启创建函数的功能
set global log_bin_trust_function_creators = 1;

After executing the SQL, you find that it has been enabled. Check whether your SQL is written incorrectly (because the SQL was given by others, it will be fine in other people's environments, but it may be possible in your own environment).

Suddenly discovered that there was indeed a problem with SQL. Because the SQL he created had a designated user, the problem occurred. The following is his 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 ;

Due to the CREATE_FUNCTION specification, it can be found that it is DEFINER This parameter can specify the database user, but your own library is not this user, so it causes problems.

The problem has been solved.

-EOF-

Case 2:

When creating a user-defined function in MySQL, the following error was reported:

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)

This is because there is a security The parameter is not turned on. The default value of log_bin_trust_function_creators is 0, which does not allow function synchronization. If this parameter is turned on, the creation will be successful.

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)

If this parameter is enabled on the master, remember to enable this parameter on the slave side as well (the slave needs to be stopped and then restarted), otherwise creating a function on the master will cause the replication to be interrupted.

Case 3:

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)

Analysis:

According to the system prompts, the cause of this error may be a security For settings configuration, check the manual. The log_bin_trust_function_creators parameter defaults to 0, which does not allow synchronization of functions. Generally, when we configure the replica, we forget to pay attention to this parameter. In this way, after the master updates the function, the slave will report an error, and then the slave stopped.

Processing process:

Log in to the mysql database

> set global log_bin_trust_function_creators = 1;
> start slave;

Trace the startup log of mysql, the slave runs normally, and the problem is solved.

Related recommendations:

Solution to 1418 error in mysql creation function

##Mysql-php database connection error, what is the reason

Mysql startup error after data migration

The above is the detailed content of How to solve the error in MYSQL creation function. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment