您的位置:首页 > 数据库 > MySQL

Mysql show global status 各项指标的含义

2013-06-19 14:17 357 查看
Aborted_clients
指出由于某种原因客户程序不能正常关闭连接而导致失败的连接的数量。如果客户不在退出之前调整mysql_close()函数,wait_timeout或interactive_timeout的限制已经被超出,或者是客户端程序在传输的过程中被关闭,则这种情况会发生。

Aborted_connects
指出试图连接到MYSQL的失败的次数。这种情况在客户尝试用错误的密码进行连接时,没有权限进行连接时,为获得连接的数据包所花费的时间超过了connect_timeout限制的秒数,或数据包中没有包含正确的信息时,都会发生。
Binlog_cache_disk_use 0
Binlog_cache_use 0
Binlog_stmt_cache_disk_use 0
Binlog_stmt_cache_use 0
Bytes_received
从客户端处已经接收到的字节数。
Bytes_sent
已经发送给所有客户端的字节数。
Com_[statement] (以下所有以Com_开始的条目)
用于每一种语句的这些变量中的一种。变量值表示这条语句被执行的次数,如com_select,表示select查询语句被执行的次数。
可以适当的对一些敏感数据,进行下面某些操作的监控。比如删除语句(delete /drop)。
Com_admin_commands

Com_assign_to_keycache

Com_alter_db

Com_alter_db_upgrade
Com_alter_event

Com_alter_function

Com_alter_procedure

Com_alter_server

Com_alter_table

Com_alter_tablespace

Com_analyze

Com_begin

Com_binlog

Com_call_procedure

Com_change_db

Com_change_master

Com_check

Com_checksum

Com_commit

Com_create_db

Com_create_event

Com_create_function

Com_create_index

Com_create_procedure

Com_create_server

Com_create_table

Com_create_trigger

Com_create_udf

Com_create_user

Com_create_view

Com_dealloc_sql

Com_delete

Com_delete_multi

Com_do

Com_drop_db

Com_drop_event

Com_drop_function

Com_drop_index

Com_drop_procedure

Com_drop_server

Com_drop_table

Com_drop_trigger

Com_drop_user

Com_drop_view

Com_empty_query

Com_execute_sql

Com_flush

Com_grant

Com_ha_close

Com_ha_open

Com_ha_read

Com_help

Com_insert

Com_insert_select

Com_install_plugin

Com_kill

Com_load

Com_lock_tables

Com_optimize

Com_preload_keys

Com_prepare_sql

Com_purge

Com_purge_before_date

Com_release_savepoint

Com_rename_table

Com_rename_user

Com_repair

Com_replace

Com_replace_select

Com_reset

Com_resignal

Com_revoke

Com_revoke_all

Com_rollback

Com_rollback_to_savepoint

Com_savepoint

Com_select 68
Com_set_option 68
Com_signal

Com_show_authors

Com_show_binlog_events

Com_show_binlogs

Com_show_charsets

Com_show_collations

Com_show_contributors

Com_show_create_db

Com_show_create_event

Com_show_create_func

Com_show_create_proc

Com_show_create_table

Com_show_create_trigger

Com_show_databases

Com_show_engine_logs

Com_show_engine_mutex

Com_show_engine_status

Com_show_events

Com_show_errors

Com_show_fields

Com_show_function_status

Com_show_grants

Com_show_keys

Com_show_master_status

Com_show_open_tables

Com_show_plugins

Com_show_privileges

Com_show_procedure_status

Com_show_processlist

Com_show_profile

Com_show_profiles

Com_show_relaylog_events

Com_show_slave_hosts

Com_show_slave_status

Com_show_status
Com_show_storage_engines

Com_show_table_status

Com_show_tables

Com_show_triggers

Com_show_variables

Com_show_warnings

Com_slave_start

Com_slave_stop

Com_stmt_close

Com_stmt_execute

Com_stmt_fetch

Com_stmt_prepare

Com_stmt_reprepare

Com_stmt_reset

Com_stmt_send_long_data

Com_truncate

Com_uninstall_plugin

Com_unlock_tables

Com_update

Com_update_multi

Com_xa_commit

Com_xa_end

Com_xa_prepare

Com_xa_recover

Com_xa_rollback

Com_xa_start


