mysql 查看删除触发器等操作

Posted davie_2020

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 查看删除触发器等操作相关的知识,希望对你有一定的参考价值。

mysql 查看删除触发器等操作

  平时很少操作触发器,源于昨晚的一次故障,使用pt-online-change-schema修改大表过程中出现异常,再次执行时,提示已经存在触发器,导致失败。

这里推荐第三种方式:

 

1.、查看所有触发器

select * from information_schema.triggersG;

2、根据触发器名称看下相关触发器信息

mysql> select * from information_schema.triggers where trigger_name=‘pt_osc_fudao_course_fudao_course_ins‘G;

3、show triggersG;

技术图片
mysql>  show triggersG;
*************************** 1. row ***************************
             Trigger: pt_osc_fudao_course_fudao_course_ins
               Event: INSERT
               Table: fudao_course
           Statement: REPLACE INTO `fudao_course`.`_fudao_course_new` (`id`, `course_id`, `subject`, `grade`, `tid`, `uid`, `aid`, `join_person_id`, `period_type`, `start_time`, `end_time`, `day`, `week`, `day_start_time`, `day_end_time`, `grade_type`, `course_type`, `course_status`, `teacher_remark`, `student_remark`, `cw_id`, `hw_id`, `add_time`, `update_time`, `complaint`) VALUES (NEW.`id`, NEW.`course_id`, NEW.`subject`, NEW.`grade`, NEW.`tid`, NEW.`uid`, NEW.`aid`, NEW.`join_person_id`, NEW.`period_type`, NEW.`start_time`, NEW.`end_time`, NEW.`day`, NEW.`week`, NEW.`day_start_time`, NEW.`day_end_time`, NEW.`grade_type`, NEW.`course_type`, NEW.`course_status`, NEW.`teacher_remark`, NEW.`student_remark`, NEW.`cw_id`, NEW.`hw_id`, NEW.`add_time`, NEW.`update_time`, NEW.`complaint`)
              Timing: AFTER
             Created: NULL
            sql_mode: NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION
             Definer: admin_m@%
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
  Database Collation: utf8_general_ci
*************************** 2. row ***************************
             Trigger: pt_osc_fudao_course_fudao_course_upd
               Event: UPDATE
               Table: fudao_course
           Statement: BEGIN DELETE IGNORE FROM `fudao_course`.`_fudao_course_new` WHERE !(OLD.`id` <=> NEW.`id`) AND `fudao_course`.`_fudao_course_new`.`id` <=> OLD.`id`;REPLACE INTO `fudao_course`.`_fudao_course_new` (`id`, `course_id`, `subject`, `grade`, `tid`, `uid`, `aid`, `join_person_id`, `period_type`, `start_time`, `end_time`, `day`, `week`, `day_start_time`, `day_end_time`, `grade_type`, `course_type`, `course_status`, `teacher_remark`, `student_remark`, `cw_id`, `hw_id`, `add_time`, `update_time`, `complaint`) VALUES (NEW.`id`, NEW.`course_id`, NEW.`subject`, NEW.`grade`, NEW.`tid`, NEW.`uid`, NEW.`aid`, NEW.`join_person_id`, NEW.`period_type`, NEW.`start_time`, NEW.`end_time`, NEW.`day`, NEW.`week`, NEW.`day_start_time`, NEW.`day_end_time`, NEW.`grade_type`, NEW.`course_type`, NEW.`course_status`, NEW.`teacher_remark`, NEW.`student_remark`, NEW.`cw_id`, NEW.`hw_id`, NEW.`add_time`, NEW.`update_time`, NEW.`complaint`);END
              Timing: AFTER
             Created: NULL
            sql_mode: NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION
             Definer: admin_m@%
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
  Database Collation: utf8_general_ci
*************************** 3. row ***************************
             Trigger: pt_osc_fudao_course_fudao_course_del
               Event: DELETE
               Table: fudao_course
           Statement: DELETE IGNORE FROM `fudao_course`.`_fudao_course_new` WHERE `fudao_course`.`_fudao_course_new`.`id` <=> OLD.`id`
              Timing: AFTER
             Created: NULL
            sql_mode: NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION
             Definer: admin_m@%
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
  Database Collation: utf8_general_ci
3 rows in set (0.00 sec)

ERROR: 
No query specified
show triggersG

4、删除触发器

技术图片
drop trigger pt_osc_fudao_course_fudao_course_ins;
drop trigger pt_osc_fudao_course_fudao_course_upd;
drop trigger pt_osc_fudao_course_fudao_course_del;
drop trigger

 

 

以上是关于mysql 查看删除触发器等操作的主要内容,如果未能解决你的问题,请参考以下文章

[转]mysql查看所有触发器以及存储过程等操作集合

MySQL触发器触发器的使用创建修改及删除

MySQL-08-笔记

mysql事务触发器视图存储过程函数

MySQL触发器的操作

mysql关于触发器怎么判断数据存在时更新不存在时添加呢!