MySQL – Table ‘the_table’ was not locked with Lock Tables

MySQL

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?

Best Answer

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