2010年5月31日星期一

MySQL enterprise Monitor的安装和使用

  上次内部分享MySQL经验的时候,西山居的DBA建议试用一下MySQL enterprise Monitor,游戏部门已经购买,并且评价很高。
  
  抽空安装试用了一下,感觉挺好的,可以发现不少数据库存在的风险,推荐大家使用。

  官方的文档挺全的,这里记录一下安装的过程。
   1、到https://enterprise.mysql.com/去申请一个试用版。
   2、安装监控访问管理端的程序(service manager and dashboard),这个我是安装在windows下的。一路next就行
  3、增加agent的MySQL权限:
            grant select,replication client,show databases,super,process on *.* to ‘agent’@'127.0.0.1′ identified by ‘password’;
           grant create,insert on mysql.* to ‘agent’@'127.0.0.1′ identified by ‘password’;
 4、安装agent端程序(mysqlmonitoragent),:
       rpm -qa | grep -i lsb 看redhat-lsb-3.1-12.3.EL是否存在(数据库操作系统为centos5.4)
       直接执行 mysqlmonitoragent-2.2.0.1705-linux-glibc2.3-x86-64bit-installer.bin --mode text即可。如果不需要agent采集SQL语句来分析,就不用开启MySQL Enterprise Agent Proxy Service。
5、/etc/init.d/mysql-monitor-agent start 启动agent。可以查看/opt/mysql/enterprise/agent/mysql-monitor-agent.log来看是否正常。
6、没问题的话,在server端的18080端口就可以看到数据库的监控情况了。
     

2010年5月12日星期三

MySQL Query Browser的SQL语句耗时提示

在MySQL Query Browser中执行一条SQL语句,会发现左下角有一行提示:

N row(s) fetched in Time1 s(Time2 s)


以前没有在意里面两个时间的区别,最近数据库(IBM x3650)网卡故障,访问很慢,在排除软件问题的时候,发现这两个时间比较诡异,有时Time1比Time2大很多。google了下,这里可以看到sun数据库工程师的解释:

 query_time is the time the query needed to execute:

// Start query timer
timer_start(&timer);

if (sql)
r= myx_mysql_query(mysql, resultset->query->sql);
#if MYSQL_VERSION_ID >= 50000
else
r= mysql_next_result(mysql);
#endif
// Stop query timer
resultset->query_time= timer_stop(&timer);

and fetch_time is what it took to get the result set transferred to the client.


可以得知,Time1是服务器端把结果传回客户端的时间,Time2是数据库执行SQL语句的时间。