Compression OFF
Connections
试图连接到MYSQL服务器的次数。
Created_tmp_disk_tables
执行语句时,”磁盘上“生成的隐含临时表的数量
Created_tmp_files
由mysqld生成的临时文件的数量
Created_tmp_tables
执行语句时,”内存中“生成的隐含临时表的数量
Delayed_errors
当发生错误时,由INSERT DELAYED语句写入的记录的。绝大多数普通的错误是复制键
Delayed_insert_threads
当前正在使用的延迟插入句柄的线程数量
Delayed_writes
由INSERT DELAYED语句写入的记录的个数。
Flush_commands
被执行的FLUSH语句的个数
Handler_commit
内部COMMIT命令的个数
Handler_delete
从一个表中删除行的次数
Handler_discover 0
Handler_prepare 0
Handler_read_first
一条索引中的第一个条目被读取的次数,通常是指完全索引扫描(例如,假定indexed_col被索引,语句SELECT
indexed_col from tablename导致了一个完全索引扫描)
Handler_read_key
当读取一行数据时,使用索引的请求的个数。如果查询时使用了索引,就希望这个值快速增加
Handler_read_last 0
Handler_read_next
按照索引顺序读取下一行数据的请求的个数。如果使用了完全索引进行扫描,或者在一个不变的范围内查询一个索引,则这个值就会增加
Handler_read_prev
按照索引的顺序读取前面一行数据的请求的个数。这个变量值由SELECT fieldlist ORDER BY fields DESC类型的语句使用
Handler_read_rnd 0
Handler_read_rnd_next 9892
Handler_rollback 0
Handler_savepoint 0
Handler_savepoint_rollback 0
Handler_update 0
Handler_write 9780
Innodb_buffer_pool_pages_data 149
Innodb_buffer_pool_pages_dirty 0
Innodb_buffer_pool_pages_flushed 0
Innodb_buffer_pool_pages_free 6379
Innodb_buffer_pool_pages_misc 0
Innodb_buffer_pool_pages_total 6528
Innodb_buffer_pool_read_ahead_rnd 0
Innodb_buffer_pool_read_ahead 0
Innodb_buffer_pool_read_ahead_evicted 0
Innodb_buffer_pool_read_requests 482
Innodb_buffer_pool_reads 150
Innodb_buffer_pool_wait_free 0
Innodb_buffer_pool_write_requests 0
Innodb_data_fsyncs 3
Innodb_data_pending_fsyncs 0
Innodb_data_pending_reads 0
Innodb_data_pending_writes 0
Innodb_data_read 4640768
Innodb_data_reads 160
Innodb_data_writes 3
Innodb_data_written 1536
Innodb_dblwr_pages_written 0
Innodb_dblwr_writes 0
Innodb_have_atomic_builtins ON
Innodb_log_waits 0
Innodb_log_write_requests 0
Innodb_log_writes 1
Innodb_os_log_fsyncs 3
Innodb_os_log_pending_fsyncs 0
Innodb_os_log_pending_writes 0
Innodb_os_log_written 512
Innodb_page_size 16384
Innodb_pages_created 0
Innodb_pages_read 149
Innodb_pages_written 0
Innodb_row_lock_current_waits 0
Innodb_row_lock_time 0
Innodb_row_lock_time_avg 0
Innodb_row_lock_time_max 0
Innodb_row_lock_waits 0
Innodb_rows_deleted 0
Innodb_rows_inserted 0
Innodb_rows_read 0
Innodb_rows_updated 0
Innodb_truncated_status_writes 0
Key_blocks_not_flushed 0
Key_blocks_unused 44216
Key_blocks_used 0
Key_read_requests

读取索引的请求次数.
Key_reads
从磁盘读取索引的请求次数。

那么缓存的未命中率为:
key_cache_miss_rate
= Key_reads / Key_read_requests * 100% =0.27%

针对命中率比较低的情况,我们可以加大 key_buffer_size
,即缓存的大小(单位为byte,除以(1024*1024)
得到单位M)。
mysql> show variables like 'key_buffer_size';

+-----------------+----------+

| Variable_name | Value |

+-----------------+----------+

| key_buffer_size | 67108864 |

+-----------------+----------+

通常人们认为Key_read_requests / Key_reads越大越好,否则就应该增大key_buffer_size的设置,但通过计数器的比例来调优有两个问题:
虽说Key_read_requests大比小好,但是对于系统调优而言,更有意义的应该是单位时间内的Key_reads:
Key_reads / Uptime



Key_write_requests 0
Key_writes

向硬盘写入键的数据块的物理写操作的次数。



Last_query_cost
它对应的值是一个浮点数。其默认值为0表示没有查询(query)被编译。它的含义是:查询优化器计算出来的,最后一个被编译的查询的消耗。值越大,消耗越大。这个值对于比较同一个查询语句在不同的查询状况下的消耗很有用。

