I try and load tables via MySQL and get the following error?
MySQL said: Table \'cms\' was not locked with LOCK TABLES
Why does
One of the most important lines in the MySQL docs relating to the "Table 'my_table' was not locked with LOCK TABLES" message is as follows:
"While the locks thus obtained are held, the session can access only the locked tables" https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html
This means that if you are trying to access any other table in the database while the LOCK is in place you will get the error message "Table 'my_table' was not locked with LOCK TABLES"
The fix is to apply the lock to all of the tables you want to have access to during the lock like this. "LOCK TABLES table_1 WRITE, table_2 WRITE"
Where table_1 is the one you really want to lock but you also want to access table_2 during the same process.
This was confusing because I was locking only table_1 but the error message was telling me Table 'table_2' was not locked with LOCK TABLES
Took me a while to figure out why table_2 was even involved. I hope that this helps someone else with the same issue.