2013-05-28 15 views
4

我導入了一個MySQL數據庫。所有成功導入的表格,但不包括函數。我可以執行SQL查詢的唯一方法是通過phpMyAdmin或PHP腳本(無SSH)。在phpMyAdmin中創建函數 - 錯誤:訪問被拒絕您需要此操作的超級權限

這裏的功能的示例導入:

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的或與服務器?

+0

可能重複http://stackoverflow.com/questions/8080681/store-procedures-in-phpmyadmin ) –

+0

謝謝。在查看這篇文章之前,我沒有使用分隔符字段。我嘗試過,但我仍然有同樣的錯誤: #1227 - 訪問被拒絕;你需要這個操作的SUPER特權 – pec

回答

13

問題是我沒有超級特權,但如果我從查詢中刪除DEFINER,我不再需要這個特權。

As of MySQL 5.0.3, CREATE PROCEDURE and CREATE FUNCTION require the CREATE ROUTINE privilege. They might also require the SUPER privilege, depending on the DEFINER value, as described later in this section. If binary logging is enabled, CREATE FUNCTION might require the SUPER privilege, as described in Section 18.6, 「Binary Logging of Stored Programs」.

還必須在SQL文本框下設置分隔符字段。 phpMyAdmin Delimiter field

這裏的SQL查詢,而不DEFINER聲明:

/*!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 */;; 
的[在phpMyAdmin存儲過程(
+0

哇謝謝,這真是一個奇怪的問題-.- – Fabiotocchi

相關問題