发布于 2016-03-29 22:26:08 | 125 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Mysql教程,程序狗速度看过来!

Mysql关系型数据库管理系统

MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。


这篇文章主要介绍了批量杀死MySQL连接的四种方法详解,本文分别给出了代码实例,需要的朋友可以参考下

方法一
  通过information_schema.processlist表中的连接信息生成需要处理掉的MySQL连接的语句临时文件,然后执行临时文件中生成的指令。



mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root';

+------------------------+

| concat('KILL ',id,';') |

+------------------------+

| KILL 3101;             |

| KILL 2946;             |

+------------------------+

2 rows in set (0.00 sec)

 

mysql>select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';

Query OK, 2 rows affected (0.00 sec)

 

mysql>source /tmp/a.txt;

Query OK, 0 rows affected (0.00 sec)

方法二
  杀掉当前所有的MySQL连接



mysqladmin -uroot -p processlist|awk -F "|" '{print $2}'|xargs -n 1 mysqladmin -uroot -p kill


杀掉指定用户运行的连接,这里为Mike


mysqladmin -uroot -p processlist|awk -F "|" '{if($3 == "Mike")print $2}'|xargs -n 1 mysqladmin -uroot -p kill


方法三
通过SHEL脚本实现


#杀掉锁定的MySQL连接

for id in `mysqladmin processlist|grep -i locked|awk '{print $1}'`

do

   mysqladmin kill ${id}

done


方法四
  通过Maatkit工具集中提供的mk-kill命令进行


#杀掉超过60秒的sql

mk-kill -busy-time 60 -kill

#如果你想先不杀,先看看有哪些sql运行超过60秒

mk-kill -busy-time 60 -print

#如果你想杀掉,同时输出杀掉了哪些进程

mk-kill -busy-time 60 -print –kill

mk-kill更多用法可参考:
http://www.maatkit.org/doc/mk-kill.html



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务