我导入了一个MySQL数据库.所有成功导入的表但不是函数.我可以执行SQL查询的唯一方法是通过phpMyAdmin或PHP脚本(没有SSH).
以下是要导入的函数的示例:
DELIMITER ;; /*!50003 DROP FUNCTION IF EXISTS `f_calc_gst` */;; /*!50003 SET SESSION SQL_MODE=""*/;; /*!50003 CREATE*/ /*!50020 DEFINER=`journal`@`%`*/ /*!50003 FUNCTION `f_calc_gst`(p_ht decimal(15,3), p_province varchar(2)) RETURNS varchar(255) CHARSET utf8 begin declare res varchar(255); declare v_gst decimal(15,3); declare v_gst_formula varchar(255); select GST, GST_formula into v_gst, v_gst_formula from taxes_periods where NOW() between dt_debut and dt_fin and id_province = p_province; set v_gst_formula = replace(v_gst_formula, 'HT$', p_ht); set v_gst_formula = replace(v_gst_formula, 'GST%', v_gst); set res = concat('select round(', v_gst_formula, ',2) "gst"'); return res; end */;;
如果我在phpMyAdmin中粘贴此代码,我会收到此错误:#1227 - 拒绝访问; 您需要此操作的SUPER权限
我尝试删除"/ !50003"和" /"以取消注释SQL但我收到相同的错误消息.
我也试过不使用任何分隔符并删除"DELIMITER ;;" 并得到此错误:
DROP FUNCTION IF EXISTS f_calc_gst SET SESSION SQL_MODE = "" CREATE DEFINER = `journal`@`%` FUNCTION `f_calc_gst` ( p_ht DECIMAL( 15, 3 ) , p_province VARCHAR( 2 ) ) RETURNS VARCHAR( 255 ) CHARSET utf8 BEGIN declare res VARCHAR( 255 ) ; #1064 - 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 'SET SESSION SQL_MODE="" CREATE DEFINER=`journal`@`%` FUNCTION `f_calc_gst`(p_ht ' at line 2
还尝试过:
CREATE DEFINER=`journal`@`%` FUNCTION `f_calc_gst`(p_ht decimal(15,3), p_province varchar(2)) RETURNS varchar(255) CHARSET utf8 begin declare res varchar(255); declare v_gst decimal(15,3); declare v_gst_formula varchar(255); select GST, GST_formula into v_gst, v_gst_formula from taxes_periods where NOW() between dt_debut and dt_fin and id_province = p_province; set v_gst_formula = replace(v_gst_formula, 'HT$', p_ht); set v_gst_formula = replace(v_gst_formula, 'GST%', v_gst); set res = concat('select round(', v_gst_formula, ',2) "gst"'); return res; end//
导致 :
#1064 - 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 3
是SQL,phpMyAdmin还是与服务器有问题?
问题是我没有超级特权,但如果我从查询中删除DEFINER,我就不再需要这个特权了.
从MySQL 5.0.3开始,CREATE PROCEDURE和CREATE FUNCTION需要CREATE ROUTINE权限.它们可能还需要SUPER权限,具体取决于DEFINER值,如本节后面所述.如果启用了二进制日志记录,则CREATE FUNCTION可能需要SUPER权限,如第18.6节"存储程序的二进制日志记录"中所述.
还必须在SQL文本框下设置分隔符字段.
这是没有DEFINER语句的SQL Query:
/*!50003 DROP FUNCTION IF EXISTS `f_calc_gst` */;; /*!50003 SET SESSION SQL_MODE=""*/;; /*!50003 CREATE*/ /*!50003 FUNCTION `f_calc_gst`(p_ht decimal(15,3), p_province varchar(2)) RETURNS varchar(255) CHARSET utf8 begin declare res varchar(255); declare v_gst decimal(15,3); declare v_gst_formula varchar(255); select GST, GST_formula into v_gst, v_gst_formula from taxes_periods where NOW() between dt_debut and dt_fin and id_province = p_province; set v_gst_formula = replace(v_gst_formula, 'HT$', p_ht); set v_gst_formula = replace(v_gst_formula, 'GST%', v_gst); set res = concat('select round(', v_gst_formula, ',2) "gst"'); return res; end */;;