I'm using MySQL 5.0 and I would like to know if there's a way to disable deletes on a table. As in, not make it possible for ANY user to delete anything from the tablets, only update and insert.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here's an example of a trigger:
DELIMITER $$
CREATE TRIGGER tr_table1_del BEFORE DELETE ON table1 FOR EACH ROW
BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'DELETE cancelled';
END $$
DELIMITER ;
回答2:
Yes, see the MySQL manual for the GRANT syntax
Here is an example of what you want:
GRANT SELECT, INSERT ON mydb.mytbl TO 'someuser'@'somehost';
Which gives only SELECT
and INSERT
privilages to a specific user/host on a specified table.
回答3:
You can use grant
as proposed by others. Or you can create BEFORE DELETE
trigger that raises an error, so nobody can issue delete
against your table (keep in mind, it is still possible to TRUNCATE TABLE
)
回答4:
Setting permissions on your table would let you disable the delete operations. You set permissions with GRANT
.