kill掉Sleep的连接线程
2021-04-24 01:28
标签:mat rom pts code process 模块 sys imp sele kill掉Sleep的连接线程 标签:mat rom pts code process 模块 sys imp sele 原文地址:https://www.cnblogs.com/zhouwanchun/p/13266792.html#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#----------------------------------------------------------#
# Date : xxxx-xx-xx #
# Author : Created by zhouwanchun. #
# Wechat : loveoracle11g #
# Function: This scripts function is ... #
# Version : 1.1 #
#----------------------------------------------------------#
# 导入模块
import os
import subprocess
import mysql.connector
import myloginpath
# Linux终端清屏
os.system(‘clear‘)
# 注释信息
print("""\033[1;36m
############################################################
# Date : 2020-05-22 #
# Author : Created by zhouwanchun. #
# Wechat : loveoracle11g #
# Function: This scripts function is ... #
# Version : v1.1 #
############################################################
\033[0m""")
# 连接数据库账号
conn_user = ‘dba‘
# SQL语句
sql1 = ‘select concat("kill ", id, ";") from information_schema.PROCESSLIST where Command="Sleep";‘
print("\033[1;32mshow processlist; 查看当前的连接线程是 Sleep 状态\033[0m" + "\n")
subprocess.run([‘/usr/local/mysql/bin/mysql --login-path=‘ + conn_user + ‘ -BNse ‘ + "‘" + sql1 + "‘"], shell=True)
# 是否要kill掉这些Sleep的连接线程
if_kill = input("\n你是否要kill掉这些Sleep的连接线程(yes/no) : ").strip()
if if_kill == ‘yes‘:
subprocess.run([‘/usr/local/mysql/bin/mysql --login-path=‘ + conn_user + ‘ -BNse ‘ + "‘" + sql1 + "‘ > /tmp/kill_mysql_sleep.sql"], shell=True)
subprocess.run([‘/usr/local/mysql/bin/mysql --login-path=‘ + conn_user + ‘ -f ‘], shell=True)
else:
print("\033[1;35m大量的Sleep连接线程不kill掉,你在想啥呢?\033[0m" + "\n")
上一篇:推荐系统算法概览
下一篇:python 3 基础之单例模式