开发者

mysqldump Fully Qualifies Triggers with Database Name

开发者 https://www.devze.com 2023-01-21 05:12 出处:网络
I\'m am trying to use mysqldump to export a database which needs to be imported using a different database name. Looking at the SQL generated by mysqldump, it appears that triggers are the only object

I'm am trying to use mysqldump to export a database which needs to be imported using a different database name. Looking at the SQL generated by mysqldump, it appears that triggers are the only object names which are fully-qualified with the source database name thus foiling my needs. Is there anyway to dire开发者_Go百科ct mysqldump to not fully-qualify any object names including triggers?


I had the same problem and I found the solution. I was using MySQL Workbench to design my database and I've created some triggers there. All of them used the syntax CREATE TRIGGER trigger_name except for one: CREATE TRIGGER dbname.trigger_name (it was just my mistake). Mysqldump output included all triggers in the same way: only one had database name.

Mysqldump uses your original CREATE TRIGGER instructions which you can see via SHOW CREATE TRIGGER. If you have a trigger defined with a database name, simply replace it (drop and create) with a one without dbname.


Most probably you add the database name when you create the trigger. Try updating your trigger without the database name in it.


Not an ideal solution but pumping the output through the following has gotten rid of the database name on the triggers for me.

mysqldump ... opts ... | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' 
0

精彩评论

暂无评论...
验证码 换一张
取 消