I created a small/basic python script to insert data into a MySQL database. I included some error handling - mainly to close the connection and/or prevent hanging connections in
I believe the issue was I wasn't invoking conn.rollback()
in the except
clause (and consequently, the connection was not closing properly). One line (see below) seemed to fix the issue (I can't be exactly sure if that was this issue - if someone could confirm that would be great).
conn=MySQLdb.connect(host=####, user=####, passwd=####, db=####)
curs=conn.cursor()
try:
curs.execute(sql)
conn.commit()
except MySQLdb.Error as e:
conn.rollback() #rollback transaction here
if e[0]!= ###:
raise
finally:
curs.close()
conn.close()