[MySQL] Several running monitoring commands

1. View running threads: show processlist

show processlist;

This is a very important command, used to display the user running threads. The thread can be killed according to the id number. You can also look up the table, the effect is the same:

select * from information_schema.processlist;

Insert picture description here

Column meaning
Id The only mark of the thread, you can kill the thread according to it
User The user who started this thread, ordinary users can only see their own thread
Host Which IP port initiated the connection
db Operating database
Command Thread commands https://dev.mysql.com/doc/refman/5.7/en/thread-commands.html
Time Operation duration, in seconds
State Thread state, such as query may include copyingtotmptable, Sortingresult, Sendingdata
https://dev.mysql.com/doc/refman/5.7/en/general-thread-states.html
Info The first 100 characters of the SQL statement, if you want to view the complete SQL statement, use SHOW FULL PROCESSLIST

2. Server operating status: show status

SHOW STATUS is used to view the running status of the MySQL server (it will be cleared after restart). There are two scopes: session and global, format: parameter-value. You can use like with wildcards to filter.

SHOW GLOBAL STATUS LIKE 'com_select';-- 查看 select 次数

Insert picture description here

3. Storage engine operating information: show engine

show engine is used to display the current operating information of the storage engine, including table locks and row locks held by transactions; lock waiting status of transactions; thread semaphore waiting; file IO requests; buffer pool statistics.

E.g:

show engine innodb status;

If you need to output the monitoring information to the error log (every 15 seconds), you can turn on the output.

show variables like 'innodb_status_output%'; -- 开启输出:
SET GLOBAL innodb_status_output=ON; 
SET GLOBALinnodb_status_output_locks=ON;

We now know so many commands for analyzing server status, storage engine status, and thread running information. If you were asked to write a database monitoring system, what would you do? In fact, many open source slow query log monitoring tools, their principle is actually to read the variables and status of the system.

Guess you like

Origin blog.csdn.net/weixin_43935927/article/details/114004781