Friday, June 22, 2018

MySQL - Table 'my_table' was not locked with Lock Tables

http://dev.mysql.com/doc/refman/5.7/en/lock-tables.html



MySQL enables client sessions to acquire table locks explicitly for
the purpose of cooperating with other sessions for access to tables,
or to prevent other sessions from modifying tables during periods when
a session requires exclusive access to them. A session can acquire or
release locks only for itself. One session cannot acquire locks for
another session or release locks held by another session.


Locks may be used to emulate transactions or to get more speed when
updating tables. This is explained in more detail later in this
section.


LOCK TABLES explicitly acquires table locks for the current client
session. Table locks can be acquired for base tables or views. You
must have the LOCK TABLES privilege, and the SELECT privilege for each
object to be locked.


For view locking, LOCK TABLES adds all base tables used in the view to
the set of tables to be locked and locks them automatically. If you
lock a table explicitly with LOCK TABLES, any tables used in triggers
are also locked implicitly, as described in Section 13.3.5.2, “LOCK
TABLES and Triggers”.


UNLOCK TABLES explicitly releases any table locks held by the current
session. LOCK TABLES implicitly releases any table locks held by the
current session before acquiring new locks.


Another use for UNLOCK TABLES is to release the global read lock
acquired with the FLUSH TABLES WITH READ LOCK statement, which enables
you to lock all tables in all databases. See Section 13.7.6.3, “FLUSH
Syntax”. (This is a very convenient way to get backups if you have a
file system such as Veritas that can take snapshots in time.)



Syntax for LOCK and UNLOCK


 LOCK TABLES
tbl_name [[AS] alias] lock_type
[, tbl_name [[AS] alias] lock_type] ...
lock_type:
READ [LOCAL]
| [LOW_PRIORITY] WRITE

Eg:-


LOCK TABLE t WRITE, t AS t1 READ;

Unlock tables


 UNLOCK TABLES

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...