Created
January 31, 2019 00:55
-
-
Save jonathanhle/8217c6ca47fc9fcfbc588b3ba47d0ea6 to your computer and use it in GitHub Desktop.
kill old mysql sessions with sqlalchemy
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
from sqlalchemy import create_engine | |
engine = create_engine('mysql+mysqldb://USERNAME:[email protected]/DBNAME', pool_recycle=3600) # connect to server | |
old_sessions = engine.execute("select id from information_schema.processlist where user not in ('user1','user2','user3')").fetchall() | |
for session in old_sessions: | |
print("Killing session id " + str(session[0])) | |
engine.execute("CALL mysql.rds_kill({session_id});".format(session_id=session[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment