How to bulk change MySQL Triggers DEFINER(如何批量更改 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
这篇关于如何批量更改 MySQL 触发器 DEFINER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何批量更改 MySQL 触发器 DEFINER


基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01