MySQL table lock

How to lock a table in MySQL so that you cannot edit or discard it no matter what if you do not unlock it?

+4
source share
2 answers

"Locking" a table usually means restricting access to the data in the table by other processes during data editing. To protect the table so that it cannot be changed or deleted, I believe that the best solution would be to change the permissions of the table, delete DROP, UPDATE, INSERT and any other permissions that you want to restrict for this particular table.

REVOKE DROP, INSERT, TRUNCATE ON database.table FOR 'user'@'host'; 
+7
source

You can use the LOCK keyword.

 LOCK TABLES t1 READ; 

Here is the syntax:

 LOCK TABLES tbl_name [[AS] alias] lock_type [, tbl_name [[AS] alias] lock_type] ... 

Where:

 lock_type: READ [LOCAL] | [LOW_PRIORITY] WRITE 

Read the documents for more information and the requirements necessary to lock the table, for example, it also depends on the type of your db server.

+2
source

Source: https://habr.com/ru/post/1339485/


All Articles