如何列出MySQL数据库中的所有触发器?

Har*_*rry 93 mysql triggers

列出MySQL数据库中所有触发器的命令是什么?

Har*_*rry 134

列出所有触发器的命令是:

show triggers;
Run Code Online (Sandbox Code Playgroud)

或者您可以通过以下方式INFORMATION_SCHEMA直接访问该表:

select trigger_schema, trigger_name, action_statement
from information_schema.triggers
Run Code Online (Sandbox Code Playgroud)

  • 请注意,`SHOW TRIGGERS`要求您拥有该数据库和表的`TRIGGER`权限.如果您使用非特权用户登录MySQL,执行`SHOW TRIGGERS`将不返回任何内容而不是抛出错误.如果您不了解特权要求,那可能会令人困惑. (3认同)
  • 我建议使用"SHOW TRIGGERS"查询而不是直接访问information_schema - 一旦你在服务器上拥有超过数千个数据库而后者将非常慢,而"SHOW TRIGGERS"仍然具有出色的性能. (2认同)

Pra*_*ria 13

我希望以下代码能为您提供更多信息.

select * from information_schema.triggers where 
information_schema.triggers.trigger_schema like '%your_db_name%'
Run Code Online (Sandbox Code Playgroud)

这将为您提供MySQL版本中的总共22列:5.5.27及以上

TRIGGER_CATALOG 
TRIGGER_SCHEMA
TRIGGER_NAME
EVENT_MANIPULATION
EVENT_OBJECT_CATALOG
EVENT_OBJECT_SCHEMA 
EVENT_OBJECT_TABLE
ACTION_ORDER
ACTION_CONDITION
ACTION_STATEMENT
ACTION_ORIENTATION
ACTION_TIMING
ACTION_REFERENCE_OLD_TABLE
ACTION_REFERENCE_NEW_TABLE
ACTION_REFERENCE_OLD_ROW
ACTION_REFERENCE_NEW_ROW
CREATED 
SQL_MODE
DEFINER 
CHARACTER_SET_CLIENT
COLLATION_CONNECTION
DATABASE_COLLATION
Run Code Online (Sandbox Code Playgroud)


Kai*_*nda 12

您可以使用以下内容查找特定的触发器定义.

SHOW TRIGGERS LIKE '%trigger_name%'\G
Run Code Online (Sandbox Code Playgroud)

或以下显示数据库中的所有触发器.它适用于MySQL 5.0及更高版本.

SHOW TRIGGERS\G
Run Code Online (Sandbox Code Playgroud)


小智 9

要在特定模式中显示特定触发器,您可以尝试以下操作:

select * from information_schema.triggers where 
information_schema.triggers.trigger_name like '%trigger_name%' and 
information_schema.triggers.trigger_schema like '%data_base_name%'
Run Code Online (Sandbox Code Playgroud)