一旦出现插入便缓慢或者超时严重的问题,可以采用如下的方案进行排解。
1,输入命令vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 58272 46016 93992 766284 0 2 10 43 40 119 31 0 69 0 0
主要看b参数和wa参数,b为等待资源的进程数;wa为io等待占用cpu的百分比,超过30%表示io压力过大。
2.查看线程状态
[root@TSMIS mysql]# /usr/bin/mysql test -e "show full processlist";
+----+------+-----------+------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+-----------------------+
| 45 | root | localhost | test | Sleep | 20 | | NULL |
| 46 | root | localhost | test | Sleep | 20 | | NULL |
| 47 | root | localhost | test | Sleep | 197 | | NULL |
| 48 | root | localhost | NULL | Sleep | 501 | | NULL |
| 86 | root | localhost | test | Query | 0 | NULL | show full processlist |
+----+------+-----------+------+---------+------+-------+-----------------------+
3.使用mysqlRecort
系统已经运行了14个多小时具备代表性
MySQL 5.0.77 uptime 0 14:22:56 Wed Aug 1 10:27:12 2012
__ Key _________________________________________________________________
Buffer used 177.59M of 256.00M %Used: 69.37 //索引缓存占据了70,80~88%的时候就要考虑扩大,这里可以扩大索引缓存。my.cnf 中key_buffer_size项
Current 32.97M %Usage: 12.88 //生成本次报告占用的缓存,12~13%看出状况良好
Write hit 0.00% //索引写入硬盘命中率,对于insert和update语句,0是可接受;如果是select操作,>90%才是可接受;如果是负数,表示索引总是写到磁盘不写到缓存中,是不合理的。分子是写入到硬盘的量;分母是写入到缓存的量。
Read hit 80.35% //分子为读取硬盘的量,分母是读取缓存的量,此值过低只能说明索引空间偏小,导致mysql从硬盘读取索引,开始运行mysql1~2,低于99%是正常,但是之后取值应该接近99%。
__ Questions ___________________________________________________________//表明mysql正在忙碌什么
Total 57.19k 1.1/s //这一行表明,mysql平均每秒处理1.1次请求,正常要有48~100.
DMS 90.55k 1.7/s %Total: 158.34 //数据操作语句,mysql主要工作之一, 占总操作数的118.53???错误???
-Unknown 67.78k 1.3/s 118.53 //非主要操作,理应值更小
QC Hits 22.57k 0.4/s 39.47 //查询缓存命中率,mysql主要工作之二,qc hit非常不理想(缓存命中率很低)。
Com_ 11.77k 0.2/s 20.58
COM_QUIT 80 0.0/s 0.14
Slow 10 s 1 0.0/s 0.00 %DMS: 0.00 Log: OFF //慢查询数目有多少。long_queue_time最好设置为1或者毫秒级。理想状态这个值为0
DMS 90.55k 1.7/s 158.34 //数据操作语句为最重要,这里详细列出操作了哪些内容
INSERT 56.01k 1.1/s 97.94 61.85 //insert操作较多,推荐innodb 引擎。
SELECT 34.54k 0.7/s 60.40 38.14 //如果select操作较多,推荐myisam引擎。
DELETE 3 0.0/s 0.01 0.00
UPDATE 2 0.0/s 0.00 0.00
REPLACE 0 0/s 0.00 0.00
Com_ 11.77k 0.2/s 20.58 //非主要,值理应小,
call_proced 11.46k 0.2/s 20.03 //存储过程调用,说明这台机器主要操作存储过程。
repair 68 0.0/s 0.12
set_option 65 0.0/s 0.11
__ SELECT and Sort _____________________________________________________
Scan 11.21k 0.2/s %SELECT: 32.47
Range 0 0/s 0.00
Full join 3 0.0/s 0.01
Range check 0 0/s 0.00
Full rng join 0 0/s 0.00
Sort scan 2 0.0/s
Sort range 8 0.0/s
Sort mrg pass 0 0/s
__ Query Cache _________________________________________________________
Memory usage 62.58k of 64.00M %Used: 0.10
Block Fragmnt 5.26%
Hits 22.57k 0.4/s
Inserts 11.23k 0.2/s
Insrt:Prune 11.23k:1 0.2/s
Hit:Insert 2.01:1
__ Table Locks _________________________________________________________
Waited 8 0.0/s %Total: 0.01
Immediate 79.20k 1.5/s
__ Tables ______________________________________________________________
Open 54 of 2048 %Cache: 2.64
Opened 131 0.0/s
__ Connections _________________________________________________________
Max used 16 of 1024 %Max: 1.56 //连接数使用率挺低的。
Total 89 0.0/s
__ Created Temp ________________________________________________________
Disk table 0 0/s
Table 51 0.0/s Size: 256.0M
File 37 0.0/s
__ Threads _____________________________________________________________
Running 1 of 5
Cached 11 of 128 %Hit: 82.02
Created 16 0.0/s
Slow 0 0/s
__ Aborted _____________________________________________________________
Clients 14 0.0/s
Connects 1 0.0/s
__ Bytes _______________________________________________________________
Sent 5.18M 100.1/s
Received 8.32M 160.6/s
__ InnoDB Buffer Pool __________________________________________________
Usage 304.00k of 8.00M %Used: 3.71
Read hit 84.42%
Pages
Free 493 %Total: 96.29
Data 19 3.71 %Drty: 0.00
Misc 0 0.00
Latched 0.00
Reads 77 0.0/s
From file 12 0.0/s 15.58
Ahead Rnd 1 0.0/s
Ahead Sql 0 0/s
Writes 0 0/s
Flushes 0 0/s
Wait Free 0 0/s
__ InnoDB Lock _________________________________________________________
Waits 0 0/s
Current 0
Time acquiring
Total 0 ms
Average 0 ms
Max 0 ms
__ InnoDB Data, Pages, Rows ____________________________________________
Data
Reads 25 0.0/s
Writes 3 0.0/s
fsync 3 0.0/s
Pending
Reads 0
Writes 0
fsync 0
Pages
Created 0 0/s
Read 19 0.0/s
Written 0 0/s
Rows
Deleted 0 0/s
Inserted 0 0/s
Read 0 0/s
Updated 0 0/s