pip install MySQL-python
python
import MySQLdb
db = MySQLdb.connect(host="localhost", user="username", passwd="password", db="database")
cursor = db.cursor()
db.autocommit(False)
try:
cursor.execute("START TRANSACTION")
cursor.execute("INSERT INTO table1 (column1, column2) VALUES (%s, %s)", (value1, value2))
cursor.execute("UPDATE table2 SET column1 = %s WHERE column2 = %s", (value1, value2))
db.commit()
except Exception as e:
db.rollback()
finally:
cursor.close()
db.close()