Max_used_connections
响应了多少次连接。已经建立的连接的总数。当这个连接过多的时候,似乎可以作为一个警告。

查询max_connections变量可以知道,当前被设置的所允许的最大连接数(允许同时存在多少个连接)。下面是500个。
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 500 |
+-----------------+-------+
max_used_connections / max_connections * 100% = 99.6%
(理想值 ≈ 85%)

Not_flushed_delayed_rows 0
Open_files 0
Open_streams 0
Open_table_definitions 33
Open_tables
表示当前打开的表缓存数,如果执行flush tables操作,则此系统会关闭一些当前没有使用的表缓存而使得此状态值减小.

Opened_files 77
Opened_table_definitions 33
Opened_tables
表示曾经打开的表缓存数,会一直进行累加,如果执行flush tables操作,值不会减小。
在mysql默认安装情况下,table_cache的值在2G内存以下的机器中的值默认时256到512,如果机器有4G内存,则默认这个值是2048,但这决意味着机器内存越大,这个值应该越大,因为table_cache加大后,使得mysql对SQL响应的速度更快了,不可避免的会产生更多的死锁(dead
lock),这样反而使得数据库整个一套操作慢了下来,严重影响性能。所以平时维护中还是要根据库的实际情况去作出判断,找到最适合你维护的库的table_cache值。

关于Performance_schema
的含义:
MySQL 5.5新增一个存储引擎:命名PERFORMANCE_SCHEMA
,主要用于收集数据库服务器性能参数。MySQL用户是不能创建存储引擎为PERFORMANCE_SCHEMA的表
performance_schema提供以下功能:
提供进程等待的详细信息,包括锁、互斥变量、文件信息;
保存历史的事件汇总信息,为提供MySQL服务器性能做出详细的判断;
对于新增和删除监控事件点都非常容易,并可以随意改变mysql服务器的监控周期,例如(CYCLE、MICROSECOND)

MySql 系统相关的表:
mysql> show tables ;
+----------------------------------------------+
| Tables_in_performance_schema |
+----------------------------------------------+
| cond_instances |
| events_waits_current |
| events_waits_history |
| events_waits_history_long |
| events_waits_summary_by_instance |
| events_waits_summary_by_thread_by_event_name |
| events_waits_summary_global_by_event_name |
| file_instances |
| file_summary_by_event_name |
| file_summary_by_instance |
| mutex_instances |
| performance_timers |
| rwlock_instances |
| setup_consumers |
| setup_instruments |
| setup_timers |
| threads |
+----------------------------------------------+
17 rows in set (0.00 sec)

Performance的开启很简单,在my.cnf中[mysqld]加入performanc_schema,检查性能数据库是否启动的命令:
SHOW VARIABLES LIKE ‘performance_schema’;
(类似SHOW STATUS LIKE 'perf%';)
若是返回的值为ON,则说明性能数据库正常开启状态。

而如下命令
mysql> SHOW VARIABLES LIKE 'perf%';
查询结果就是涉及到performance_schema的各个系统参数了。

mysql> SELECT * FROM threads;
threads这个表记录了系统里当前存在的各种线程。

mysql> SELECT * FROM performance_timers;
performance_timers这个表式只读表,记录了事件采样频率的设定

以 Performance_schema_
开头的项目:


Performance_schema_
xxx
_classes_lost
表示多少
instruments of type
xxx

不能被加载。

Performance_schema_
xxx
_instances_lost

表示多少对象实例
xxx
不能被创建(没有被成功创建,由于内存偏少等条件没达到)。.

Performance_schema_
xxx
_handles_lost
表示多少对象实例
xxx
没有被成功打开。
Performance_schema_locker_lost
表示多少
events 丢失,或者说没有被记录到。



Performance_schema_cond_classes_lost
Performance_schema_cond_instances_lost

Performance_schema_file_classes_lost
Performance_schema_file_handles_lost

Performance_schema_file_instances_lost

Performance_schema_locker_lost

Performance_schema_mutex_classes_lost

Performance_schema_mutex_instances_lost

Performance_schema_rwlock_classes_lost

Performance_schema_rwlock_instances_lost

Performance_schema_table_handles_lost

Performance_schema_table_instances_lost

Performance_schema_thread_classes_lost

Performance_schema_thread_instances_lost



Prepared_stmt_count
当前的预处理语句的数量。 (最大数为系统变量:
max_prepared_stmt_count)
Qcache_free_blocks

查询缓存(query cache)中可以使用的空闲的内存块
Qcache_free_memory

查询缓存(query cache)可以使用的空闲的内存数。

Qcache_hits

