mysql: ERROR 1100 (HY000): Table ‘user‘ was not locked with LOCK TABLES

This error (ERROR 1100 (HY000): Table 'user' was not locked with LOCK TABLES) encountered in MySQL is because after locking a specific table using the LOCK TABLES command, execution related to global permissions or system Table-related operations (such as FLUSH PRIVILEGES) that require access to unlocked system tables (such as user tables).
Insert image description here

explain

When we execute theLOCK TABLES command, MySQL locks the specified tables to protect them from write operations by other sessions. In the locked state, the current session can only access the locked table. This means that after locking some tables, trying to access unlocked tables (such as system tables or other tables not included in theLOCK TABLEScommand) will result in an error.

WhyFLUSH PRIVILEGES throws an error

FLUSH PRIVILEGESThe command is used to reload the permission table (such as the user table) to ensure that permission changes take effect immediately. Since the permissions table was not locked after executing LOCK TABLES, when trying to execute FLUSH PRIVILEGES, MySQL detected that the permissions table was not locked, thus causing an error.

How to solve

  1. Unlock the table:
    needs to be unlocked before performing FLUSH PRIVILEGES or operations that require access to other tables Locked form. Use the following command:

    UNLOCK TABLES;
    
  2. Execute the operation again:
    After unlocking the table, you can perform FLUSH PRIVILEGES or other operations that require access to the unlocked The table is operated.

Precautions

  • When usingLOCK TABLES, please make sure we understand the scope of the lock to avoid unnecessary access conflicts or errors.
  • Use when you need to perform maintenance on the table or perform a specific operationLOCK TABLES, but remember to release the lock after the operation is completed.

おすすめ

転載: blog.csdn.net/qq_14829643/article/details/134889136