.
2 rows in set (0.00 sec) 计算索引未命中的概率:
key_cache_miss_rate = key_reads / key_read_requests * 100% 达到0.1%以下(即每1000个请求有一个直接读硬盘)以下都很好,如果
key_cache_miss_rae在0.01%以下的话,则说明key_buffer_size分配得过多,可以适当减少。
Key_blocks_unused表示未使用的缓存簇数,Key_blocks_used表示曾经用到的最大的blocks数,比如这台服务器,所有的缓存都用到了,要么增加key_buffer_size,要么就是过度索引,把缓存占满了。比较理想的设置是:
key_blocks_used / ( key_blocks_unused + key_blocks_used ) * 100 % = 80%
mysql> show global status like 'key_blocks_u%'; +-------------------+--------+ | Variable_name | Value | +-------------------+--------+ | Key_blocks_unused | 317003 | | Key_blocks_used | 6439 | +-------------------+--------+ 2 rows in set (0.00 sec) 临时表:
当执行语句时,关于已经被创造了的隐含临时表的数量,我们可以用如下命令查询其具体情况:
mysql> show global status like 'created_tmp%'; +-------------------------+--------+
Word专业资料
.
| Variable_name | Value | +-------------------------+--------+ | Created_tmp_disk_tables | 343326 | | Created_tmp_files | 172 | | Created_tmp_tables | 675795 | +-------------------------+--------+ 3 rows in set (0.00 sec)
每次创建临时表时,created_tmp_tables都会增加,如果是在磁盘上创建临时表,created_tmp_disk_tables也会增加。created_tem_files表示MYSQL服务创建的临时文件数,比较理想的配置是:
Created_Tmp_disk_tables / Created_tmp_tables * 100% <= 25%
比如上面服务器Created_Tmp_disk_tables / Created_tmp_tables * 100% = 50%,比较差了。
我们再看一下MYSQL服务器对临时表的配置:
mysql> show variables where Variable_name in ('tmp_table_size','max_heap_table_size');
+---------------------+----------+ | Variable_name | Value | +---------------------+----------+ | max_heap_table_size | 16777216 | | tmp_table_size | 16777216 | +---------------------+----------+ 2 rows in set (0.00 sec)
只有16M以下的临时表才能全部放在内存中,超过的就会用到硬盘临时表。
打开表的情况
Word专业资料
.
Open_tables表示打开表的数量,Opend_tables表示打开过的表数量,我们可以用如下命令查看其具体情况:
mysql> show global status like 'open%tables%'; +---------------+--------+ | Variable_name | Value | +---------------+--------+ | Open_tables | 512 | | Opened_tables | 234200 | +---------------+--------+ 2 rows in set (0.00 sec)
如果Opened_tables数量过大,说明配置中tables_caceh(MYSQL 5.1.3 之后这个值叫做table_open_cache)的值可能太小。我们查询一下服务器table_cache值: mysql> show variables like 'table_open_cache'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | table_open_cache | 614 | +------------------+-------+ 1 row in set (0.00 sec) 比较合适的值为:
Open_tables / Opened_tables * 100% >= 85% Open_tables / table_open_cache * 100% <= 95%
进程使用情况
如果我们在MYSQL服务器的配置文件中设置了thread-cache_size,当客户端断开之时,服务器处理此客户请求的线程将会缓存起来以响应下一个客户而不是销毁(前提是缓存数未达上限)。Threads_created表示创建过的线程数,我们可以用如下命令查看:
Word专业资料
.
mysql> show global status like 'Thread%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 7 | | Threads_connected | 2 | | Threads_created | 2124 | | Threads_running | 2 | +-------------------+-------+ 4 rows in set (0.00 sec)
如果发现Threads_created的值过大的话,表明MYSQL服务器一直在创建线程,这也是比较耗费资源的,可以适当增大配置文件中的thread_cache_size的值。查询服务器thread_cahce_size配置,如下所示:
mysql> show variables like 'thread_cache_size'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | thread_cache_size | 8 | +-------------------+-------+ 1 row in set (0.00 sec) 查询缓存
它涉及的主要有两个参数,query_cache_size是设置MYSQL的Query_Cache大小,query_cache_size是设置使用查询缓存的类型,我们可以用如下命令查看其具体情况: mysql> show global status like 'qcache%'; +-------------------------+----------+ | Variable_name | Value | +-------------------------+----------+
Word专业资料
.
| Qcache_free_blocks | 130 | | Qcache_free_memory | 31557680 | | Qcache_hits | 15838885 | | Qcache_inserts | 2391041 | | Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 671718 | | Qcache_queries_in_cache | 676 | | Qcache_total_blocks | 1798 | +-------------------------+----------+ 8 rows in set (0.00 sec)
我们再查询一下服务器上关于query-cache的配置命令如下: mysql> show variables like 'query_cache%'; +------------------------------+----------+ | Variable_name | Value | +------------------------------+----------+ | query_cache_limit | 1048576 | | query_cache_min_res_unit | 4096 | | query_cache_size | 33554432 | | query_cache_type | ON | | query_cache_wlock_invalidate | OFF | +------------------------------+----------+ 5 rows in set (0.00 sec)
排序使用情况
它表示系统中对数据进行排序时所使用的Buffer,我们可以用如下命令查看: mysql> show global status like 'sort%'; +-------------------+-----------+
Word专业资料
Linux运维工程师工作手册



