Locking is important in many scenarios to prevent other sessions from modifying tables during periods when a session requires exclusive access to them. for example altering table definition online or any kind of table definition changes. Mysql provides an option to lock table/s with different types of locks, depends on need.
syntax for lock table:
LOCK TABLEStbl_name
[[AS]alias
]lock_type
[,tbl_name
[[AS]alias
]lock_type
] ...lock_type
: READ [LOCAL] | [LOW_PRIORITY] WRITE UNLOCK TABLES
Following are the examples for READ and WRITE LOCK:
READ LOCK:
session1> create table t1( c1 int); Query OK, 0 rows affected (0.06 sec) session1> insert …[Read more]