So I've decided to take a step back, and scrutinize the way I implement procedures on my databases.
I'll list what I have done, give my reason for doing so and hopefully I will be told that I'm a moron, and should be doing it a better way
All my procedures are stored in an SQL file, in the the following way:
SELECT 'Creating guestuser user' AS ' '; DROP USER 'guestuser'@'appserver'; CREATE USER 'guestuser'@'appserver' IDENTIFIED BY 'Password'; SELECT 'Dropping mydatabase guest procedures' AS ' '; DROP PROCEDURE IF EXISTS myProcOne; DROP PROCEDURE IF EXISTS myProcTwo; SELECT 'Creating mydatabase procedures' AS ' '; DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `myProcOne`(_id BIGINT) DETERMINISTIC COMMENT 'selects name from fluffy cats table given id' BEGIN SELECT id FROM FLUFFYCATS WHERE id=_id; END $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `myProcTwo`(_name varchar(100)) COMMENT 'inserts a new name into fluffy cats' BEGIN INSERT INTO FLUFFYCATS (name) VALUES (_name); END $$ DELIMITER ; SELECT 'Creating mydatabase guest permissions' AS ' '; GRANT EXECUTE ON PROCEDURE db_mydatabase.myProcOne TO 'guestuser'@'appserver'; GRANT EXECUTE ON PROCEDURE db_mydatabase.myProcTwo TO 'guestuser'@'appserver';
I'll start from the top. I drop and create the user, so that it looses all it's procedure permissions. As you can see, I don't give the use any permissions until the end of the file. The reason I have chosen to do this, is so that the permissions are as restrictive as possible (And therefore more secure?) ...
Then I drop the procedures (If they exist) so that they will be created with any edits I have made
Then onto the actual creation of the procedures ... I don't think I've done anything out of the ordinary here, but always open for suggestions.
Then the script finishes with giving the user the permissions for each procedure.
Of course this is just an example file, but my real one has just reached the 100th procedure --Brings out cake-- ... And would be grateful for any suggestions as to how I could maybe reduce the workload when creating a procedure (Drop,Create,Permission) ...