Waiting for table metadata lock
出现下图这个现象之前是在一张事务操作频繁地表上,执行了truncate操作。
mysql.sock@(none)> select user,host,db,command,time,state,info from information_schema.processlist where user='root'\G;
*************************** . row ***************************
user: root
host: localhost
db: NULL
command: Query
time:
state: Waiting for table metadata lock
info: truncate payment.tb_cs_rule
问题原因:
MySQL 5.5. and up uses metadata locking to manage access to objects (tables, triggers, and so forth). Metadata locking is used to ensure data consistency but does involve some overhead, which increases as query volume increases. Metadata contention increases the more that multiple queries attempt to access the same objects.
Metadata locking is not a replacement for the table definition case, and its mutxes and locks differ from the LOCK_open mutex. The following discussion provides some information about how metadata locking works.
To ensure transaction serializability, the server must not permit one session to perform a data definition language (DDL) statement on a table that is used in an uncompleted transaction in another session. The server achieves this by acquiring metadata locks on tables used within a transaction and deferring release of those locks until the transaction ends. A metadata lock on a table prevents changes to the table's structure. This locking approach has the implication that a table that is being used by a transaction within one session cannot be used in DDL statements by other sessions until the transaction ends.
This principle applies not only to transactional tables, but also to nontransactional tables. Suppose that a session begins a transaction that uses transactional table t and nontransactional table nt as follows:
START TRANSACTION;
SELECT * FROM t;
SELECT * FROM nt;
Metadata locks are held on both t and nt until the transaction ends. If another session attempts a DDL operation on either table, it blocks until metadata lock release at transaction end. For example, a second session blocks if it attempts any of these operations:
DROP TABLE t;
ALTER TABLE t ...;
DROP TABLE nt;
ALTER TABLE nt ...;
If the server acquires metadata locks for a statement that is syntactically valid but fails during execution, it does not release the locks early. Lock release is still deferred to the end of the transaction because the failed statement is written to the binary log and the locks protect log consistency.
In autocommit mode, each statement is in effect a complete transaction, so metadata locks acquired for the statement are held only to the end of the statement.
Metadata locks acquired during a PREPARE statement are released once the statement has been prepared, even if preparation occurs within a multiple-statement transaction.
Before MySQL 5.5., when a transaction acquired the equivalent of a metadata lock for a table used within a statement, it released the lock at the end of the statement. This approach had the disadvantage that if a DDL statement occurred for a table that was being used by another session in an active transaction, statements could be written to the binary log in the wrong order
解决办法:
将truncate变成delete
Waiting for table metadata lock的更多相关文章
- MySQL出现Waiting for table metadata lock的原因以及解决方法
转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) MySQL在进行alter table等DDL操作时,有时会出现Waiting for tab ...
- 【转】【MySql】Waiting for table metadata lock原因分析
MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Wa ...
- mysql出现Waiting for table metadata lock的原因及解决方案
最近经常遇到mysql数据库死锁,郁闷死, show processlist; 时 Waiting for table metadata lock 能一直锁很久 下面有官网的一段话,可以理解下 htt ...
- 20180117MySQL出现Waiting for table metadata lock的原因以及解决方法
转自http://www.cnblogs.com/digdeep/p/4892953.html 转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) ...
- 【MySQL经典案例分析】 Waiting for table metadata lock
本文由云+社区发表 一. 问题是这样来的 2018年某个周末,接到连续数据库的告警,告警信息如下: 二. 苦逼的探索过程 1.总体的思路 看到too many connection的报错信息,基本 ...
- MySQL出现Waiting for table metadata lock的场景浅析
MySQL版本为5.6.12. 在进行alter table操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的 ...
- 修改字段字符集 mysql 修改 锁表 show processlist; 查看进程 Waiting for table metadata lock
ALTER TABLE `question` MODIFY COLUMN `title` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unico ...
- 记一次MySQL中Waiting for table metadata lock问题的处理
起因:由于需要,要把一张表的一个字段从不是 null 改成 可null,我用的Navicat Premium ,但是在保存的时候,工具无响应了,几个同事操作都是这样的,很奇怪,怀疑是不是由于表被锁了还 ...
- MySQL Waiting for table metadata lock的解决方法
最近需要在某一个表中新增字段,使用Sequel Pro 或者Navicat工具都会出现程序没有反应,使用 show processlist 查看,满屏都是 Waiting for table meta ...
随机推荐
- [原创] debian 9.3 搭建Jira+Confluence+Bitbucket项目管理工具(二) -- 安装jira 7.5.4
[原创] debian 9.3 搭建Jira+Confluence+Bitbucket项目管理工具(二) -- 安装jira 7.5.4 环境都配置好以后, 开始搭建Jira的环境, 这里参考了一篇文 ...
- unable to resolve module react-native-gesture-handler from
在安装了npm install --save react-navigation后跑项目然后就红屏了. 解决方法: 安装触摸方式(需要执行以下方法) npm install --save react-n ...
- python的django基础篇
一.Django基础 Django 是用Python开发的一个免费开源的Web框架,可以用于快速搭建高性能,优雅的网站! Django的特点: 强大的数据库功能:拥有强大的数据库操作接口(QueryS ...
- Java框架spring学习笔记(十七):事务操作
事务操作创建service和dao类,完成注入关系 service层叫业务逻辑层 dao层单纯对数据库操作层,在dao层不添加业务 假设现在有一个转账的需求,狗蛋有10000元,建国有20000元,狗 ...
- 区块链入门(5)Truffle 项目实战,Solidity IDE, 智能合约部署
在上一张我们学习了Truffle项目的创建,部署等相关内容,今天我们就来实战一下. 今天我们要做3件事: 1) 学习搭建一个Solidity IDE(Remix). 2) 使用这个Solidity I ...
- 一.javascript核心部分:1.词法结构
本文作为个人学习笔记,一直也没有重视javascript的系统学习(javascript是最容易被人忽视的语言),我都是要用的时候百度一下查找下资料开始用,但没有系统的,学习,和整理过javascri ...
- lvm的备份还原及修改UUID
今天在VMware® Workstation 12 Pro虚拟机上克隆了一台Linux虚拟机,无意中发现两台虚拟机blkid一模一样. [root@stau64 ~]# blkid [root@sta ...
- webpack 模块方法
1. webpack的import和export不需要引入babel 其他ES6语法需要引入babel 2. import引入export导出的模块 3. import()模块分离 低版本浏览器想使 ...
- Eclipse中查看JDK类库源代码
在Eclipse中编写代码时,有时候可能需要了解JDK类库的一些特性,这个时候可以通过查看类的源代码来了解JDK类的详细信息.本文主要内容就是如何直接在Eclipse开发环境中查看JDK类库源代码. ...
- 识别手机浏览器代码【C#和JS两种语言】
C# 识别手机浏览器代码: public static bool MobileBrowserDetect() { bool bismobile = false; try { #region 包含and ...