mysql show processlist 显示mysql查询进程
2.启动mysql,输入show processlist;
如果有 super 权限,则可以看到全部的线程,否则,只能看到自己发起的线程(这是指,当前对应的mysql帐户运行的线程)。
得到数据形式如下(只截取了三条):
mysql> show processlist;
+-----+-------------+--------------------+-------+---------+-------+----------------------------------+----------
| id | user | host | db | command | time| state | info
+-----+-------------+--------------------+-------+---------+-------+----------------------------------+----------
|207|root |192.168.0.20:51718 |mytest | sleep | 5 | | null
|208|root |192.168.0.20:51719 |mytest | sleep | 5 | | null
|220|root |192.168.0.20:51731 |mytest |query | 84 | locked |
select bookname,culture,value,type from book where id=001
先简单说一下各列的含义和用途,第一列,id,不用说了吧,一个标识,你要kill一个语句的时候很有用。user列,显示单前用户,如果不是root,这个命令就只显示你权限范围内的sql语句。host列,显示这个语句是从哪个ip的哪个端口上发出的。呵呵,可以用来追踪出问题语句的用户。db列,显示这个进程目前连接的是哪个数据库。command列,显示当前连接的执行的命令,一般就是休眠(sleep),查询(query),连接(connect)。time列,此这个状态持续的时间,单位是秒。state列,显示使用当前连接的sql语句的状态,很重要的列,后续会有所有的状态的描述,请注意,state只是语句执行中的某一个状态,一个sql语句,已查询为例,可能需要经过copying to tmp table,sorting result,sending data等状态才可以完成,info列,显示这个sql语句
如果你在一个容量大的表中执行增删改字段或执行一个复杂的sql 查询导致mysql线程挂起.可用此命令查看出是哪些sql挂起,用kill命令把他k掉
kill命令使用方法
kill pid
如上例中我们想kill掉id为207的线程则执行
kill 207即可.
mysql show processlist命令 详解
show processlist显示哪些线程正在运行。您也可以使用mysqladmin processlist语句得到此信息。如果您有super权限,您可以看到所有线程。否则,您只能看到您自己的线程(也就是,与您正在使用的mysql账户相关的线程)。请参见13.5.5.3节,“kill语法”。如果您不使用full关键词,则只显示每个查询的前100个字符。
本语句报告tcp/ip连接的主机名称(采用host_name:client_port格式),以方便地判定哪个客户端正在做什么。
如果您得到“too many connections”错误信息,并且想要了解正在发生的情况,本语句是非常有用的。mysql保留一个额外的连接,让拥有super权限的 账户使用,以确保管理员能够随时连接和检查系统(假设您没有把此权限给予所有的用户)。
这个命令中最关键的就是state列,mysql列出的状态主要有以下几种:
checking table
正在检查数据表(这是自动的)。
closing tables
正在将表中修改的数据刷新到磁盘中,同时正在关闭已经用完的表。这是一个很快的操作,如果不是这样的话,就应该确认磁盘空间是否已经满了或者磁盘是否正处于重负中。
connect out
复制从服务器正在连接主服务器。
copying to tmp table on disk
由于临时结果集大于tmp_table_size,正在将临时表从内存存储转为磁盘存储以此节省内存。
creating tmp table
正在创建临时表以存放部分查询结果。
deleting from main table
服务器正在执行多表删除中的第一部分,刚删除第一个表。
deleting from reference tables
服务器正在执行多表删除中的第二部分,正在删除其他表的记录。
flushing tables
正在执行flush tables,等待其他线程关闭数据表。
killed
发送了一个kill请求给某线程,那么这个线程将会检查kill标志位,同时会放弃下一个kill请求。mysql会在每次的主循环中检查kill标志位,不过有些情况下该线程可能会过一小段才能死掉。如果该线程程被其他线程锁住了,那么kill请求会在锁释放时马上生效。
locked
被其他查询锁住了。
sending data
正在处理select查询的记录,同时正在把结果发送给客户端。
sorting for group
正在为group by做排序。
sorting for order
正在为order by做排序。
opening tables
这个过程应该会很快,除非受到其他因素的干扰。例如,在执alter table或lock table语句行完以前,数据表无法被其他线程打开。正尝试打开一个表。
removing duplicates
正在执行一个select distinct方式的查询,但是mysql无法在前一个阶段优化掉那些重复的记录。因此,mysql需要再次去掉重复的记录,然后再把结果发送给客户端。
reopen table
获得了对一个表的锁,但是必须在表结构修改之后才能获得这个锁。已经释放锁,关闭数据表,正尝试重新打开数据表。
repair by sorting
修复指令正在排序以创建索引。
repair with keycache
修复指令正在利用索引缓存一个一个地创建新索引。它会比repair by sorting慢些。
searching rows for update
正在讲符合条件的记录找出来以备更新。它必须在update要修改相关的记录之前就完成了。
sleeping
正在等待客户端发送新请求.
system lock
正在等待取得一个外部的系统锁。如果当前没有运行多个mysqld服务器同时请求同一个表,那么可以通过增加--skip-external-locking参数来禁止外部系统锁。
upgrading lock
insert delayed正在尝试取得一个锁表以插入新记录。
updating
正在搜索匹配的记录,并且修改它们。
user lock
正在等待get_lock()。
waiting for tables
该线程得到通知,数据表结构已经被修改了,需要重新打开数据表以取得新的结构。然后,为了能的重新打开数据表,必须等到所有其他线程关闭这个表。以下几种情况下会产生这个通知:flush tables tbl_name, alter table, rename table, repair table, analyze table,或optimize table。
waiting for handler insert
insert delayed已经处理完了所有待处理的插入操作,正在等待新的请求。
大部分状态对应很快的操作,只要有一个线程保持同一个状态好几秒钟,那么可能是有问题发生了,需要检查一下。
还有其他的状态没在上面中列出来,不过它们大部分只是在查看服务器是否有存在错误是才用得着。
mysql 查看当前连接数
命令: show processlist;
如果是root帐号,你能看到所有用户的当前连接。如果是其它普通帐号,只能看到自己占用的连接。
show processlist;只列出前100条,如果想全列出请使用show full processlist;
mysql> show processlist;
命令: show status;
aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量。
aborted_connects 尝试已经失败的mysql服务器的连接的次数。
connections 试图连接mysql服务器的次数。
created_tmp_tables 当执行语句时,已经被创造了的隐含临时表的数量。
delayed_insert_threads 正在使用的延迟插入处理器线程的数量。
delayed_writes 用insert delayed写入的行数。
delayed_errors 用insert delayed写入的发生某些错误(可能重复键值)的行数。
flush_commands 执行flush命令的次数。
handler_delete 请求从一张表中删除行的次数。
handler_read_first 请求读入表中第一行的次数。
handler_read_key 请求数字基于键读行。
handler_read_next 请求读入基于一个键的一行的次数。
handler_read_rnd 请求读入基于一个固定位置的一行的次数。
handler_update 请求更新表中一行的次数。
handler_write 请求向表中插入一行的次数。
key_blocks_used 用于关键字缓存的块的数量。
key_read_requests 请求从缓存读入一个键值的次数。
key_reads 从磁盘物理读入一个键值的次数。
key_write_requests 请求将一个关键字块写入缓存次数。
key_writes 将一个键值块物理写入磁盘的次数。
max_used_connections 同时使用的连接的最大数目。
not_flushed_key_blocks 在键缓存中已经改变但是还没被清空到磁盘上的键块。
not_flushed_delayed_rows 在insert delay队列中等待写入的行的数量。
open_tables 打开表的数量。
open_files 打开文件的数量。
open_streams 打开流的数量(主要用于日志记载)
opened_tables 已经打开的表的数量。
questions 发往服务器的查询的数量。
slow_queries 要花超过long_query_time时间的查询数量。
threads_connected 当前打开的连接的数量。
threads_running 不在睡眠的线程数量。
uptime 服务器工作了多少秒。
after create
this occurs when the thread creates a table (including internal temporary tables), at the end of the function that creates the table. this state is used even if the table could not be created due to some error.
analyzing
the thread is calculating a myisam table key distributions (for example, for analyze table).
checking permissions
the thread is checking whether the server has the required privileges to execute the statement.
checking table
the thread is performing a table check operation.
cleaning up
the thread has processed one command and is preparing to free memory and reset certain state variables.
closing tables
the thread is flushing the changed table data to disk and closing the used tables. this should be a fast operation. if not, you should verify that you do not have a full disk and that the disk is not in very heavy use.
converting heap to myisam
the thread is converting an internal temporary table from a memory table to an on-disk myisam table.
copy to tmp table
the thread is processing an alter table statement. this state occurs after the table with the new structure has been created but before rows are copied into it.
copying to group table
if a statement has different order by and group by criteria, the rows are sorted by group and copied to a temporary table.
copying to tmp table
the server is copying to a temporary table in memory.
copying to tmp table on disk
the server is copying to a temporary table on disk. the temporary result set was larger than tmp_table_size and the thread is changing the temporary table from in-memory to disk-based format to save memory.
creating index
the thread is processing alter table ... enable keys for a myisam table.
creating sort index
the thread is processing a select that is resolved using an internal temporary table.
creating table
the thread is creating a table. this includes creation of temporary tables.
creating tmp table
the thread is creating a temporary table in memory or on disk. if the table is created in memory but later is converted to an on-disk table, the state during that operation will be copying to tmp table on disk.
deleting from main table
the server is executing the first part of a multiple-table delete. it is deleting only from the first table, and saving columns and offsets to be used for deleting from the other (reference) tables.
deleting from reference tables
the server is executing the second part of a multiple-table delete and deleting the matched rows from the other tables.
discard_or_import_tablespace
the thread is processing an alter table ... discard tablespace or alter table ... import tablespace statement.
end
this occurs at the end but before the cleanup of alter table, create view, delete, insert, select, or update statements.
executing
the thread has begun executing a statement.
execution of init_command
the thread is executing statements in the value of the init_command system variable.
freeing items
the thread has executed a command. this state is usually followed by cleaning up.
flushing tables
the thread is executing flush tables and is waiting for all threads to close their tables.
fulltext initialization
the server is preparing to perform a natural-language full-text search.
init
this occurs before the initialization of alter table, delete, insert, select, or update statements.
killed
someone has sent a kill statement to the thread and it should abort next time it checks the kill flag. the flag is checked in each major loop in mysql, but in some cases it might still take a short time for the thread to die. if the thread is locked by some other thread, the kill takes effect as soon as the other thread releases its lock.
locked
the query is locked by another query.
logging slow query
the thread is writing a statement to the slow-query log.
null
this state is used for the show processlist state.
login
the initial state for a connection thread until the client has been authenticated successfully.
opening tables, opening table
the thread is trying to open a table. this is should be very fast procedure, unless something prevents opening. for example, an alter table or a lock table statement can prevent opening a table until the statement is finished.
preparing
this state occurs during query optimization.
purging old relay logs
the thread is removing unneeded relay log files.
query end
this state occurs after processing a query but before the freeing items state.
reading from net
the server is reading a packet from the network.
removing duplicates
the query was using select distinct in such a way that mysql could not optimize away the distinct operation at an early stage. because of this, mysql requires an extra stage to remove all duplicated rows before sending the result to the client.
removing tmp table
the thread is removing an internal temporary table after processing a select statement. this state is not used if no temporary table was created.
rename
the thread is renaming a table.
rename result table
the thread is processing an alter table statement, has created the new table, and is renaming it to replace the original table.
reopen tables
the thread got a lock for the table, but noticed after getting the lock that the underlying table structure changed. it has freed the lock, closed the table, and is trying to reopen it.
repair by sorting
the repair code is using a sort to create indexes.
repair done
the thread has completed a multi-threaded repair for a myisam table.
repair with keycache
the repair code is using creating keys one by one through the key cache. this is much slower than repair by sorting.
rolling back
the thread is rolling back a transaction.
saving state
for myisam table operations such as repair or analysis, the thread is saving the new table state to the .myi file header. state includes information such as number of rows, the auto_increment counter, and key distributions.
searching rows for update
the thread is doing a first phase to find all matching rows before updating them. this has to be done if the update is changing the index that is used to find the involved rows.
sending data
the thread is processing rows for a select statement and also is sending data to the client.
setup
the thread is beginning an alter table operation.
sorting for group
the thread is doing a sort to satisfy a group by.
sorting for order
the thread is doing a sort to satisfy a order by.
sorting index
the thread is sorting index pages for more efficient access during a myisam table optimization operation.
sorting result
for a select statement, this is similar to creating sort index, but for nontemporary tables.
statistics
the server is calculating statistics to develop a query execution plan.
system lock
the thread is going to request or is waiting for an internal or external system lock for the table. if this state is being caused by requests for external locks and you are not using multiple mysqld servers that are accessing the same tables, you can disable external system locks with the --skip-external-locking option. however, external locking is disabled by default, so it is likely that this option will have no effect. for show profile, this state means the thread is requesting the lock (not waiting for it).
table lock
the next thread state after system lock. the thread has acquired an external lock and is going to request an internal table lock.
updating
the thread is searching for rows to update and is updating them.
updating main table
the server is executing the first part of a multiple-table update. it is updating only the first table, and saving columns and offsets to be used for updating the other (reference) tables.
updating reference tables
the server is executing the second part of a multiple-table update and updating the matched rows from the other tables.
user lock
the thread is going to request or is waiting for an advisory lock requested with a get_lock() call. for show profile, this state means the thread is requesting the lock (not waiting for it).
waiting for tables, waiting for table
the thread got a notification that the underlying structure for a table has changed and it needs to reopen the table to get the new structure. however, to reopen the table, it must wait until all other threads have closed the table in question.
this notification takes place if another thread has used flush tables or one of the following statements on the table in question: flush tables tbl_name, alter table, rename table, repair table, analyze table, or optimize table.
waiting on cond
a generic state in which the thread is waiting for a condition to become true. no specific state information is available.
writing to net
the server is writing a packet to the network.
推荐阅读
-
mysql show processlist 显示mysql查询进程
-
mysql show processlist 显示mysql查询进程
-
MySQL查询in操作 查询结果按in集合顺序显示
-
通过mysql show processlist 命令检查mysql锁的方法
-
MySQL查询in操作 查询结果按in集合顺序显示
-
通过mysql show processlist 命令检查mysql锁的方法
-
PHP连接MySQL查询结果中文显示乱码解决方法
-
WPF DataGrid显示MySQL查询信息,且可删除、修改、插入 (原发布 csdn 2018-10-13 20:07:28)
-
MySQL数据库show processlist指令使用解析
-
MySql下查询方法:show variables like '%max_allowed_packet%'介绍