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: [email protected]% 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: [email protected]% 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: [email protected]% character_set_client: utf8mb4 collation_connection: utf8mb4_general_ci Database Collation: utf8_general_ci 3 rows in set (0.00 sec) ERROR: No query specifiedshow 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