Forums

Python 3.6 and InnoDB -- how to autocommit

For some reason, autocommit doesn't work for me, such that I have to add explicit conn.commit() after every INSERT/UPDATE.

Could be a syntax issue as several suggestions can be found on the www. For instance, the statement(s) below do not work, unless the c.execute statement is followed by a db.commit(). Any idea?

 import MySQLdb
 db=MySQLdb.connect(passwd="PW!",db="user$DB",host='user.mysql.pythonanywhere-services.com')
 db.autocommit = True
 c=db.cursor()
 theQuery = "INSERT INTO aTable (aCol) SELECT aCol from anotherTable"
 c.execute(theQuery)

You want

db.autocommit(True)

Thanks.