查询缓存的命中数。
Qcache_inserts
被添加到查询缓存当中的查询的总数。

Qcache_lowmem_prunes

由于内存太少而从查询缓存里删除的查询的总数。
Qcache_not_cached
没有缓存的查询数量。包括不可缓存的,和由于
query_cache_type
的设置二不能缓存的。

Qcache_queries_in_cache

注册在查询缓存里的查询数量。

Qcache_total_blocks

在查询缓存中块的总数。
Queries
服务器执行语句的数量。这个变量包含了执行的语句,包括存储过程。它不统计:
COM_PING

COM_STATISTICS
两个命令。这个变量是在
MySQL 5.1.31
在版本中被加入的。

Questions
服务器已经执行的语句的数量。它跟 Queries不一样。这个变量不统计以下命令:
COM_PING
,
COM_STATISTICS
,
COM_STMT_PREPARE
,
COM_STMT_CLOSE
,
COM_STMT_RESET


Rpl_status
可能的值:AUTH_MASTER
。表示fail-safe复制状态(尚未实现)。这个变量并不再使用,并且 MySQL
5.6 中已经去掉了。
Select_full_join
没有使用索引的联接的数量。如果该值不为0,你应仔细检查表的索引


Select_full_range_join
在引用的表中使用范围搜索的联接的数量



Select_range
在第一个表中使用范围的联接(join)的数量。一般情况不是关键问题,即使该值相当大。


Select_range_check
在每一行数据后对键值进行检查的不带键值的联接(JOIN)的数量。如果不为0,你应仔细检查表的索引。


Select_scan
对第一个表进行全扫描连接的次数。
Slave_heartbeat_period
Slave的心跳骤起。

Slave_open_temp_tables
Slave SQL县城当前打开的临时表的数量。如果这个值大于0,那么关掉SL***E是不安全的。
Slave_received_heartbeats
Slave接受到的心跳数。
Slave_retried_transactions
自从启动以来,SL***E的SQL线程重试事务的总数。
Slave_running
可能的值为(OFF/ON)。如果该服务器是连接到MASTER的SL***E,那么,就是ON。否则就是OFF。

Slow_launch_threads

记录慢查询开启的线程数
慢查询的定义与设置:
如果
mysql> show variables like '%slow%';

这条语句查询出来的 log_slow_queries
为 OFF,那么慢查询优化是被关闭的。
打开这一项方便针对慢查询的优化。
那么多久没断定为慢查询呢?这个时间是由slow_launch_time的值来决定的。
下面它的值是2,所以,如果一个查询耗时2秒还没有完成,那就算是慢查询。
+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| log_slow_queries | OFF |

| slow_launch_time | 2 |

+------------------+-------+


Slow_queries

慢查询的次数。慢查询字数过多,应该警告。慢查询即:查询时间超过long_query_time秒(默认值是10秒)的查询的个数

Sort_merge_passes
排序算法已经执行的合并的数量。如果这个变量值较大,应考虑增加sort_buffer_size系统变量的值。


Sort_range
在范围内执行的排序的数量。


Sort_rows
已经排序的行数。


Sort_scan
通过扫描表完成的排序的数量。


Ssl_accept_renegotiates
需要建立连接,而进行的协商次数。
Ssl_accepts
已接受的SSL连接的数量。

Ssl_callback_cache_hits
SSL回调缓存命中的次数。
Ssl_cipher
当前的密码(
对于无SSL的连接是空的)
Ssl_cipher_list
当前可能的SSL密码列表(其值是字符串)。
Ssl_client_connects
SSL尝试连接到 SSL-enabled
主设备的次数。
Ssl_connect_renegotiates
建立到SSL-enable
主设备的连接的协商次数。

Ssl_ctx_verify_depth
SSL的内容认证深度(在链中认证被测试的次数)。
Ssl_ctx_verify_mode
SSL内容认证模式。
Ssl_default_timeout
默认是SSL超时。
Ssl_finished_accepts
成功连接到服务器的SSL连接次数。
Ssl_finished_connects
SSL成功连接(作为从设备)到开启SSL的主设备。
Ssl_session_cache_hits
SSL会还缓存的命中数。
Ssl_session_cache_misses
SSL缓存漏掉的数量(就是缓存中没有命中的次数)。
Ssl_session_cache_mode

