I have created a python program (with python3 and mysql.connector library) that updates the value of a column in a MySQL DB. When I run the command SELECT * FROM table_name in python seems to have changed the value, but when I run this command in MySql WorkBench it drops me the table with no changes applied.
Here is my code:
db = mysql.connector.connect(
host = "IP adress",
user = "user",
passwd = "password"
)
mycursor = db.cursor()
mycursor.execute("USE db_name;")
mycursor.execute('UPDATE table_name SET column = value WHERE condition;')
mycursor.execute('SELECT * FROM table_name;')
print(mycursor.fetchone())
As I have previously mentioned, when I run the command SELECT * FROM table_name in python it seems like the changes have been applied, but when I run it in MySql Workbench it seems like no changes have been applied. Does anybody know what the problem is?
-
2Either you're not connected to the same database, or you're in implicit transaction mode and are not committing the transaction.deceze– deceze ♦2022年04月18日 09:58:58 +00:00Commented Apr 18, 2022 at 9:58
1 Answer 1
try : before print(mycursor.fetchone())
db.commit()