One solution would be to create a child table with a foreign key to your permissions table, and add dependent rows referencing the individual rows for which you want to block deletion.
CREATE TABLE preserve_permissions (
permission_id INT PRIMARY KEY,
FOREIGN KEY (permission_id) REFERENCES permissions (permission_id)
);
INSERT INTO perserve_permissions (permission_id) VALUES (1234);
Now you can't delete the row from permissions with id 1234, because it would violate the foreign key dependency.
If you really want to do it with a trigger, instead of re-inserting a row when someone tries to delete it, just abort the delete. MySQL 5.5 has the SIGNAL
feature to raise an SQLEXCEPTION in a stored proc or trigger.
If you use MySQL 5.0 or 5.1, you can't use SIGNAL but you can use a trick which is to declare a local INT variable in your trigger and try to assign a string value to it. This is a data type conflict so it throws an error and aborts the operation that spawned the trigger. The extra clever trick is to specify an appropriate error message in the string you try to stuff into the INT, because that string will be reported in the error! :-)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…