作为MySQL 数据库管理,经常使用一些工具将非常有效的帮助完成日常的工作。
比如对系统和数据库性能做测试用到的 Sysbench工具;Percona公司出品的PT系列工具,尤其是其中的slow log分析工具,是比较有效的;对于MySQL数据库进行实时监控的 orz系列工具,都是比较好的有效的工具。
orztop工具为淘宝的朱旭开发的一款可以查看mysql数据库实时运行的sql状况的工具,以前苦于通过show processlist/show full processlist抓取sql的同志们现在只要盯一盯屏幕就可以了,对于显示mysql数据库的实时事务状态非常直观、高效。
orztop可以点击下载链接进行下载,orztop下载链接;也可以在本文的附件中下载。
将orztop工具下载后,解压缩,然后上传到MySQL服务器上:
ssh 10.10.0.100
# cd /usr/local/src
# rz orztop
# chmod +x orztop
执行下面的命令确认orztop是否安装正常:
# ./orztop --help
Can't locate Term/ReadKey.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./orztop line 14.
BEGIN failed--compilation aborted at ./orztop line 14.
如果出现上述错误,说明缺少orztop运行所需的软件包,执行下面的命令查询并安装相应软件包:
查询缺少软件包的命令为:
yum search Readkey
实际执行过程如下:
# yum search Readkey
Loaded plugins: dellsysid, fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* updates: mirrors.yun-idc.com
base | 3.7 kB 00:00
dell-omsa-indep | 1.9 kB 00:00
dell-omsa-specific | 1.9 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 889 kB 00:00
============================= N/S Matched: Readkey =============================
perl-TermReadKey.x86_64 : A perl module for simple terminal control
Name and summary matches only, use "search all" for everything.
安装上述查询到的缺失软件包命令为:
yum -y install perl-TermReadKey.x86_64
实际执行过程如下:
# yum install perl-TermReadKey.x86_64
Loaded plugins: dellsysid, fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* updates: mirrors.yun-idc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package perl-TermReadKey.x86_64 0:2.30-13.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
perl-TermReadKey x86_64 2.30-13.el6 base 31 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 31 k
Installed size: 62 k
Is this ok [y/N]: y
Downloading Packages:
perl-TermReadKey-2.30-13.el6.x86_64.rpm | 31 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-TermReadKey-2.30-13.el6.x86_64 1/1
Verifying : perl-TermReadKey-2.30-13.el6.x86_64 1/1
Installed:
perl-TermReadKey.x86_64 0:2.30-13.el6
Complete!
再次执行命令确认 orztop 工具的状态
./orztop -help
执行过程如下:
# ./orztop --help
==========================================================================================
Info :
Created By [email protected]
Usage :
Command line options :
-help Print Help Info.
-h,--host Hostname/Ip to use for mysql connection.
-u,--user User to use for mysql connection.
-p,--pwd Password to use for mysql connection.
-P,--port Port to use for mysql connection(default 3306).
-S,--socket Socket to use for mysql connection.
-t Time(second) Interval.
==========================================================================================
顺利出线上述提示,说明orztop工具已经可以正常使用,使用方法如下:
#
./orztop -u=root -p=password -h=10.10.0.100 -P=3307
也可以将上述命令编写成一个脚本,以后直接执行脚本即可:
# vim /usr/local/src/orztop.sh
内容如下:
/usr/local/src/oztop
-u=root -p=password -h=10.10.0.100 -P=3307
然后将路径加入Linux系统文件中:
# vim /etc/profile.d/path.sh
加入 /usr/local/src:
# source /etc/profile.d/path.sh
以后调用下面的命令即可:
# orztop.sh
orztop工具执行后,在屏幕中会体现目前执行的sql语句,屏幕打出的信息中还包括了数据库的每秒的insert/update/delete/select,逻辑读,命中率,当前活动线程等,可以大致看到数据库的当前压力情况,当你的实例出现性能瓶颈时,不妨用该工具看看,抓取一下当前正在跑的慢sql,然后在分析一下sql,很不错的工具,推荐给大家。