Forums

Access denied error when attempting to connect to MySQL

Hello, I'm receiving the following connection error when trying to connect with the code below. I'm able to successfully use the MySQL console and run queries against the database with the credentials within the code (note, password in copied code changed for security purposes). I'm new to Python programming and pythonAnywhere, any help is appreciated.

error ----> mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'camino946'@'10.0.0.146' (using password: YES)

---------------------------------- code below this line----------------------------------------------------------------------------------------

import mysql.connector
print("beginning")
def get_data():
    connection = mysql.connector.connect(
    host='camino946.mysql.pythonanywhere-services.com',
    user='camino946',
    password='myDBpassword',   # note: i use my real password in my code that is failing
    database='camino946$nba_db'
    )

cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT player_name, AVG(pts) as avg_points FROM player o join player_game_log c on o.player_id = c.player_id group by player_name;")
rows = cursor.fetchall()

cursor.close()
connection.close()

return rows

You need to use the correct password to access your database. It is the one that you used when you enabled MySQL.