SSL会话的缓存模式(一般是NONE)。
Ssl_session_cache_overflows
SSL会话的缓存溢出数量。
Ssl_session_cache_size
SSL会话的缓存大小。
Ssl_session_cache_timeouts
SSL会话缓存的超时时间。
Ssl_sessions_reused
来自缓存被重复使用的SSL连接。
Ssl_used_session_cache_entries
被用到的SSL session cache entries
的数量。
Ssl_verify_depth
SSL连接的认证深度。
Ssl_verify_mode
回应SSL连接的认证模式。
Ssl_version
SSL协议的版本号。
Table_locks_immediate 36
Table_locks_waited 0
Tc_log_max_pages_used 0
Tc_log_page_size 0
Tc_log_page_waits 0

Threads_cached
线程缓存内的线程的数量。

连接线程是 MySQL
为了提高创建连接线程的效率,将部分空闲的连接线程保持在一个缓存区以备新进连接请求的时候使用,这尤其对那些使用短连接的应用程序来说可以极大的提高创建连接的效率。当我们通过 thread_cache_size
设置了连接线程缓存池可以缓存的连接线程的大小之后,可以通过show status查询出来的结果计算(Connections
– Threads_created) / Connections * 100% 得出连接线程缓存的命中率。注意,这里设置的是可以缓存的连接线程的数目,而不是内存空间的大小。



Threads_connected

当前打开的连接的数量。


Threads_created
创建用来处理连接的线程数。如果Threads_created较大,你可能要增加thread_cache_size值。缓存访问率的计算方法Threads_created/Connections。

Threads_running
激活的(非睡眠状态)线程数(线程是MYSQL根据查询的需要创建的,总数肯定不超过Threads_created的值)。


Uptime
服务器已经运行的时间(以秒为单位)。【监控点】


Uptime_since_flush_status
最近一次使用FLUSH STATUS
的时间(使用的时候,到现在有多久)(以秒为单位)。







总格310个项目。

参考URL;http://www.51testing.com/?uid-110296-action-viewspace-itemid-69547



http://www.blogjava.net/redcoatjk/archive/2012/09/05/387100.html








================参考信息==============





1, 查看MySQL服务器配置信息

输入命令

mysql> show variables;

mysql> show variables;

2, 查看MySQL服务器运行的各种状态值

输入命令

mysql> show global status;

mysql> show global status;

3, 慢查询

输入命令

mysql> show variables like '%slow%';

+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| log_slow_queries | OFF |

| slow_launch_time | 2 |

+------------------+-------+

mysql> show global status like '%slow%';

+---------------------+-------+

| Variable_name | Value |

+---------------------+-------+

| Slow_launch_threads | 0 |

| Slow_queries | 279 |

+---------------------+-------+

mysql> show variables like '%slow%';

+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| log_slow_queries | OFF |

| slow_launch_time | 2 |

+------------------+-------+

mysql> show global status like '%slow%';

+---------------------+-------+

| Variable_name | Value |

+---------------------+-------+

| Slow_launch_threads | 0 |

| Slow_queries | 279 |

+---------------------+-------+

配置中关闭了记录慢查询(最好是打开,方便优化),超过2秒即为慢查询,一共有279条慢查询

4, 连接数

输入命令

mysql> show variables like 'max_connections';

+-----------------+-------+

| Variable_name | Value |

+-----------------+-------+

| max_connections | 500 |

+-----------------+-------+



mysql> show global status like 'max_used_connections';

+----------------------+-------+

| Variable_name | Value |

+----------------------+-------+

| Max_used_connections | 498 |

+----------------------+-------+

mysql> show variables like 'max_connections';

+-----------------+-------+

| Variable_name | Value |

+-----------------+-------+

| max_connections | 500 |

+-----------------+-------+

mysql> show global status like 'max_used_connections';

+----------------------+-------+

| Variable_name | Value |

+----------------------+-------+

| Max_used_connections | 498 |

+----------------------+-------+

设置的最大连接数是500,而响应的连接数是498

max_used_connections / max_connections * 100% = 99.6% (理想值 ≈ 85%)

5, key_buffer_size

key_buffer_size是对MyISAM表性能影响最大的一个参数, 不过数据库中多为Innodb

输入命令

mysql> show variables like 'key_buffer_size';

+-----------------+----------+

| Variable_name | Value |

+-----------------+----------+

| key_buffer_size | 67108864 |

+-----------------+----------+



mysql> show global status like 'key_read%';

+-------------------+----------+

| Variable_name | Value |

+-------------------+----------+

| Key_read_requests | 25629497 |

| Key_reads | 66071 |

+-------------------+----------+

一共有25629497个索引读取请求,有66071个请求在内存中没有找到直接从硬盘读取索引,计算索引未命中缓存的概率:

key_cache_miss_rate = Key_reads / Key_read_requests * 100% =0.27%

需要适当加大key_buffer_size

输入命令

