"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Solve the \"1418 (HY000) This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled\" Error in MySQL?

How to Solve the \"1418 (HY000) This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled\" Error in MySQL?

Published on 2024-11-16
Browse:602

How to Solve the \

When importing a MySQL database, you may encounter the error "1418 (HY000) at line 10185: 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 error occurs when you have not specified the deterministic nature of a function within the database.

To resolve this error, you can use one of two methods:

Method 1: Temporarily Disable Binary Logging

SET GLOBAL log_bin_trust_function_creators = 1;

Method 2: Configure the mysql.ini File

log_bin_trust_function_creators = 1;

By setting this value to 1, you are relaxing the checking for non-deterministic functions. This option should be used with caution as it can potentially compromise the integrity of your data.

Understanding Deterministic Functions

To avoid this error in the future, a better approach is to use deterministic declarations for stored functions. These declarations inform MySQL whether the function always produces the same result for the same input parameters. Here are the different deterministic declarations:

DETERMINISTIC:

  • Functions that always produce the same result for the same input parameters.

NOT DETERMINISTIC:

  • Functions that do not always produce the same result for the same input parameters. If not explicitly declared, MySQL defaults to NOT DETERMINISTIC.

READS SQL DATA:

  • Functions that only read data from databases.

NO SQL:

  • Functions that do not contain any SQL statements.

CONTAINS SQL:

  • Functions that contain SQL instructions but neither read nor write data.

Choosing the Correct Declaration

Selecting the correct declaration for a function depends on its behavior. If the function's output depends on factors external to the database, such as the current time or a random number generator, it should be declared as NOT DETERMINISTIC. If the function only reads data, it can be declared as READS SQL DATA. If the function does not contain any SQL statements, it can be declared as NO SQL.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3