Home Database Mysql Tutorial MySQL artifact show full processlist

MySQL artifact show full processlist

May 09, 2020 am 11:29 AM
mysql

When synchronizing test data today, the network was suddenly disconnected. After reconnecting, I found that the table could not be opened.

You can see that the data length of the table is 112192kb, but unfortunately it cannot be opened.

If you can’t open it, prepare to delete it and try again.

Things are often not that simple. Sure enough, it couldn't be deleted, nor could truncate. Then navicat got stuck, so I logged into the database and performed the dorp operation, but it still didn't work.

It is probably a network error that caused some strange things to happen.

Then let’s take a look and see what happened.

The artifact appears.

show full processlist;

show full processlist The result returned changes in real time and is a live snapshot of the mysql link execution, so it is very useful for handling emergencies. it works.

This sql usually acts as a firefighter to solve some sudden problems.

It can check some of the current running conditions of mysql, whether there is pressure, what SQL is being executed, how much time the statement takes, whether there is any slow SQL being executed, etc.

When you find some sql that takes a long time to execute, you need to pay more attention. Kill it if necessary and solve the problem first.

The command has three execution methods:

1. This is to query directly on the command line. The \G at the end means that the query results will be printed in columns, so that each field can be printed to separate rows.

mysql> show full processlist;
+--------+------+----------------------+-------+---------+------+----------+-----------------------+
| Id     | User | Host                 | db    | Command | Time | State    | Info                  |
+--------+------+----------------------+-------+---------+------+----------+-----------------------+
| 449000 | root | 127.123.213.11:59828 | stark | Sleep   | 1270 |          | NULL                  |
| 449001 | root | 127.123.213.11:59900 | stark | Sleep   | 1241 |          | NULL                  |
| 449002 | root | 127.123.213.11:59958 | stark | Sleep   | 1216 |          | NULL                  |
| 449003 | root | 127.123.213.11:60088 | stark | Sleep   | 1159 |          | NULL                  |
| 449004 | root | 127.123.213.11:60108 | stark | Sleep   | 1151 |          | NULL                  |
| 449005 | root | 127.123.213.11:60280 | stark | Sleep   | 1076 |          | NULL                  |
| 449006 | root | 127.123.213.11:60286 | stark | Sleep   | 1074 |          | NULL                  |
| 449007 | root | 127.123.213.11:60344 | stark | Sleep   | 1052 |          | NULL                  |
| 449008 | root | 127.123.213.11:60450 | stark | Sleep   | 1005 |          | NULL                  |
| 449009 | root | 127.123.213.11:60498 | stark | Sleep   |  986 |          | NULL                  |
| 449013 | root | localhost            | NULL  | Query   |    0 | starting | show full processlist |
+--------+------+----------------------+-------+---------+------+----------+-----------------------+
11 rows in set (0.01 sec)
mysql> show full processlist\G;
*************************** 1. row ***************************
     Id: 449000
   User: root
   Host: 127.123.213.11:59828
     db: stark
Command: Sleep
   Time: 1283
  State: 
   Info: NULL
*************************** 2. row ***************************
     Id: 449001
   User: root
   Host: 127.123.213.11:59900
     db: stark
Command: Sleep
   Time: 1254
  State: 
   Info: NULL
Copy after login

2. View the snapshot by querying the tables related to the link thread

SELECT id, db, USER, HOST, command, time, state, info FROM information_schema. PROCESSLIST WHERE command != ' Sleep' ORDER BY time DESC;

3. View through [Tools] => [Server Monitoring] in navicat.

This method is more convenient and can also be sorted.

A brief introduction to the meaning of each column:

Id: The unique identifier of the link mysql server thread. You can terminate the link of this thread through kill.

User: The user of the current thread connecting to the database

Host: Displays which IP and which port this statement is issued from. Can be used to track the user who issued the problematic statement

db: The database to which the thread is connected, null if not available

Command: Displays the executed command of the current connection, usually sleep or idle (sleep) , query (query), connection (connect)

Time: The time the thread is in the current state, the unit is seconds

State: Displays the status of the sql statement using the current connection, very important Column, there will be descriptions of all states later. Please note that state is just a certain state in statement execution. A sql statement, for example, has been queried. It may need to go through copying to tmp table, Sorting result, Sending data and other states. Completion

Info: The sql statement executed by the thread, or null if no statement is executed. This statement can be an execution statement sent by the client or an internal execution statement.

How to solve the problem after discovering it?

1. You can kill the problematic lines above individually

kill 449000

2. You can also batch terminate threads that take more than 3 minutes

- - Query the threads whose execution time exceeds 3 minutes, and then splice them into a kill statement

select concat('kill ', id, ';')

from information_schema.processlist

where command != 'Sleep'

and time > 3*60

order by time desc;

Of course the problem can usually be solved at this point, but this During the show processlist process, I only saw the previous truncate and drop operations, and killed these two threads, which was of no use. . . .

Of course the above is not nonsense, this is something similar to methodology, just like in [Chinese Captain], when encountering a flight accident, first check it according to the manual, investigate the cause, and solve the problem.

Continue

Immediately afterwards, I used navicat to perform the table repair operation, and the result was Waiting for table metadata lock

When MySQL was performing some DDL operations such as alter table , if there are uncommitted transactions on the table, Waiting for table metadata lock will occur. Once metadata lock occurs, subsequent operations on the table will be blocked.

Solution:

1. View the currently uncommitted transactions from the information_schema.innodb_trx table

select trx_state, trx_started, trx_mysql_thread_id, trx_query from information_schema.innodb_trx\G

Field meaning:

trx_state: transaction status, usually RUNNING

trx_started: starting time of transaction execution, if the time is long, analyze whether the transaction is reasonable

trx_mysql_thread_id: MySQL thread ID, used for kill

trx_query: sql in the transaction

Generally, as long as these threads are killed, the DDL operation will not wait for table metadata lock.

2. Adjust the lock timeout threshold

lock_wait_timeout represents the timeout (in seconds) for obtaining the metadata lock. The allowed value range is 1 to 31536000 (1 year). The default value is 31536000.

See https://dev.mysql.com/doc/refman/5.6/en/se...

The default value is one year. . . .

Adjust it to 30 minutes

set session lock_wait_timeout = 1800;

set global lock_wait_timeout = 1800;

so that it will fail quickly when this problem occurs (failfast).

Recommended tutorials: "MySQL Tutorial" "Navicat"

The above is the detailed content of MySQL artifact show full processlist. For more information, please follow other related articles on the PHP Chinese website!

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 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)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Monitor Redis Droplet with Redis Exporter Service Monitor Redis Droplet with Redis Exporter Service Apr 10, 2025 pm 01:36 PM

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

See all articles