MySQL Forums :: Stored Procedures :: Stored procedure doesn't work correctly


Advanced Search

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 633 Quazi Siddiqui 03/03/2017 09:22PM
Re: Stored procedure doesn't work correctly 64 Peter Brawley 03/03/2017 11:06PM
Re: Stored procedure doesn't work correctly 56 Quazi Siddiqui 03/03/2017 11:17PM
Re: Stored procedure doesn't work correctly 52 Peter Brawley 03/04/2017 12:59AM
Re: Stored procedure doesn't work correctly 58 Quazi Siddiqui 03/06/2017 10:33AM


Sorry, only registered users may post in this forum.

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.