Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the stored procedure definer

I have a around one hundred stored routines in my MySQL database with with most of them have 'root' as the definer.

I have another mysql account named 'abc', how to change the definer of all routines to 'abc'.

Is it possible to do the same if I have access to MySQL server only as 'abc' user and not as 'root'

like image 380
Mithun Sreedharan Avatar asked Jul 08 '10 18:07

Mithun Sreedharan


People also ask

How do I change the definer of a procedure?

How to change the definer of a Stored Procedure? The definer of a Stored Procedure cannot be directly altered. To change it, you will need to recreate the procedure with the desired definer.

What is definer in stored procedure?

In this stored procedure, the definer is root@localhost that is the superuser which has all privileges. The SQL Security is set to the definer. It means that any user account which calls this stored procedure will execute with all privileges of the definer i.e., root@localhost user account.

How do I change the definer of a trigger in MySQL?

Show activity on this post. 2) Open triggers. sql file in your favorite editor and use Find and Replace feature to change DEFINER s. Save updated file.

How do I find MySQL definer?

To identify which DEFINER values exist in each table, use these queries: SELECT DISTINCT DEFINER FROM INFORMATION_SCHEMA. EVENTS; SELECT DISTINCT DEFINER FROM INFORMATION_SCHEMA. ROUTINES; SELECT DISTINCT DEFINER FROM INFORMATION_SCHEMA.


1 Answers

To see the definers:

show procedure status; 

You can change them like this:

UPDATE `mysql`.`proc` p SET definer = 'YournewDefiner' WHERE definer='OldDefinerShownBefore' 

For example:

 UPDATE `mysql`.`proc` p SET definer = 'user@%' WHERE definer='root@%' 

Be careful, because this will change all the definers for all databases.

like image 106
gibzaki Avatar answered Sep 17 '22 22:09

gibzaki