mysql> show global status like 'key_blocks_u%';

+-------------------+-------+

| Variable_name | Value |

+-------------------+-------+

| Key_blocks_unused | 10285 |

| Key_blocks_used | 47705 |

+-------------------+-------+

mysql> show global status like 'key_blocks_u%';

+-------------------+-------+

| Variable_name | Value |

+-------------------+-------+

| Key_blocks_unused | 10285 |

| Key_blocks_used | 47705 |

+-------------------+-------+

Key_blocks_unused表示未使用的缓存簇(blocks)数,Key_blocks_used表示曾经用到的最大的blocks数

Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 18% (理想值 ≈ 80%)

6, 临时表

输入命令

mysql> show global status like 'created_tmp%';

+-------------------------+---------+

| Variable_name | Value |

+-------------------------+---------+

| Created_tmp_disk_tables | 4184337 |

| Created_tmp_files | 4124 |

| Created_tmp_tables | 4215028 |

+-------------------------+---------+

mysql> show global status like 'created_tmp%';

+-------------------------+---------+

| Variable_name | Value |

+-------------------------+---------+

| Created_tmp_disk_tables | 4184337 |

| Created_tmp_files | 4124 |

| Created_tmp_tables | 4215028 |

+-------------------------+---------+

每次创建临时表,Created_tmp_tables增加,如果是在磁盘上创建临时表,Created_tmp_disk_tables也增加,Created_tmp_files表示MySQL服务创建的临时文件文件数:

Created_tmp_disk_tables / Created_tmp_tables * 100% = 99% (理想值<= 25%)

输入命令

mysql> show variables where Variable_name in ('tmp_table_size', 'max_heap_table_size');

+---------------------+-----------+

| Variable_name | Value |

+---------------------+-----------+

| max_heap_table_size | 134217728 |

| tmp_table_size | 134217728 |

+---------------------+-----------+

mysql> show variables where Variable_name in ('tmp_table_size', 'max_heap_table_size');

+---------------------+-----------+

| Variable_name | Value |

+---------------------+-----------+

| max_heap_table_size | 134217728 |

| tmp_table_size | 134217728 |

+---------------------+-----------+

需要增加tmp_table_size

7,open table 的情况

输入命令

mysql> show global status like 'open%tables%';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| Open_tables | 1024 |

| Opened_tables | 1465 |

+---------------+-------+

mysql> show global status like 'open%tables%';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| Open_tables | 1024 |

| Opened_tables | 1465 |

+---------------+-------+

Open_tables 表示打开表的数量,Opened_tables表示打开过的表数量,如果Opened_tables数量过大,说明配置中 table_cache(5.1.3之后这个值叫做table_open_cache)值可能太小,我们查询一下服务器table_cache值

输入命令

mysql> show variables like 'table_cache';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| table_cache | 1024 |

+---------------+-------+

mysql> show variables like 'table_cache';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| table_cache | 1024 |

+---------------+-------+

Open_tables / Opened_tables * 100% =69% 理想值 (>= 85%)

Open_tables / table_cache * 100% = 100% 理想值 (<= 95%)

8, 进程使用情况

输入命令

mysql> show global status like 'Thread%';

+-------------------+-------+

| Variable_name | Value |

+-------------------+-------+

| Threads_cached | 31 |

| Threads_connected | 239 |

| Threads_created | 2914 |

| Threads_running | 4 |

+-------------------+-------+

mysql> show global status like 'Thread%';

+-------------------+-------+

| Variable_name | Value |

+-------------------+-------+

| Threads_cached | 31 |

| Threads_connected | 239 |

| Threads_created | 2914 |

| Threads_running | 4 |

+-------------------+-------+

如果我们在MySQL服务器配置文件中设置了thread_cache_size,当客户端断开之后,服务器处理此客户的线程将会缓存起来以响应下一个客户而不是销毁(前提是缓存数未达上限)。Threads_created表示创建过的线程数,如果发现Threads_created值过大的话,表明 MySQL服务器一直在创建线程,这也是比较耗资源,可以适当增加配置文件中thread_cache_size值,查询服务器 thread_cache_size配置:

输入命令

mysql> show variables like 'thread_cache_size';

+-------------------+-------+

| Variable_name | Value |

+-------------------+-------+

| thread_cache_size | 32 |

+-------------------+-------+

mysql> show variables like 'thread_cache_size';

+-------------------+-------+

| Variable_name | Value |

+-------------------+-------+

| thread_cache_size | 32 |

+-------------------+-------+

9, 查询缓存(query cache)

输入命令

mysql> show global status like 'qcache%';

