问题
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:
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.
回答2:
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
)
回答3:
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 ;
回答4:
Setting permissions on your table would let you disable the delete operations. You set permissions with GRANT.
来源:https://stackoverflow.com/questions/7948302/is-it-possible-to-disable-deletes-on-a-table-on-mysql