1

I'm still learning how to work with a databases using python libraries

An operational error has occurred while executing the following code screenshot

Code snippet:

import pymysql
db1=pymysql.connect(host="127.0.0.1",user="root",password='root',port=3306,db='world')

a=db1.cursor()

sql='SELECT * from CITY'
print(a.execute(sql))

Error:

(1045, "Access denied for user 'root'@'localhost' (using password: NO)")

what could be the reason for this?

1 Answer 1

1

An operational error has occurred while executing the following code screenshot. what could be the reason for this?

  • Error in question is:

    (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
    

    It reveals that you are attempting to connect without password while you actually supplied one in connection arguments. This was at one point known bug with pymysql so answer can be version dependent. If you can normally connect to mysql with mysql -u root -proot world (database, password and user from your connect arguments) that means that your database is indeed with proper credentials and expects password while connect method is not sending one, most probably due to old version. On the other hand if you can't connect then most probably your root password is blank and you need to set it properly. Also there is option that you have issues with access to database 'world' for root user.

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

Comments

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.