MySQL监控性能的一些方法总结


---首先, Oracle中的逻辑读对应物理读的概念,是在利用数据缓存区的技术上,对数据访问次数的计数分类。
---物理读,真正有IO;逻辑读,是从缓存区读到数据,可以考察缓存区的命中率,但只是某个具体对象在缓存区中的命中率。
---所以,使用数据缓存区技术的,都可以有类似的方式。但是,这仅是从IO的角度去衡量数据库的性能的。即不完全可靠。
---其次,MySQL提供了一些方式,用以考察IO的使用情况。
---MySQL方式1:区分“索引读”还是“随机读”。这种情况,不从缓存区的角度出发,是从单表扫描数据的方式的角度出发的。
---所以,可以采用如下方式辅助判断:
mysql> show status like 'handler_read%';
+-----------------------+-------+
| Variable_name        | Value |
+-----------------------+-------+
| Handler_read_first    | 0    |
| Handler_read_key      | 2    |
| Handler_read_last    | 0    |
| Handler_read_next    | 0    |
| Handler_read_prev    | 0    |
| Handler_read_rnd      | 0    |
| Handler_read_rnd_next | 0    |
+-----------------------+-------+
7 rows in set (0.00 sec)
---MySQL方式2:通过状态变量了解服务器整体状况
---通过show status和应用特点了解各种sql的执行频率
---通过show status可以提供服务器状态信息,如以下几个参数对MyISAM和Innodb存储引擎都计数:
1、com_select:执行select操作的计数,一次查询只累加1;
2、com_insert:执行insert操作的次数,对于批量插入的insert操作,只累加一次;
3、com_update:执行update操作的次数;
4、com_delete:执行delete操作的次数;
---以下几个参数是针对Innodb存储引擎计数的,累加的算法也略有不同:
1、Innodb_rows_read:查询返回的行数,不仅是select操作,delete和update也会触发对元组的读操作;
2、Innodb_rows_inserted:执行insert操作插入的行数;
3、Innodb_rows_updated:执行update操作更新的行数;
4、Innodb_rows_deleted:执行delete 操作删除的行数;
通过以上几个参数,使用show status 命令查看参数值,就可以很容易了解当前数据库的应用是以插入更新为主还是查询操作为主,对于更新操作的计数,是对执行次数的计数,不论成功提交还是回滚都会累加。
对于事务型的应用,可以通过com_commit和com_rollback可以了解事务提交和回滚的情况,对于回滚操作非常频繁的数据库,可能意味着存在应用编写问题。
---MySQL方式3:通过PFS(Performance Schema)了解服务器整体状况/IO状况
1、The MySQL Performance Schema is a feature for monitoring MySQL Server execution at a low level.
2、The Performance Schema monitors server events. An “event” is anything the server does that takes time and has been instrumented so that timing information can be collected. In general, an event could be a function call, a wait for the operating system, a stage of an SQL statement execution such as parsing or sorting, or an entire statement or group of statements. Currently, event collection provides access to information about synchronization calls (such as for mutexes) file and table I/O, table locks, and so forth for the server and for several storage engines.
3、这个功能很强大, 请大家注意掌握. 内容多我们不一一说明,可以参考官方手册的performance-schema.htm文件. 他必定要成为MySQL监控的主流.

--------------------------------------分割线 --------------------------------------

Ubuntu 14.04下安装MySQL

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主从服务器

Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群

Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb

MySQL-5.5.38通用二进制安装

--------------------------------------分割线 --------------------------------------

本文永久更新链接地址:

相关内容