DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration – JA Media Solutions | GIS Services, Software and Web Development

DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration

Home » Blog » DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration

Written by Aldwin Galapon posted on Sunday, November 11th, 2012

4.40 avg. rating (87% score) - 5 votes

I experienced this error while trying to alter one of my stored procedures remotely on a master server. After some research, I ended up getting information from “Binary Logging of Stored Programs“.

From MySQL Reference in verbatim:
When you create a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication.

By default, for a CREATE FUNCTION statement to be accepted, at least one of DETERMINISTIC, NO SQL, or READS SQL DATA must be specified explicitly. Otherwise an error occurs:

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)

Further reading helped me arrive to the conclusion to the cause of this error:

Cause:
The error arises if the binary logging option, which is required for the replication, is turned on for the MySQL server.

We can choose solutions listed below depending to our system requirements, for me, I opted on using the later.

  1. When creating or altering a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication.
  2. 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.

Posted on Sunday, November 11th, 2012 at 11:54 pm Print this Article Email this Article

  • Alex

    Thanks. It’s help for me :)

  • bbhaosac

    Thanks a lot ! I really helpful with me when I try import my .sql file which included functions and procedure. :)

  • thiago paulino

    Good information thank your!

  • benny

    Thanks .. Helpful. Keep sharing.