MySQLKillsleep process _ MySQL

Source: Internet
Author: User
If the MySQLKillsleep process is idle, study it slowly...



--------------------------------------------------------


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)


---------------------------------------------------------
#! /Bin/bash
# While ["2"-gt "1"]
# Do
Log_command = 'mysqladmin processlist | grep-I sleep | wc-L'
Date = 'date + % Y % m % d/[% H: % M: % S]'
# Echo $ log_command
If ["$ log_command"-gt 250]
Then
For I in 'mysqladmin processlist | grep-I sleep | awk '{print $2 }''
Do
Mysqladmin kill $ I
Done
Echo "$ date: $ log_command, sleep is too when I killed it">/data/killsleep/sleep. log
Else
Echo "$ date: $ log_command, not need to kill">/data/killsleep/sleep. log
Fi
# Sleep 180
# Done

Note that the user executing mysqladmin directly runs mysqladmin processlist | grep-I sleep | wc-l on the command line, which is actually-uroot. The user logging on to the server is used to execute this script on the command line. While crontab is used for execution, although it is edited as the root crontab, it is not a root user during execution, and I do not know which one is used. It is best to add su-root to the crontab command.




Bytes --------------------------------------------------------------------------------------
# It is used to kill processlist of mysql sleep ~~~
#! /Bin/sh
While:


Do
N = '/opt/mysql/bin/mysqladmin processlist | grep-I sleep | wc-L'
Date = 'date + % Y % m % d/[% H: % M: % S]'
Echo $ n
# Id = '/opt/mysql/bin/mysqladmin processlist | grep Sleep | awk' {if ($12> 100) {print $2 }}''
# Echo "$ date: $ n">/tmp/sleep. log
# If [id! = ""]
# Then
# For j in $ id
# Do
#/Opt/mysql/bin/mysqladmin kill $ j
# Echo "$ date: sleep is to long">/tmp/sleep. log
# Fi
#
If ["$ n"-gt 60]
Then


For I in '/opt/mysql/bin/mysqladmin processlist | grep-I sleep | awk' {print $2 }''
Do
/Opt/mysql/bin/mysqladmin kill $ I
Done
Echo "sleep is too I killed it">/tmp/sleep. log
Echo "$ date: $ n">/tmp/sleep. log
Fi
Sleep 1
Done

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.