Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to Disable deletes on a table on MYSQL?

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.

like image 856
Skynight Avatar asked Oct 30 '11 22:10

Skynight


People also ask

Is deletion possible in MySQL?

You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the condition in the WHERE clause. You cannot use ORDER BY or LIMIT in a multiple-table DELETE .

How do I disable a row in MySQL?

To delete rows in a MySQL table, use the DELETE FROM statement: DELETE FROM products WHERE product_id=1; The WHERE clause is optional, but you'll usually want it, unless you really want to delete every row from the table.

Which MySQL command is used to delete or remove a record?

If you want to delete a record from any MySQL table, then you can use the SQL command DELETE FROM.


2 Answers

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 ;
like image 158
costamatrix Avatar answered Oct 06 '22 00:10

costamatrix


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.

like image 39
Aiden Bell Avatar answered Oct 05 '22 23:10

Aiden Bell