MySQL Forums
Forum List  »  Stored Procedures

Stored procedure doesn't work correctly
Posted by: Quazi Siddiqui
Date: March 03, 2017 09:22PM

Hello,

I'm trying put the below 2 grants statements into a procedure in MySQL 5.7.

GRANT USAGE ON *.* TO 'ABC123'@'%';
GRANT SELECT ON `%`.* TO 'ABC123'@'%';

I'm using phpMyAdmin to write the procedure but somehow the below procedure runs but doesn't give the grants. I'm suspecting may be I'm not putting the sysntax correctly in the CONCAT statements. Also, when I save the procedure, I see the '\'' is getting converted to '''.

Would appreciate if you correct this procedure or advise a better approach to run grants. Also, I'm not finding ROLES feature is available in MySQL 5.7.



CREATE PROCEDURE LK_USER_Proc(IN eid VARCHAR(6))
BEGIN


SELECT eid;

set @eid = CONCAT_WS('','\'',eid,'\'','@','\'','%','\'');

set @st1 = CONCAT_WS('', 'GRANT USAGE ON *.* TO', ' ', @eid) ;

set @st2 = CONCAT_WS('', 'GRANT SELECT ON', ' ','\'',`%`,'\'','.*', ' ', 'TO', ' ', @eid) ;


SELECT @eid;
SELECT @st1;
SELECT @st2;



PREPARE stmt from @st1 ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;

PREPARE stmt from @st2 ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;

END

Options: ReplyQuote


Subject
Views
Written By
Posted
Stored procedure doesn't work correctly
1740
March 03, 2017 09:22PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.