zoukankan      html  css  js  c++  java
  • MySql 创建函数 Error Code : 1418

    查看日志信息:show variables like 'log_%';显示'log_bin'、'log_bin_trust_function_creators'等状态

    解决方法:

    1. 关闭binary logging
    2. 在创建函数 begin 之前加上 DETERMINISTIC READS SQL DATA
    3. SET GLOBAL log_bin_trust_function_creators = 1;

    参考  http://dev.mysql.com/doc/refman/5.0/en/stored-programs-logging.html

    • 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 DETERMINISTICNO 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)

      This function is deterministic (and does not modify data), so it is safe:

      CREATE FUNCTION f1(i INT)
      RETURNS INT
      DETERMINISTIC
      READS SQL DATA
      BEGIN
        RETURN i;
      END;

      This function uses UUID(), which is not deterministic, so the function also is not deterministic and is not safe:

      CREATE FUNCTION f2()
      RETURNS CHAR(36) CHARACTER SET utf8
      BEGIN
        RETURN UUID();
      END;

      This function modifies data, so it may not be safe:

      CREATE FUNCTION f3(p_id INT)
      RETURNS INT
      BEGIN
        UPDATE t SET modtime = NOW() WHERE id = p_id;
        RETURN ROW_COUNT();
      END;

      Assessment of the nature of a function is based on the honesty of the creator: MySQL does not check that a function declared DETERMINISTIC is free of statements that produce nondeterministic results.

    • 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_creatorssystem 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.

      If binary logging is not enabled, log_bin_trust_function_creators does not apply. SUPER is not required for function creation unless, as described previously, the DEFINER value in the function definition requires it.

    • For information about built-in functions that may be unsafe for replication (and thus cause stored functions that use them to be unsafe as well), see Section 16.4.1, “Replication Features and Issues”.

    ^_^ 天行健,君子以自强不息;地势坤,君子以厚德载物
  • 相关阅读:
    map/reduce/filter/lambda
    DHCP Option43配置
    函数的参数
    通用路由封装协议——GRE
    spring 中使用quartz实现定时任务
    自己实现的简单的grid
    Java 中 Double 相关问题
    爬坑纪——RESTful WCF
    Hi,UEditor——百度编辑器配置若干
    去除ColumnChart自带的阴影效果
  • 原文地址:https://www.cnblogs.com/w-y-f/p/3210925.html
Copyright © 2011-2022 走看看