How to enable autocommit in python-mysql integration using mysql.connector?

258 views Asked by At

I am working on a python project using mysql database integration by mysql.connector package. I want to turn on autocommit but dont know how to do that. This is how I connected with mysql:

mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="admin"
)

Please tell me how to turn on autocommit if you know so.

1

There are 1 answers

0
Bill Karwin On BEST ANSWER

Given your example, you should use this line of code:

mydb.autocommit = True

This is in the documentation. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-autocommit.html