Skip to content

Instantly share code, notes, and snippets.

@mdpuma
Created April 18, 2017 18:16
Show Gist options
  • Select an option

  • Save mdpuma/a06075e1011e3fe66d6cb8ecf6a1b837 to your computer and use it in GitHub Desktop.

Select an option

Save mdpuma/a06075e1011e3fe66d6cb8ecf6a1b837 to your computer and use it in GitHub Desktop.
kill_long_mysql_queries.sh
#!/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