设为首页 收藏本站
查看: 506|回复: 0

[经验分享] mysql自定义函数与log_bin_trust_function_creators参数

[复制链接]

尚未签到

发表于 2016-10-23 02:17:33 | 显示全部楼层 |阅读模式
mysql自定义函数与log_bin_trust_function_creators参数
2011年12月29日
   问题1:
  root@hupan 10:54:58>CREATE FUNCTION getDistance(x1 double,y1 double,x2 double,y2 double)
  -> RETURNS double
  -> BEGIN
  -> declare Flattening,er,pix,z1,z2,d1,b1,b2,l1,l2,theta,dista nce double;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
  root@hupan 10:54:58>set Flattening=298.257223563002;
  ERROR 1193 (HY000): Unknown system variable 'Flattening'
  root@hupan 10:54:58>set er=6378.137;
  ERROR 1193 (HY000): Unknown system variable 'er'
  root@hupan 10:54:58>set pix=3.1415926535;
  ERROR 1193 (HY000): Unknown system variable 'pix'
  root@hupan 10:54:58>set b1 = (0.5-x1/180)*pix;
  ERROR 1193 (HY000): Unknown system variable 'b1'
  root@hupan 10:54:58>set l1 = (y1/180)*pix;
  ERROR 1193 (HY000): Unknown system variable 'l1'
  root@hupan 10:54:58>set b2 = (0.5-x2/180)*pix;
  ERROR 1193 (HY000): Unknown system variable 'b2'
  root@hupan 10:54:58>set l2 = (y2/180)*pix;
  ERROR 1193 (HY000): Unknown system variable 'l2'
  root@hupan 10:54:58>set x1 = er*COS(l1)*SIN(b1);
  ERROR 1193 (HY000): Unknown system variable 'x1'
  root@hupan 10:54:58>set y1 = er*SIN(l1)*SIN(b1);
  ERROR 1193 (HY000): Unknown system variable 'y1'
  root@hupan 10:54:58>set z1 = er*COS(b1);
  ERROR 1193 (HY000): Unknown system variable 'z1'
  root@hupan 10:54:58>set x2 = er*COS(l2)*SIN(b2);
  ERROR 1193 (HY000): Unknown system variable 'x2'
  root@hupan 10:54:58>set y2 = er*SIN(l2)*SIN(b2);
  ERROR 1193 (HY000): Unknown system variable 'y2'
  root@hupan 10:54:58>set z2 = er*COS(b2);
  ERROR 1193 (HY000): Unknown system variable 'z2'
  root@hupan 10:54:58>set d1 = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z 2));
  ERROR 1193 (HY000): Unknown system variable 'd1'
  root@hupan 10:54:58>set theta= acos((er*er+er*er-d1*d1)/(2*er*er));
  ERROR 1193 (HY000): Unknown system variable 'theta'
  root@hupan 10:54:58>set distance= theta*er;
  ERROR 1193 (HY000): Unknown system variable 'distance'
  root@hupan 10:54:58>RETURN distance;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RETURN distance' at line 1
  root@hupan 10:54:58>END;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
  root@hupan 10:54:58>delemiter ;;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delemiter' at line 1
  ERROR:
  No query specified
  root@hupan 10:54:58>delemiter ;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delemiter' at line 1
  //
  root@hupan 05:20:05>show variables like '%commit%';
  +--------------------------------+-------+
  | Variable_name                  | Value |
  +--------------------------------+-------+
  | autocommit                     | ON    |
  | innodb_commit_concurrency      | 0     |
  | innodb_flush_log_at_trx_commit | 2     |
  +--------------------------------+-------+
  3 rows in set (0.00 sec)
  自动提交时不是将函数作为一个整体声明所以报错--------解决:用delimiter 修改结束符定义,将函数作为整体进行说明
  问题2:
  root@hupan 10:55:51>delimiter ;;
  root@hupan 10:55:53>CREATE FUNCTION getDistance(x1 double,y1 double,x2 double,y2 double)
  -> RETURNS double
  -> BEGIN
  -> declare Flattening,er,pix,z1,z2,d1,b1,b2,l1,l2,theta,dista nce double;
  -> set Flattening=298.257223563002;
  -> set er=6378.137;
  -> set pix=3.1415926535;
  -> set b1 = (0.5-x1/180)*pix;
  -> set l1 = (y1/180)*pix;
  -> set b2 = (0.5-x2/180)*pix;
  -> set l2 = (y2/180)*pix;
  -> set x1 = er*COS(l1)*SIN(b1);
  -> set y1 = er*SIN(l1)*SIN(b1);
  -> set z1 = er*COS(b1);
  -> set x2 = er*COS(l2)*SIN(b2);
  -> set y2 = er*SIN(l2)*SIN(b2);
  -> set z2 = er*COS(b2);
  -> set d1 = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z 2));
  -> set theta= acos((er*er+er*er-d1*d1)/(2*er*er));
  -> set distance= theta*er;
  -> RETURN distance;
  -> END;
  -> delimiter ;;
  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)
  root@hupan 10:55:53>delimiter ;
  //
  root@hupan 10:55:58>show variables like 'log_bin_trust_function_creators';
  +---------------------------------+-------+
  | Variable_name                   | Value |
  +---------------------------------+-------+
  | log_bin_trust_function_creators | OFF   |
  +---------------------------------+-------+
  1 row in set (0.00 sec)
  log_bin_trust_function_creators
  Command-Line Format    --log-bin-trust-function-creators        
  Option-File Format    log-bin-trust-function-creators        
  Option Sets Variable    Yes, log_bin_trust_function_creators         
  Variable Name    log_bin_trust_function_creators        
  Variable Scope    Global        
  Dynamic Variable    Yes        
  Permitted Values         
  Type    boolean        
  Default    FALSE     
  This variable applies when binary logging is enabled. It controls whether stored function creators can be trusted not to create stored functions that will cause unsafe events to be written to the binary log. If set to 0 (the default), users are not permitted to create or alter stored functions unless they have the SUPER privilege in addition to the CREATE ROUTINE or ALTER ROUTINE privilege. A setting of 0 also enforces the restriction that a function must be declared with the DETERMINISTIC characteristic, or with the READS SQL DATA or NO SQL characteristic. If the variable is set to 1, MySQL does not enforce these restrictions on stored function creation. This variable also applies to trigger creation. See Section 18.7, “Binary Logging of Stored Programs”.
  主要是考虑binlog安全,如果没开binlog的话这个值是无意义的;打开binlog后需要超级权限才能定义,并且在sql上也有需求
  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)
  这个报错目前知道可以通过两个方式解决:
  RETURNS    double  【READS SQL DATA/DETERMINISTIC】
  即在自定义函数后增加一个只读数据或者指定字符的信息
  参数参考手册:
  http://dev.mysql.com/doc/refman/5.1/en/server-syst em-variables.html#sysvar_log_bin_trust_function_cre ators

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-289846-1-1.html 上篇帖子: 导入MySQL数据库模式及数据的Bash脚本 (导出的姊妹篇) 下篇帖子: CakePHP: tips on ssl, mysql load balance, master/slave, xhprof benchmark tool
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表