I've built my code base primarily in PHP and am seeing what I can put together in Python. One key challenge I've wanted to tackle is to be able to read and write to my MySQL database through AWS RDS. I played around with a script using pymysql and thought I had solved my problems. I run a short update script:
usql1 = "UPDATE table_name SET STATE='Georgia', SCORE2='1' WHERE ID=1"
response1 = cursor.execute(usql1)
When I print the results in my Python code I see the state changed to Georgia and the SCORE2
field changed to 1
. However when I refresh the table in MySQL Workbench nothing has changed.
Why would the results be changing when I retrieve and print the table in my Python script but not in the underlying database? Does this have something to do with how cursors are initiated with pymysql?
Thanks!
When you execute your update, MySQL is implicitly starting a transaction. You need to commit this transaction by calling connection.commit()
after you execute your update to keep the transaction from automatically rolling back when you disconnect.