MySQL 优化脚本(analyze)引起的应用崩溃
早上刚走进公司的门口,快走到办公桌的时候,开发的同事很着急的跟我说:你可来了!我:发生什么事情了?开发同事:XX数据库死掉了!我:特别惊讶!这个库运行的
早上刚走进公司的门口,,快走到办公桌的时候,开发的同事很着急的跟我说:你可来了!
我:SELECT.......
注意红色字体的关键字,官网的解释是:
Flushing tables
The thread is executing FLUSH TABLES and is waiting for all threads to close their tables.
也就是说线程执行刷新表操作并且等待所有的线程关闭他们占用的表。
一个超长执行时间的SQL被发现了,这个SQL大概执行了十几个小时还没有查出结果。
但是这样也不应该回引起flush tables 的问题出现。
kill 掉这个SQL线程之后,慢慢的系统恢复了正常查询的状态。
就这样粗暴的处理完成之后,就看系统各种的日志,开始查找原因,突然想到今天是周末
对呀周末!!
周末会怎样呢?
周末有一个优化脚本任务执行的!
这个优化脚本就是使用analyze去分析每张表,analyze会收集表的统计信息。
会导致mysql检测到对应的table做了修改,必须执行flush操作,close和reopen表
由此可以推断出,是因为那个执行时间超长的SQL在执行过程中,我的优化脚本任务也启动了,对SQL占用的表进行了analyze 那张表就需要被close和reopen。但是SQL写的太烂,一直没有执行完成,也就不能释放对表的占用。以至于后面的SQL就要排队等待。
只要将那个SQL给kill掉就关闭了表,然后续的SQL就重新打开了那个表,正常!
我根据推断做了一个测试,首先手工执行那个烂SQL等待了一会儿没有查出结果的迹象,在这个时候使用analyze table table_name;
show processlit 查看状态,果然如此!截图中红色框部分
实验证明了是analyze引起的问题,但不是主要的问题。
于是和开发商量需要改进SQL进行优化。搞定!
本文出自 “影子骑士” 博客,请务必保留此出处

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are two ways to implement multi-threading in Java, one is to inherit the Thread class, and the other is to implement the Runnable interface; the Thread class is defined in the java.lang package. As long as a class inherits the Thread class and overrides the run() method in this class, it can implement multi-threaded operations. However, a class can only inherit one parent class, which is a limitation of this method. Let’s look at an example: packageorg.thread.demo;classMyThreadextendsThread{privateStringname;publicMyThread(Stringname){super();this

In-depth analysis of the role and usage of the static keyword in C language. In C language, static is a very important keyword, which can be used in the definition of functions, variables and data types. Using the static keyword can change the link attributes, scope and life cycle of the object. Let’s analyze the role and usage of the static keyword in C language in detail. Static variables and functions: Variables defined using the static keyword inside a function are called static variables, which have a global life cycle

The role and examples of var keyword in PHP In PHP, the var keyword is used to declare a variable. In previous PHP versions, using the var keyword was the idiomatic way to declare member variables, but its use is no longer recommended. However, in some cases, the var keyword is still used. The var keyword is mainly used to declare a local variable, and the variable will automatically be marked as local scope. This means that the variable is only visible within the current block of code and cannot be accessed in other functions or blocks of code. Use var

Title: Is go a keyword in C language? Detailed analysis In C language, "go" is not a keyword. Keywords in C language are specified by the C standard and are used to represent specific grammatical structures or functions. They have special meanings in the compiler and cannot be used as identifiers or variable names. For example, the keyword "int" represents an integer data type, "if" represents a conditional statement, and so on. If we want to verify whether "go" is a keyword in C language, we can write a simple program to test it. Here is an example: #inc

There are 32 keywords in C language. According to the function of keywords, they can be divided into four categories: data type keywords, control statement keywords, storage type keywords and other keywords. There are 12 data type keywords, including char, double, float, int, etc.; there are 12 control statement keywords, including for, break, if, else, do, etc.; there are 4 storage type keywords, including auto, static , extern, etc.; there are 4 other keywords, including const, sizeof, etc.

In java, when it comes to threads, Thread is essential. A thread is a lighter scheduled executor than a process. Why use threads? By using threads, you can separate resource allocation and execution scheduling in operating system processes. Each thread can not only share process resources (memory address, file I/O, etc.), but can also be scheduled independently (thread is the basic unit of CPU scheduling). Note 1. Thread is the most important class for making threads, and the word itself also represents thread. 2. The Thread class implements the Runnable interface. Instance publicclassThreadDemoextendsThread{publicvoidrun(){for(inti=0

Detailed explanation of the role and usage of the extends keyword in PHP In PHP programming, extends is a very important keyword, which is used to implement class inheritance. Through the extends keyword, we can create a new class that can inherit the properties and methods of one or more existing classes. Inheritance is an important concept in object-oriented programming, which makes code reuse and extension more convenient and flexible. This article will introduce in detail the function and use of the extends keyword. extends

Use Java's Thread.start() function to start a new thread. In Java, we can use multi-threading to execute multiple tasks concurrently. Java provides the Thread class to create and manage threads. The start() function in the Thread class is used to start a new thread and execute the code in the run() method of the thread. Code example: publicclassMyThreadextendsThread{@Overr
