MySQL 更改存储过程定义器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3206820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:30:40  来源:igfitidea点击:

Change the stored procedure definer

mysqlstored-procedures

提问by Mithun Sreedharan

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

我的 MySQL 数据库中有大约一百个存储的例程,其中大多数都有“root”作为定义者。

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

我有另一个名为'abc'的mysql帐户,如何将所有例程的定义器更改为'abc'。

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

如果我只能作为“abc”用户而不是“root”访问 MySQL 服务器,是否可以做同样的事情

采纳答案by Fosco

As far as I know: You would have to get the script text of them all and drop/recreate them as abc. You would not be able to do this as abc unless abc has permission to drop/create procedures.

据我所知:您必须获取所有脚本文本并将它们删除/重新创建为 abc。除非 abc 具有删除/创建过程的权限,否则您将无法以 abc 的身份执行此操作。

回答by gibzaki

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.

小心,因为这将更改所有数据库的所有定义器。

回答by Darshan Patil

You can update the definer in mysql.proc table against the required table/db...

您可以根据所需的表/数据库更新 mysql.proc 表中的定义器...

update mysql.proc set definer='root@localhost' where name='t_p';

回答by x-yuri

Export all the procedures of the database <DB>:

导出数据库的所有程序<DB>

mysqldump --single-transaction --no-data --no-create-info --routines \
    --skip-triggers <DB> >routines.sql

Edit routines.sqland recreate them:

编辑routines.sql并重新创建它们:

cat routines.sql | mysql <DB>

Specify -uand -pswitches if necessary.

必要时指定-u-p切换。

回答by Brian Henkel

I've done mass Definer changes by exporting the database, opening the exported file in a text editor (not a word processor) and doing a find and replace trading the new Definer for the old. I then rename the original database and create a new database with the original database's name. Just import the modified export file with the new Definer information and you're done. I like this solution because it gives me a fallback if things go sideways. If something doesn't work, drop the database you created and rename the copy.

我已经通过导出数据库,在文本编辑器(不是文字处理器)中打开导出的文件并进行查找和替换来替换旧的定义器,从而完成了大量的定义器更改。然后我重命名原始数据库并使用原始数据库的名称创建一个新数据库。只需使用新的定义器信息导入修改后的导出文件即可。我喜欢这个解决方案,因为如果事情横向发展,它会给我一个后备。如果某些内容不起作用,请删除您创建的数据库并重命名副本。

回答by Sam

alter procedure old_proc_name
delimiter //
create PROCEDURE new_proc_name (parameter)
begin
 Your Sql Statement;
end//
delimiter ;