How to grant execute on specific stored procedure to user

TriGerZ picture TriGerZ · Jun 30, 2014 · Viewed 19.7k times · Source

I have created some stored procedure on a specific schema.

In this stored procedure, I want to grant execute privilege.

So I wrote that :

GRANT EXECUTE ON PROCEDURE schema_name.proc_name TO 'user_name';
GRANT SELECT ON mysql.proc to 'user_name';

The problem is : My user can see every stored procedure. I wish he could only see the procedure where he has the EXECUTE privilege.

Is there a way to achieve that ?

Thanks in advance.

Answer

Michael - sqlbot picture Michael - sqlbot · Jul 1, 2014

Yes... this works as expected if you don't grant the user the SELECT privilege on the mysql.proc table, either directly or indirectly, such as with GRANT SELECT ON *.* TO ...

Without SELECT permission on this table, a user can only see the existence of stored procedures and stored functions where they have other permissions, like EXECUTE.

Under the hood, the lack of SELECT on mysql.proc also prevents the user from seeing the procedures they don't have access to via the information_schema.routines pseudo-table.

You shouldn't need to GRANT SELECT ON mysql.proc to enable the user to execute procedures or functions... and if you do, then that seems like the question.