Mariadb 数据库级触发器

Mariadb Database level trigger

CREATE TRIGGER safety_drop
ON DATABASE 
FOR DROP_TABLE
AS
BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'DELETING NOT ALLOWED';
ROLLBACK;
END

错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ON DATABASE FOR DROP_TABLE AS BEGIN SIGNAL SQLSTATE '45000' SET MESSAGE_TEX' at line 2

MariaDB 只是不支持“数据库级”触发器。引用 the documentation(重点添加):

A trigger, as its name suggests, is a set of statements that run, or are triggered, when an event occurs on a table. [...] The event can be an INSERT, an UPDATE or a DELETE.

所以基本上这适用于 DML 操作(更改数据的语句),而不适用于 DDL(更改结构的操作)。

至于您的要求,使用权限和角色来防止用户在数据库中删除任何 table 似乎是一种更相关的方法。