Forums

MYSQL create tables gets programming error: Access denied for user

Here is my code:

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config["DEBUG"] = True

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
    username="willp111",
    password="<my-password>",
    hostname="willp111.mysql.pythonanywhere-services.com",
    databasename="willp111$default",
)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(120), unique=False, nullable=False)

I have checked the .my.cnf file to check my password so I am sure it is correct.

I go to the bash console in directory flask_app, then I run ipython3.7.

Then I enter the code:

from flask_app import db
db.create_all()

I get the error message: ProgrammingError: (mysql.connector.errors.ProgrammingError) 1045 (28000): Access denied for user 'mysql+mysqlconnector'@'10.0.0.238' (using password : YES) (Background on this error at: http://sqlalche.me/e/f405)

If I print(db), it returns: <SQLAlchemy engine=mysql+mysqlconnector://mysql+mysqlconnector:***@willp111.mysql.pythonanywhere-services.com/willp111$users?charset=utf8>

You have mysql+mysqlconnector:// twice in your connection string.

Oh my god sorry. How can i reread the same code so many times and not see that.

Heh. We've all been there.