0

I'm using the Python package MySQLdb to fetch data from a MySQL database. However, I notice that I can't fetch the entirety of the data.

import MySQLdb
db = MySQLdb.connect(host=host, user=user, passwd=password)

cur = db.cursor()

query = "SELECT count(*) FROM table"
cur.execute(query)

This returns a number less than what I get if I execute the exact same query in MySQL Workbench. I've noticed that the data it doesn't return is the data that was inserted into the database most recently. Where am I going wrong?

1 Answer 1

2

You are not committing the inserted rows on the other connection.

Sign up to request clarification or add additional context in comments.

8 Comments

How do I do that?
send a COMMIT
Sorry but what's the code and where should I put it?
When you insert the rows using workbench, your connection can see the rows it just inserted. Other connections can't, as long as the transaction is not committed. Send a COMMIT from Workbench after you inserted the rows and both COUNT(*) will match.
Then you are probably not on the same database :-)
|

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.