如何批量更改 MySQL 触发器 DEFINER
我一直在我们的内部开发服务器上工作,并在我们的 MySQL 5.6.13 服务器上创建 MySQL 触发器.我现在遇到的问题是触发器(总共大约 200 个)是在内部服务器上使用 DEFINER=root
@%
创建的.
I've been working on our internal development server and creating MySQL Triggers on our MySQL 5.6.13 server. The problem I now have is the Triggers (around 200 in total) were created with as DEFINER=root
@%
on the internal server.
现在我想转移到实时生产服务器.但是,在我们的实时服务器上,我们不允许 root 用户进行此访问.因此,如何批量更改所有触发器,使其读取 DEFINER=root
@localhost
Now I want to move to the live production server. However on our live server we don't allow this access for user root. Therefore how can I bulk change all my Triggers, so that it reads DEFINER=root
@localhost
推荐答案
一种方法:
1) 将触发器定义转储到文件中
1) Dump trigger definitions into a file
# mysqldump -uroot -p --triggers --add-drop-trigger --no-create-info
--no-data --no-create-db --skip-opt test > /tmp/triggers.sql
2) 在您喜欢的编辑器中打开 triggers.sql
文件并使用 Find and Replace
功能来更改 DEFINER
s.保存更新的文件.
2) Open triggers.sql
file in your favorite editor and use Find and Replace
feature to change DEFINER
s. Save updated file.
3) 从文件中重新创建触发器
3) Recreate triggers from the file
# mysql < triggers.sql
相关文章