I have the MySQL version of this question for SQL-Server
I'm running mysql Ver 14.14 Distrib 5.5.49, for debian-linux-gnu (x86_64) using readline 6.3
I have created a user with only this permission:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'p@55w0rd';
GRANT EXECUTE ON dbname.* TO 'username'@'localhost';
I have created this procedure on dbname
:
DELIMITER $$
CREATE PROCEDURE seed_database()
this_procedure:BEGIN
INSERT INTO `dbtable` VALUES (1,'data');
END $$
DELIMITER ;
But when I login with that user and try to CALL seed_database();
, I get:
ERROR 1142 (42000) at line 1: INSERT command denied to user 'username'@'localhost' for table 'dbtable'
I'm trying to follow the principle of least privilege by only allowing a user to execute stored procedures. I don't want to give a user privilege to directly INSERT on a table with the obvious GRANT INSERT ON dbname.dbtable TO 'username'@'localhost';
, in case the credentials are compromised and because I have some complex logic inside the stored procedure that produces inputs to be stored (represented by hard-coded data in the example (1,'data')
) that I don't want the user generating and inserting directly. But I would like for them to use the stored procedure to accomplish the same objective.