mytop 是一个类似 Linux 下的 top 命令风格的 MySQL 监控工具,可以监控当前的连接用户和正在执行的命令。
1. 安装TermReadKey
下载地址: wget http://search.cpan.org/CPAN/authors/id/J/JS/JSTOWE/TermReadKey-2.30.tar.gz
安装:
tar xzvf TermReadKey
cd TermReadKey
perl Makefile.pl
make
make test
make install
2. 安装DBI
下载地址: wget http://cpan.uwinnipeg.ca/dist/DBI (不可行)
安装:
tar xzvf DBI-1.615.tar.gz
cd DBI-1.615
perl Makefile.pl
make
make test
make install
或者:(可行)
[root@hd-119-186 mytop-1.6]# yum list|grep DBD
Unable to read consumer identity
perl-DBD-MySQL.x86_64 3.0007-2.el5 installed
perl-DBD-Pg.x86_64 1.49-2.el5_3.1 hc360
[root@hd-119-186 mytop-1.6]# yum -y install perl-DBD-MySQL.x86_64
3. 安装Mytop
下载地址:wget http://jeremy.zawodny.com/mysql/mytop/mytop-1.6.tar.gz
安装:
tar xzvf mytop-1.6.tar.gz
cd mytop-1.6
perl Makefile.pl
make
make test
make install
4.执行 mytop -uroot -pxxxxx 可能会出现报错:
==========补充============
Can't locate ExtUtils/Embed.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 .).
BEGIN failed--compilation aborted.
到网上搜索, 需要安装perl-ExtUtils-Embed:
yum install perl-ExtUtils-Embed -y
==========补充============
配置mytop并运行 [root@tech mytop-1.6]# mytop Cannot connect to MySQL server. Please check the: * database you specified "test" (default is "test") * username you specified "root" (default is "root") * password you specified "" (default is "") * hostname you specified "localhost" (default is "localhost") * port you specified "3306" (default is 3306) * socket you specified "" (default is "") The options my be specified on the command-line or in a ~/.mytop config file. See the manual (perldoc mytop) for details. Here's the exact error from DBI. It might help you debug: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
配置
1
|
vi /root/.mytop
|
写入如下内容:
host=localhost
user=root
pass=111111
db=mysql
port=3306 socket=/tmp/mysql.sock delay=5 batchmode=0 color=1 idle=1
保存退出
MySQL on localhost (5.1.43-log) up 345+20:36:31 [09:07:11]
Queries: 3.0 qps: 0 Slow: 0.0 Se/In/Up/De(%): 00/00/00/00
Key Efficiency: 100.0% Bps in/out: 0.0/ 0.0
Id User Host/IP DB Time Cmd Query or State
-- ---- ------- -- ---- --- ----------
Use of uninitialized value in substitution (s///) at ./mytop line 955.
Use of uninitialized value in substitution (s///) at ./mytop line 955.
...................................................
Use of uninitialized value in substitution (s///) at ./mytop line 955.
解决方法:
vi mytop
跳到955行,找到
$host =~ s/^([^.]+).*/$1/;
$thread->{Host} = $host;
改为:
if ($host)
{
$host =~ s/^([^.]+).*/$1/;
$thread->{Host} = $host;
}
三、参数
-u / --user :指定 username,预设是 root
-p / --pass / --password :指定 password,预设是 none
-h / --host :指定 MySQL server 的 hostname,预设是 localhost
-P / --port :指定连接 MySQL server 的 port,预设是 3306
-s / --delay :更新的秒数,预设是 5 秒
-d / --db / --database :指定连接的资料库,预设是 test
-b / --batch / --batchmode:指定为 batch mode,每次更新不会清除旧的显示结果,会将更新资料显示上最上方,预设是 unset
-S / --socket :指定使用 MySQL socket 直接连线,而不使用 TCP/IP 连线,预设是 none (当 mytop 和 MySQL 在同一台时才能使用)
--header or -noheader:是否要显示表头,预设是 header
--color or --nocolor:是否要使用颜色,预设是 color
-i / -idle or -noidle:idle 的 thread 是否要出现在清单上,预设是 idle
mytop 快捷键
s:设定更新时间
p:暂停画面更新
q:离开
u:只看某个使用者的 thread
o:反转排列顺序
参考:http://blog.51cto.com/solothisworld/994509
评论(0)