Stack Exchange
MySQL query works at MySQL command line but doesn't work with Python
The following query works as expected at MySQL command prompt:
select * from users;


But, the same query in my following python program returns 0 rowcount. Python program is:
import mysql.connector
from mysql.connector import errorcode

config = {'user':'user1', 'password':'user1', 'host': '127.0.0.1', 'database': 'user1'}
con = mysql.connector.connect(**config)

if con == None or con == errorcode.ER_ACCESS_DENIED_ERROR or con == errorcode.ER_BAD_DB_ERROR:
    exit

print(con)

selectrow_users = "SELECT * FROM users"

cursor = con.cursor()
x = cursor.execute(selectrow_users, params=None)
print('rowcount = ', cursor.rowcount)  ## It gives zero

con.close()

Output is 0 rowcount:


Are you certain that you are hitting the same table in both cases, and that nothing is modifying the table contents in between invocations?

Were you in a transaction when you added the user to the table? Did you commit the transaction?

@TimBiegeleisen, yes Tim. There is only one table in my fresh mysql installation. I have just inserted one row in the table users. There are no other transactions.

@Barmar, yes Barmar. I have already commit the transaction. Restarted my computer also.

Still the problem persists. Let me know if someone is facing the same problem and solution if you have..

This is not a normal problem. You're doing something wrong that you haven't explained in the question.
