Stored procedure doesn't work correctly
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