Home > Database > Mysql Tutorial > How to solve the Waiting for table metadata lock exception in MySQL

How to solve the Waiting for table metadata lock exception in MySQL

WBOY
Release: 2023-05-29 11:31:12
forward
2635 people have browsed it

1. Reason

When a DDL statement is executed, the MDL metadata write lock will be automatically added to the table, and the lock will not be released until the transaction is committed. The purpose of this lock is to protect the integrity of the table structure and the consistency of metadata.

2. Processing method

Mode the production environment as shown below: session A opens a transaction and executes DQL

How to solve the Waiting for table metadata lock exception in MySQL

This Session B needs to add full-text indexes to the two fields of the table.

How to solve the Waiting for table metadata lock exception in MySQL

After execution, it was found that the master has been stuck.

How to solve the Waiting for table metadata lock exception in MySQL

Check the related process list and find that it has been waiting to obtain the mdl metadata lock

select * from information_schema.processlist where info like '%alter table `bas_business_type_text` %'
Copy after login

How to solve the Waiting for table metadata lock exception in MySQL

Looking at the table lock situation, you can see that the read and write locks are mutually exclusive

SELECT * FROM sys.schema_table_lock_waits
Copy after login

How to solve the Waiting for table metadata lock exception in MySQL

According to the prompts, execute kill 11

How to solve the Waiting for table metadata lock exception in MySQL

You can see that session B was executed successfully immediately

How to solve the Waiting for table metadata lock exception in MySQL

The above is the detailed content of How to solve the Waiting for table metadata lock exception in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template