2

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?

1
  • 2
    Either you're not connected to the same database, or you're in implicit transaction mode and are not committing the transaction. Commented Apr 18, 2022 at 9:58

1 Answer 1

1

try : before print(mycursor.fetchone())

db.commit()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much that solved my problem!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.