Permalink
Browse files

Add -S option for MySQL socket file

  • Loading branch information...
1 parent bc4bc4e commit 969c4cb9d10cf0305ae7cb58bcd71a8768da69a0 dschultz committed Sep 27, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 MySQL/mysqlHammerOfThor.py
View
@@ -54,6 +54,7 @@ def killQueriesByID(db, queries):
parser.add_option('-u', '--user', help='User that can kill queries (default: root).', dest='user', default=False, action='store')
parser.add_option('-w', '--wildcard', help='Kills all queries from any host matching a wildcard string.', dest='host', default=False, action='store')
parser.add_option('-t', '--threshold', help='Kills all queries that have been running longer than this value in seconds.', dest='thresh', default=False, action='store')
+ parser.add_option('-S', '--socket', help='The socket file to use for connection.', dest='socket', default=False, action='store')
(opts, args) = parser.parse_args()
@@ -75,6 +76,11 @@ def killQueriesByID(db, queries):
else:
myUser = opts.user
+ if not opts.socket:
+ socket = "/var/lib/mysql/mysql.sock"
+ else:
+ socket = opts.socket
+
if opts.host and opts.thresh:
print "You can only specify one kill method."
sys.exit(1)
@@ -84,14 +90,14 @@ def killQueriesByID(db, queries):
if opts.host:
# BTW, This will kill your own connecton to the server if the wildcard matches your own host.
print "Killing all queries from hosts matching *%s*" % opts.host
- db = MySQLdb.connect(host=opts.server, port=myPort, user=myUser, passwd=myPasswd, db='information_schema')
+ db = MySQLdb.connect(unix_socket=socket, host=opts.server, port=myPort, user=myUser, passwd=myPasswd, db='information_schema')
q = getQueriesByHost(db, opts.host)
killQueriesByID(db, q)
db.close()
elif opts.thresh:
print "Killing all queries running longer than %s seconds" % opts.thresh
- db = MySQLdb.connect(host=opts.server, port=myPort, user=myUser, passwd=myPasswd, db='information_schema')
+ db = MySQLdb.connect(unix_socket=socket, host=opts.server, port=myPort, user=myUser, passwd=myPasswd, db='information_schema')
q = getQueriesByTime(db, opts.thresh)
killQueriesByID(db, q)
db.close()

0 comments on commit 969c4cb

Please sign in to comment.