Home Database Mysql Tutorial Mysql Error:1205错误诊断_MySQL

Mysql Error:1205错误诊断_MySQL

Jun 01, 2016 pm 01:18 PM

bitsCN.com

      前两天遇到一个1205(ER_LOCK_WAIT_TIMEOUT)的错误,弄了半天终于找到原因,掌握原理+细心才能找到罪归祸首。下面我给大家分享下这个问题的分析处理过程,希望对大家有所帮助。接到slave error告警后,看到现场是这样的:slave重做binlog因为锁超时中断,报HA_ERR_LOCK_WAIT_TIMEOUT错误。

     超时,easy啊,心想估计是有大事务长期持有锁,导致其他事务超时等待。但是这个库是只读的备库,不可能有写事务,通过show processlist命令也确实没有发现写事务,倒是有一个大查询任务。当时觉得MVCC查询不上锁啊,直接无视。我尝试重新start slave,发现没过几秒钟,错误依然出现,并且Exec_Master_Log_Pos没有变化,这说明同样的事务尝试写错误,依然被堵住,导致锁超时等待了。这一定是事务持有锁导致锁超时,但机器上除了查询,啥也木有。隔离级别,确认下隔离级别,虽然生产环境中机器都是RC(读提交)模式,但也不排除这种可能。但结果再次让我失望,事务隔离级别是读提交。

会不会是存储引擎的问题,我又验证了一把,表是innodb存储引擎,读不存在说是上表锁的情况。无语了,难道innodb的MVCC,读在某些情况下也上锁?这岂不是与读不上锁上违背吗?继续排查问题,查看锁等待情况:

select * from information_schema.innodb_lock_waits;

这说明确实有事务堵住了更新。继续,

SELECT r.trx_id waiting_trx_id,

       r.trx_query waiting_query,

       b.trx_id blocking_trx_id,

       b.trx_query blocking_query,

       b.trx_mysql_thread_id blocking_thread,

       b.trx_started,

       b.trx_wait_started

FROM information_schema.innodb_lock_waits w

       INNER JOIN information_schema.innodb_trx b

               ON b.trx_id = w.blocking_trx_id

       INNER JOIN information_schema.innodb_trx r

               ON r.trx_id = w.requesting_trx_id 

从图中可以看到,blocking_query确实是select语句,靠,难道真是它上锁了,上的什么锁呢?

select * from information_schema.innodb_locks;

可以看到一个读锁和一个写锁,这说明了,查询的确是上了记录的读锁,锁应该都是在innodb层面加的。到底为啥会上读锁呢?

select trx_id,trx_state,trx_isolation_level from information_schema.innodb_trx;

答案揭晓了,可以看到RUNNING的事务隔离级别是SERIALIZABLE,串行化隔离级别导致读上锁,进而阻塞复制无法进行下去。

     这个例子其实很简单,通过这个例子可以看到,information_schema下面的几张表太重要了,暴露了很多信息,方便我们排查问题。同时排查问题时,一定要坚信原理,并且细心,问题总会水落石出。

bitsCN.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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Reduce the use of MySQL memory in Docker Reduce the use of MySQL memory in Docker Mar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How to solve the problem of mysql cannot open shared library How to solve the problem of mysql cannot open shared library Mar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin) Run MySQl in Linux (with/without podman container with phpmyadmin) Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overview What is SQLite? Comprehensive overview Mar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Running multiple MySQL versions on MacOS: A step-by-step guide Running multiple MySQL versions on MacOS: A step-by-step guide Mar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles