mk-kill – 顾名思义,杀mysql线程。安装方法查看这里。
在一个OLTP的生产环境,一般不会让sql执行过长的时间,特别是myisam这样表锁的引擎,如果出现长时间执行的sql一般是误操作,要不就是出现问题了。
出现这种情况,一般是登录mysql手工执行kill操作,Maatkit现在提供了一个命令来执行这个操作。例如:
杀掉超过60秒的sql:
mk-kill -busy-time 60 -kill
如果你想先不杀,先看看有哪些sql运行超过60秒:
mk-kill -busy-time 60 -print
如果你想杀掉,同时输出杀掉了哪些进程:
mk-kill -busy-time 60 -print –kill |
Read the rest of this entry »
mk-slave-find – 顾名思义,根据master查找slave。安装方法查看这里。
在mysql5.1里查看一个master有哪些slave可以通过PROCESSLIST系统表查出:
mysql> select HOST from information_schema.PROCESSLIST where STATE like '%slave%';
+------------------+
| HOST |
+------------------+
| 192.168.1.2:44846 |
| 192.168.1.3:33022 |
| 192.168.1.4:50836 |
| 192.168.1.5:32769 |
| 192.168.1.6:33113 |
| 192.168.1.7:33005 |
| 192.168.1.8:32786 |
| 192.168.1.9:32862 |
+------------------+
11 rows in set (0.00 sec) |
Read the rest of this entry »
mk-query-digest 一个功能很强大的工具,能分析慢查询日志,也可以对当前的语句进行分析等。安装方法查看这里。
一、分析慢查询日志,生成报表
mysql通过log-slow-queries和long_query_time参数来记录慢查询,默认的格式如下:
# Time: 090909 4:34:28
# User@Host: sparty[sparty] @ [localhost]
# Query_time: 18 Lock_time: 0 Rows_sent: 5 Rows_examined: 52830
select * from test;
# Time: 090909 14:04:24
# User@Host: sparty[sparty] @ [localhost]
# Query_time: 20 Lock_time: 0 Rows_sent: 10 Rows_examined: 2500284
select * from test2; |
Read the rest of this entry »
mk-table-checksum – 检查数据库复制模式里,master和slave的表是否一致,安装方法可以参考这里。
mysql在5.1之前,其replication都是采用的STATEMENT模式,对表的数据是否一致要求并不严格,所以对数据一致性要求比较严格的应用,定期检查数据一致性是很有必要的,mk-table-checksum 是一个很不错的检查工具。
Read the rest of this entry »
mk-parallel-restore – Load files into MySQL in parallel. 安装方法可以参考这里。
在上一篇介绍了mk-parallel-dump并行备份,会把mysql的按照database模式,每个表都生成一个单独的备份文件,并统一在你指定的目录。
mk-parallel-restore其实就是mk-parallel-dump的反向操作,也会同时启用4个mysql进程去进行恢复,默认优先恢复大表。
Read the rest of this entry »
mk-parallel-dump – 顾名思义,并行mysqldump工具。安装方法可以参考这里。
mysqldump是单进程的,同时只能备份1个表。mk-parallel-dump它会同时并发4个mysqldump进程,同时备份4个表,默认是先备份大表,在备份小表。和mysqldump出来生成一个文件不同,它将每个表生成一个单独的文件。默认使用gzip对文件进行压缩。
使用mysqldump备份40G左右的数据,大概需要2小时。而使用mk-parallel-dump不到1小时能完成,效率能提高200%左右。
Read the rest of this entry »
mk-visual-explain – 格式化mysql执行计划输出。安装方法可以参考这里。
Mysql默认的执行计划输出类似如下:
mysql> explain select count(*) from test a,test2 b where a.id<100 and b.id>160 and a.id=b.id;
+----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
| 1 | SIMPLE | b | range | uid | id | 4 | NULL | 30 | Using where |
| 1 | SIMPLE | a | eq_ref | PRIMARY | PRIMARY | 4 | b.uid | 1 | Using index |
+----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
2 rows in set (0.00 sec) |
Read the rest of this entry »
mk-deadlock-logger – 查看mysql的死锁信息。安装方法可以参考这里。
有2种方式可以查看死锁信息。第一种方法是直接打印出来:
$ mk-deadlock-logger --source u=sg,p=xxxx,h=localhost --print
server ts thread txn_id txn_time user hostname ip db tbl idx lock_type lock_mode wait_hold victim query
localhost 2007-03-08T20:34:22 81 21309 29 baron localhost test c GEN_CLUST_INDEX RECORD X w 1 select * from c for update
localhost 2007-03-08T20:34:22 83 21310 19 baron localhost test a GEN_CLUST_INDEX RECORD X w 0 select * from a for update |
Read the rest of this entry »
mk-duplicate-key-checker – 检查MYSQL重复索引,并给出删除语句。安装方法可以参考这里。
在oracle里,不允许在同一个列上创建多个索引,如果试图创建就会报错如下:
CREATE INDEX sg1 ON uid_tmp(user_id);
CREATE INDEX sg1 ON uid_tmp(user_id)
*
ERROR AT line 1:
ORA-01408: such column list already indexed |
而在mysql上,却是允许的,不知道为何要这样,总之是可以的。
Read the rest of this entry »
mk-audit – 分析报告mysql状态和操作系统相关环境,给出推荐值。安装方法可以参考这里。
这个工具能把MYSQL的配置文件,SCHEMA的情况,操作系统的情况统一收集起来,形成一个统一的报表,并给出建议。
Read the rest of this entry »