Forums

Authentication error Accessing MySQL with flask

Hi, I’m trying to access my SQL database hosted on Pythonanywhere eu and I get the following error - sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) 1045.(28000): Access denied for user '19roberl'@'10.0.0.42' (using password: YES) (Background on this error at: https://sqlalche.me/e/20/f405)

I am using this code :::python

from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy
import hashlib
app = Flask(__name__)
SQLALCHEMY_DATABASE_URI = (
    "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
        username="19roberl",
        password="12345",
        hostname="19roberl.mysql.eu.pythonanywhere-services.com",
        databasename="19roberl$account",
    )
)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)

app.app_context().push()

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.String(256), nullable=False)
db.create_all()

I have set my database password to be 12345 and the names are correct. Any help would be greatly appreciated

Are you sure you set your database password to that? That error means that either the username, the host, the database or the password are incorrect and everything except the password looks right for your account.

I've just checked the password and tried to reset it, I didn't see the error last time for an invalid password when resseting it. It all works properly now, Thanks for the nudge

Glad you got it working! One thing to check in case it happens again to you (or, more likely, someone else hitting the same problem and searching the forums for an answer) is the file .my.cnf in your home directory. It will contain your MySQL password.