+-------------------------+----------+

| Variable_name | Value |

+-------------------------+----------+

| Qcache_free_blocks | 2226 |

| Qcache_free_memory | 10794944 |

| Qcache_hits | 5385458 |

| Qcache_inserts | 1806301 |

| Qcache_lowmem_prunes | 433101 |

| Qcache_not_cached | 4429464 |

| Qcache_queries_in_cache | 7168 |

| Qcache_total_blocks | 16820 |

+-------------------------+----------+

mysql> show global status like 'qcache%';

+-------------------------+----------+

| Variable_name | Value |

+-------------------------+----------+

| Qcache_free_blocks | 2226 |

| Qcache_free_memory | 10794944 |

| Qcache_hits | 5385458 |

| Qcache_inserts | 1806301 |

| Qcache_lowmem_prunes | 433101 |

| Qcache_not_cached | 4429464 |

| Qcache_queries_in_cache | 7168 |

| Qcache_total_blocks | 16820 |

+-------------------------+----------+

Qcache_free_blocks:缓存中相邻内存块的个数。数目大说明可能有碎片。FLUSH QUERY CACHE会对缓存中的碎片进行整理,从而得到一个空闲块。

Qcache_free_memory:缓存中的空闲内存。

Qcache_hits:每次查询在缓存中命中时就增大

Qcache_inserts:每次插入一个查询时就增大。命中次数除以插入次数就是不中比率。

Qcache_lowmem_prunes:缓存出现内存不足并且必须要进行清理以便为更多查询提供空间的次数。这个数字最好长时间来看;如果这个数字在不断增长,就表示可能碎片非常严重,或者内存很少。(上面的 free_blocks和free_memory可以告诉您属于哪种情况)

Qcache_not_cached:不适合进行缓存的查询的数量,通常是由于这些查询不是 SELECT 语句或者用了now()之类的函数。

Qcache_queries_in_cache:当前缓存的查询(和响应)的数量。

Qcache_total_blocks:缓存中块的数量。

我们再查询一下服务器关于query_cache的配置:

输入命令

mysql> show variables like 'query_cache%';

+------------------------------+----------+

| Variable_name | Value |

+------------------------------+----------+

| query_cache_limit | 33554432 |

| query_cache_min_res_unit | 4096 |

| query_cache_size | 33554432 |

| query_cache_type | ON |

| query_cache_wlock_invalidate | OFF |

+------------------------------+----------+

mysql> show variables like 'query_cache%';

+------------------------------+----------+

| Variable_name | Value |

+------------------------------+----------+

| query_cache_limit | 33554432 |

| query_cache_min_res_unit | 4096 |

| query_cache_size | 33554432 |

| query_cache_type | ON |

| query_cache_wlock_invalidate | OFF |

+------------------------------+----------+

各字段的解释:

query_cache_limit:超过此大小的查询将不缓存

query_cache_min_res_unit:缓存块的最小大小

query_cache_size:查询缓存大小

query_cache_type:缓存类型,决定缓存什么样的查询,示例中表示不缓存 select sql_no_cache 查询

query_cache_wlock_invalidate:当有其他客户端正在对MyISAM表进行写操作时,如果查询在query cache中,是否返回cache结果还是等写操作完成再读表获取结果。

query_cache_min_res_unit的配置是一柄”双刃剑”,默认是4KB,设置值大对大数据查询有好处,但如果你的查询都是小数据查询,就容易造成内存碎片和浪费。

查询缓存碎片率 = Qcache_free_blocks / Qcache_total_blocks * 100%

如果查询缓存碎片率超过20%,可以用FLUSH QUERY CACHE整理缓存碎片,或者试试减小query_cache_min_res_unit,如果你的查询都是小数据量的话。

查询缓存利用率 = (query_cache_size – Qcache_free_memory) / query_cache_size * 100%

查询缓存利用率在25%以下的话说明query_cache_size设置的过大,可适当减小;查询缓存利用率在80%以上而且Qcache_lowmem_prunes > 50的话说明query_cache_size可能有点小,要不就是碎片太多。

查询缓存命中率 = (Qcache_hits – Qcache_inserts) / Qcache_hits * 100%

示例服务器 查询缓存碎片率 = 20.46%,查询缓存利用率 = 62.26%,查询缓存命中率 = 1.94%,命中率很差,可能写操作比较频繁吧,而且可能有些碎片。

10,排序使用情况

输入命令

mysql> show global status like 'sort%';

+-------------------+----------+

| Variable_name | Value |

+-------------------+----------+

| Sort_merge_passes | 2136 |

| Sort_range | 81888 |

