如何列出MySQL数据库中的所有触发器?
要列出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表。
注意-您必须具有MySQL5.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)
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