MySQL 데이터베이스의 모든 트리거를 나열하려면 SHOW 명령을 사용할 수 있습니다. 쿼리는 다음과 같습니다 -
mysql> show triggers;
다음은 출력입니다 -
+----------------+--------+----------------------+--------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ | Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation | +----------------+--------+----------------------+--------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ | binsertTrigger | INSERT | functiontriggersdemo | SET new.Id = uuid() | BEFORE | 2018-10-16 13:36:09.86 | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | root@% | cp850 | cp850_general_ci | utf8mb4_unicode_ci | | Table1Trigger | INSERT | table1 | begin insert into Table2(id, name) values (new.id, new.name); end | AFTER | 2018-10-23 10:51:31.76 | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | root@% | cp850 | cp850_general_ci | utf8mb4_unicode_ci | | insertBef | INSERT | tblfunctiontrigger | SET new.id = uuid() | BEFORE | 2018-10-16 13:44:10.93 | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | root@% | cp850 | cp850_general_ci | utf8mb4_unicode_ci | +----------------+--------+----------------------+--------------------------------------------------------------------+--------+------------------------+--------------------------------------------+---------+----------------------+----------------------+--------------------+ 3 rows in set (0.13 sec)
다음 쿼리를 사용하여 information_schema 테이블에 액세스할 수 있습니다.
참고 − MySQL 버전 5.0.10 이상이 필요합니다. 저는 현재 MySQL 버전 8.0.12를 사용하고 있습니다 -
mysql> select trigger_schema, trigger_name, action_statement −> from information_schema.triggers;
다음은 출력입니다 -
+----------------+----------------------------+-------------------------------------------------------------------------------------------------------------------+ | TRIGGER_SCHEMA | TRIGGER_NAME | ACTION_STATEMENT | +----------------+----------------------------+-------------------------------------------------------------------------------------------------------------------+ | sys | sys_config_insert_set_user | BEGIN IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN SET NEW.set_by = USER(); END IF; END | | sys | sys_config_update_set_user | BEGIN IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN SET NEW.set_by = USER(); END IF; END | | business | binsertTrigger | SET new.Id = uuid() | | business | insertBef | SET new.id = uuid() | | business | Table1Trigger | begin insert into Table2(id, name) values (new.id, new.name);end | +----------------+----------------------------+-------------------------------------------------------------------------------------------------------------------+ 5 rows in set (0.00 sec)