显示 MySQL 数据库中的所有触发器

发布于 2024-07-05 10:15:41 字数 32 浏览 4 评论 0原文

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

What is the command to list all triggers in a MySQL database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

感悟人生的甜 2024-07-12 10:15:41

这句话可能有助于解决问题:

select LOWER(concat('delimiter |', '\n', 'create trigger %data_base_name%.', TRIGGER_NAME, '\n', 
'    ', ACTION_TIMING, ' ', EVENT_MANIPULATION, ' on %data_base_name%.', EVENT_OBJECT_TABLE, ' for each row', '\n',
ACTION_STATEMENT, '\n',
'|')) AS TablaTriggers from information_schema.triggers where 
information_schema.triggers.trigger_schema like '%data_base_name%'

This sentence could contribute to solving the problem:

select LOWER(concat('delimiter |', '\n', 'create trigger %data_base_name%.', TRIGGER_NAME, '\n', 
'    ', ACTION_TIMING, ' ', EVENT_MANIPULATION, ' on %data_base_name%.', EVENT_OBJECT_TABLE, ' for each row', '\n',
ACTION_STATEMENT, '\n',
'|')) AS TablaTriggers from information_schema.triggers where 
information_schema.triggers.trigger_schema like '%data_base_name%'
蝶…霜飞 2024-07-12 10:15:41

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

select * from information_schema.triggers where 
information_schema.triggers.trigger_name like '%trigger_name%' and 
information_schema.triggers.trigger_schema like '%data_base_name%'

For showing a particular trigger in a particular schema you can try the following:

select * from information_schema.triggers where 
information_schema.triggers.trigger_name like '%trigger_name%' and 
information_schema.triggers.trigger_schema like '%data_base_name%'
来日方长 2024-07-12 10:15:41

您可以使用 MySQL 工作台:
连接到 MySQL 服务器
在表名称行上选择数据库

  • 单击表编辑窗口中的编辑图标(看起来像工作工具)
  • - 单击触发器列表上的“触发器”选项卡
  • 单击触发器名称以获取其源代码

You can use MySQL Workbench:
Connect to the MySQL Server
Select DB

  • tables
  • on the table name line click the edit icon (looks like a work tool)
  • in the table edit window - Click the tab "Triggers"
  • on the Triggers list click th eTrigger name to get its source code
青巷忧颜 2024-07-12 10:15:41
USE dbname;
SHOW TRIGGERS

或者

SHOW TRIGGERS FROM dbname;
USE dbname;
SHOW TRIGGERS

OR

SHOW TRIGGERS FROM dbname;
記柔刀 2024-07-12 10:15:41

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

SHOW TRIGGERS LIKE '%trigger_name%'\G

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

SHOW TRIGGERS\G

You can use below to find a particular trigger definition.

SHOW TRIGGERS LIKE '%trigger_name%'\G

or the below to show all the triggers in the database. It will work for MySQL 5.0 and above.

SHOW TRIGGERS\G
z祗昰~ 2024-07-12 10:15:41

我希望下面的代码能为您提供更多信息。

select * from information_schema.triggers where 
information_schema.triggers.trigger_schema like '%your_db_name%'

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

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

I hope following code will give you more information.

select * from information_schema.triggers where 
information_schema.triggers.trigger_schema like '%your_db_name%'

This will give you total 22 Columns in MySQL version: 5.5.27 and Above

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
一个人的旅程 2024-07-12 10:15:41

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

show triggers;

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

select trigger_schema, trigger_name, action_statement
from information_schema.triggers

The command for listing all triggers is:

show triggers;

or you can access the INFORMATION_SCHEMA table directly by:

select trigger_schema, trigger_name, action_statement
from information_schema.triggers
梦亿 2024-07-12 10:15:41

您可以使用下面的 SQL 显示所有触发器。 *文档解释INFORMATION_SCHEMA.TRIGGERS 表,我建议使用 \G 可以更清楚地显示它们,下面的 SQL 可以比 SHOW TRIGGERS 这是我最后解释的:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS;

或者:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS\G

并且,您可以使用下面的 SQL 显示 apple 数据库的触发器:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA = 'apple';

并且,您可以显示apple 数据库选择 apple 数据库,其中 使用。 *文档解释了SHOW TRIGGERS< /code> ,我建议使用 \G 可以更清楚地显示它们:

USE apple;
SHOW TRIGGERS;

Or:

USE apple;
SHOW TRIGGERS\G

Or:

USE apple;
SHOW TRIGGERS FROM apple;

Or:

USE apple;
SHOW TRIGGERS FROM apple\G

并且,即使选择,您也可以显示 orange 数据库的触发器apple 数据库与 USE

USE apple;
SHOW TRIGGERS FROM orange;

并且,您可以显示 apple 数据库的触发器,而不选择任何一个具有 USE 的数据库>:

SHOW TRIGGERS FROM apple;

小心,如果你运行下面的SQL时没有用USE选择任何一个数据库:

SHOW TRIGGERS;

那么,就会出现下面的错误:

错误 1046 (3D000):未选择数据库

You can show all triggers with the SQL below. *The doc explains INFORMATION_SCHEMA.TRIGGERS table and I recommend to use \G which can show them more clearly and the SQL below can show more details than SHOW TRIGGERS which I explain last:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS;

Or:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS\G

And, you can show the triggers of apple database with the SQL below:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA = 'apple';

And, you can show the triggers of apple database selecting apple database with USE. *The doc explains SHOW TRIGGERS and I recommend to use \G which can show them more clearly:

USE apple;
SHOW TRIGGERS;

Or:

USE apple;
SHOW TRIGGERS\G

Or:

USE apple;
SHOW TRIGGERS FROM apple;

Or:

USE apple;
SHOW TRIGGERS FROM apple\G

And, you can show the triggers of orange database even if selecting apple database with USE:

USE apple;
SHOW TRIGGERS FROM orange;

And, you can show the triggers of apple database not selecting any one of databases with USE:

SHOW TRIGGERS FROM apple;

Be careful, if you run the SQL below not selecting any one of databases with USE:

SHOW TRIGGERS;

Then, there is the error below:

ERROR 1046 (3D000): No database selected

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文