I try and load tables via MySQL and get the following error?
MySQL said: Table 'cms' was not locked with LOCK TABLES
Why does the table need to be Locked? I haven't seen this before? is there any way to unlock? do you even want to?
In MySQL, locked tables are identified using the SHOW OPEN TABLES command. In its simplest form is displays all locked tables. All open tables in the table cache are listed, but the IN_USE column indicates of the table is locked. When the first lock is taken, the value increments to 1.
LOCK TABLES works as follows: Sort all tables to be locked in an internally defined order (from the user standpoint the order is undefined). If a table is locked with a read and a write lock, put the write lock before the read lock. Lock one table at a time until the thread gets all locks.
LOCK TABLES is not transaction-safe and implicitly commit any active transaction before attempting to lock the tables. Beginning a transaction, for instance, START TRANSACTION implicitly commits any current transaction and releases existing MySQL locks.
If in one session, you locked one table but want to select from another table, you must either lock that table too or unlock all tables.
mysql> LOCK TABLES t1 READ; mysql> SELECT COUNT(*) FROM t1; +----------+ | COUNT(*) | +----------+ | 3 | +----------+ mysql> SELECT COUNT(*) FROM t2; ERROR 1100 (HY000): Table 't2' was not locked with LOCK TABLES
The solution for me was to unlock the tables. They had been locked by a previous query which failed before reaching the unlock tables
statement.
UNLOCK TABLES SELECT ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With