Solution to MYSQL function creation error _ MySQL

Source: Internet
Author: User
During program development, have you ever encountered a problem where mysql functions cannot be created? I have encountered a very troublesome problem. I searched the internet for some relevant information and sorted it together, for your reference, when you use a MySQL database, you may encounter situations where MySQL functions cannot be created. The following describes how to solve the problem that MySQL functions cannot be created.

Case 1:

An error occurred while executing the mysql creation function in the project,

The error message for creating a function in mysql 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 function to be created is enabled. the SQL statement to check whether the function is enabled is as follows:

-- Check whether the show variables like '% func %' function is enabled; -- enable the function set global log_bin_trust_function_creators = 1;

After the SQL statement is executed, it is enabled. check whether your SQL statement is written incorrectly (because the SQL statement is provided by others. if there is no problem in other environments, it is possible in your own environment ).

A problem occurs because the SQL statement he created has a specified user. The following is his SQL statement:

DROP FUNCTION IF EXISTS `nextval`;DELIMITER ;;CREATE DEFINER=`devop`@`%` FUNCTION `nextval`(`seq_name` VARCHAR(50)) RETURNS varchar(20) CHARSET utf8BEGIN  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 ;

Because of the CREATE_FUNCTION specification, it can be found that the DEFINER parameter can specify the database user, but its own database is not the user, which leads to problems.

The problem has been solved.

-EOF-

Case 2:

When creating a user-defined function in MySQL, the following error is 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 a security parameter is not enabled. log_bin_trust_function_creators defaults to 0, which does not allow function synchronization. If this parameter is enabled, it can be created successfully.

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 node, remember to enable this parameter on the slave side (salve needs to stop and then start again). Otherwise, the replaction is interrupted when a function is created on the master node.

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 prompt, the cause of this error may be a security configuration. the log_bin_trust_function_creators parameter in the manual is 0 by default, and function synchronization is not allowed, generally, when configuring repliaction, we forget to pay attention to this parameter. in this way, after the master updates the funtion, slave reports an error and slave stoped.

Processing process:

Log on to the mysql database

> set global log_bin_trust_function_creators = 1;> start slave;

Tracking mysql startup logs. slave runs normally and the problem is solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.