| Sort_rows | 35918141 |

| Sort_scan | 55269 |

+-------------------+----------+

mysql> show global status like 'sort%';

+-------------------+----------+

| Variable_name | Value |

+-------------------+----------+

| Sort_merge_passes | 2136 |

| Sort_range | 81888 |

| Sort_rows | 35918141 |

| Sort_scan | 55269 |

+-------------------+----------+

Sort_merge_passes 包括两步。MySQL 首先会尝试在内存中做排序,使用的内存大小由系统变量 Sort_buffer_size 决定,如果它的大小不够把所有的记录都读到内存中,MySQL 就会把每次在内存中排序的结果存到临时文件中,等 MySQL 找到所有记录之后,再把临时文件中的记录做一次排序。这再次排序就会增加 Sort_merge_passes。实际上,MySQL 会用另一个临时文件来存再次排序的结果,所以通常会看到 Sort_merge_passes 增加的数值是建临时文件数的两倍。因为用到了临时文件,所以速度可能会比较慢,增加
Sort_buffer_size 会减少 Sort_merge_passes 和 创建临时文件的次数。但盲目的增加 Sort_buffer_size 并不一定能提高速度,见 How fast can you sort data with MySQL?(引自http://qroom.blogspot.com/2007/09/mysql-select-sort.html

另外,增加read_rnd_buffer_size(3.2.3是record_rnd_buffer_size)的值对排序的操作也有一点的好处,参见:http://www.mysqlperformanceblog.com/2007/07/24/what-exactly-is- read_rnd_buffer_size/

11.文件打开数(open_files)

输入命令

mysql> show global status like 'open_files';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| Open_files | 821 |

+---------------+-------+



mysql> show variables like 'open_files_limit';

+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| open_files_limit | 65535 |

+------------------+-------+

mysql> show global status like 'open_files';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| Open_files | 821 |

+---------------+-------+

mysql> show variables like 'open_files_limit';

+------------------+-------+

| Variable_name | Value |

+------------------+-------+

| open_files_limit | 65535 |

+------------------+-------+

比较合适的设置:Open_files / open_files_limit * 100% <= 75%

正常

12。 表锁情况

输入命令

mysql> show global status like 'table_locks%';

+-----------------------+---------+

| Variable_name | Value |

+-----------------------+---------+

| Table_locks_immediate | 4257944 |

| Table_locks_waited | 25182 |

+-----------------------+---------+

mysql> show global status like 'table_locks%';

+-----------------------+---------+

| Variable_name | Value |

+-----------------------+---------+

| Table_locks_immediate | 4257944 |

| Table_locks_waited | 25182 |

+-----------------------+---------+

Table_locks_immediate 表示立即释放表锁数,Table_locks_waited表示需要等待的表锁数,如果 Table_locks_immediate / Table_locks_waited > 5000,最好采用InnoDB引擎,因为InnoDB是行锁而MyISAM是表锁,对于高并发写入的应用InnoDB效果会好些.

13. 表扫描情况

输入命令

mysql> show global status like 'handler_read%';

+-----------------------+-----------+

| Variable_name | Value |

+-----------------------+-----------+

| Handler_read_first | 108763 |

| Handler_read_key | 92813521 |

| Handler_read_next | 486650793 |

| Handler_read_prev | 688726 |

| Handler_read_rnd | 9321362 |

| Handler_read_rnd_next | 153086384 |

+-----------------------+-----------+

mysql> show global status like 'handler_read%';

+-----------------------+-----------+

| Variable_name | Value |

+-----------------------+-----------+

| Handler_read_first | 108763 |

| Handler_read_key | 92813521 |

| Handler_read_next | 486650793 |

| Handler_read_prev | 688726 |

| Handler_read_rnd | 9321362 |

| Handler_read_rnd_next | 153086384 |

+-----------------------+-----------+

各字段解释参见http://hi.baidu.com/thinkinginlamp/blog/item/31690cd7c4bc5cdaa144df9c.html,调出服务器完成的查询请求次数:

输入命令

mysql> show global status like 'com_select';

+---------------+---------+

| Variable_name | Value |

+---------------+---------+

| Com_select | 2693147 |

+---------------+---------+

mysql> show global status like 'com_select';

+---------------+---------+

| Variable_name | Value |

+---------------+---------+

| Com_select | 2693147 |

+---------------+---------+

计算表扫描率:

表扫描率 = Handler_read_rnd_next / Com_select

如果表扫描率超过4000,说明进行了太多表扫描,很有可能索引没有建好,增加read_buffer_size值会有一些好处,但最好不要超过8MB。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: