使用触发器转储 mysql5.5 模式并恢复到具有不同名称的新模式
我遇到的问题是触发器定义在其中硬编码了原始模式名称,例如:
TRIGGER `sales`.`tender_delete_trigger`
AFTER DELETE ON `sales`.`tender`
FOR EACH ROW
......
因此,如果使用 mysqldump 备份“sales”模式,然后尝试恢复到我得到的同一服务器上新创建的名为“sales_test”的模式在同一事件上不允许出现表示多个触发器的错误。
我当前的解决方案是在转储文件中手动将旧架构名称“sales”替换为新架构名称“sales_test”。这可行,但是有没有更简单、不那么繁琐的解决方案呢?
The problem I have is that the trigger definitions have the original schema name hardcoded within them e.g:
TRIGGER `sales`.`tender_delete_trigger`
AFTER DELETE ON `sales`.`tender`
FOR EACH ROW
......
So if backup the 'sales' schema, using mysqldump, then try and restore to a newly created schema called 'sales_test' on the same server I get an error stating something along the lines of multiple triggers are not allowed on the same event.
My current solution is to manually replace the old schema name 'sales' with the new schema name 'sales_test' within the dump file. This works, but is there an easier less tedious solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要手动执行此操作。由于您没有指定操作系统,我将假设使用 Linux,尽管大多数其他操作系统都有等效的操作系统:
另一种可能性是从触发器中省略架构名称。假定当前模式。
(编辑)
1)同意。但重命名模式一开始就是一个奇怪的问题。 2)这肯定是一个风险,因为可能存在类似名称的表和变量。对模式的修改可能会有所帮助:
坚持将模式名称放置在适当的位置,除非中间有空格。
Don't do it manually. Since you don't specify an O/S, I'll assume Linux, though there are equivalents for most others:
Another possibility is to omit the schema name from the triggers. The current schema is assumed.
(edit)
1) Agreed. But renaming a schema is a strange problem to begin with. 2) That is certainly a risk since there are likely to be tables and variables similarly named. A modification to the pattern might help:
would insist that the schema name is appropriately placed, unless there is intervening whitespace.