Possible to have multiple users as DEFINER for MySQL Stored Procedure?

荒凉一梦 提交于 2019-12-06 15:42:07

DEFINER always refers to the user who created the stored procedure. This can only be 1 user.

If Mary wants to see Bobs procedure, she could call:

SHOW CREATE PROCEDURE proc_name

To see the code of the procedure. She could also call the following to see the code:

SELECT ROUTINE_DEFINITION FROM information_schema.ROUTINES WHERE SPECIFIC_NAME='proc_name'

Heres how to enable Mary to access the view of the procedure via MySQL-Workbench:

By default, Mary is not able to send the create statement to the SQL-Editor. But this is just a privilege thing. Mary just needs a basic SELECT privilege in the mysql.proc table. To do this, run the following SQL-Statement (via Command line or directly in the Workbench):

GRANT SELECT ON mysql.proc TO 'mary'@'%'

This command enables Mary to access the Create-Statement from all hosts. If you want to limit it to a specific host you would do something like:

GRANT SELECT ON mysql.proc TO 'mary'@'192.168.2.1'

If Mary has the SELECT privilege she should be able to see the procedure after doing Send to SQL Editor -> CREATE statement

NOTE: In order to run the GRANT-Command you need to be logged in as user who has the privilege to grant privileges (e.g. root-user)

+++++++++++++++++++++++++EDIT+++++++++++++++++++++++++

There is a "quick and dirty" way to achieve this for a large number of users without writing for each user a new command to grant the privilege: (make sure to do this with a user who has the privilege to insert rows via the Workbench)

  1. Open a new SQL-Tab in your Workbench
  2. Type SELECT * FROM mysql.tables_priv; and run it
  3. Above the result-grid there should be the a small button which allows you to import data from a csv-File.
  4. Create a CSV-File which looks like this:

    %,mysql,jane,proc,root@localhost,"2016-02-19 22:51:47",Select, %,mysql,max,proc,root@localhost,"2016-02-19 22:51:47",Select, %,mysql,steve,proc,root@localhost,"2016-02-19 22:51:47",Select, %,mysql,greg,proc,root@localhost,"2016-02-19 22:51:47",Select, %,mysql,jamie,proc,root@localhost,"2016-02-19 22:51:47",Select,

    ...further users

jane, max, steve,... would be your users. Leave the other columns the way they are.

  1. Import your csv-File
  2. Run FLUSH PRIVILEGES in an SQL-Window (reloades privileges from priv-tables)
  3. Finished! All your users can now access Stored Procedures
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!