In fact, @JoeDay described above has little to do with MySQL default behavior. MySQL by default runs in auto-commit mode , and usually you don't need any additional changes to save the changes:
By default, MySQL works with autocommit enabled. This means that as soon as you execute the statement that updates (changes) the table, MySQL saves the update on disk to make it permanent. This change cannot be undone.
The authors of PEP-249 (DB API) decided to complicate the situation and break Zen Python, making the transaction run implicit, offering automatic commit by default.
What I propose to do is restore the default MySQL behavior. And use transactions explicitly only when you need it.
import pymysql connection = pymysql.connect(autocommit=True)
I also wrote about this here with a few links.
source share