Created
April 18, 2017 18:16
-
-
Save mdpuma/a06075e1011e3fe66d6cb8ecf6a1b837 to your computer and use it in GitHub Desktop.
kill_long_mysql_queries.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| IFS='|' | |
| # Id | User | Host | db | Command | Time | State | Info | Progress | |
| mysqladmin pr | sed -E 's/\s+//g' | grep -v '\-\-\-' | grep -vi Time | while read -r id1 id user host db command time state info progress; do | |
| [ -z "$time" ] && continue; | |
| [ "$command" = "Sleep" ] && continue; | |
| if [ "$time" -gt 300 ]; then | |
| mysql -e "kill $id" | |
| echo "killing $id ($db) $info" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment