当前位置:七道奇文章资讯数据防范MySQL防范
日期:2012-06-02 15:08:00  来源:本站整理

mysql show processlist 显示mysql查询进程[MySQL防范]

赞助商链接



  本文“mysql show processlist 显示mysql查询进程[MySQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
1.进入mysql/bin目录下输入mysqladmin processlist;
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防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • Windows 搭配 IIS7 PHP MySQL 环境
  • mysql Out of memory (Needed 16777224 bytes)的错误办理
  • mysql提醒[Warning] Invalid (old?) table or database name问题的办理办法
  • mysql启用skip-name-resolve情势时呈现Warning的处理办法
  • mysql启用skip-name-resolve情势时呈现Warning的处理办法
  • MySQL Order By语法介绍
  • <b>MySQL ORDER BY 的实现解析</b>
  • mysql数据库插入速度和读取速度的调整记录
  • MySQL Order By索引优化办法
  • MySQL Order By用法分享
  • mysql #1062 –Duplicate entry ''1'' for key ''PRIMARY''
  • MySQL Order By Rand()效率解析
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .