Forums

Can't connect to mysql db

I have an app that allows users to register and log in. I can see the user details in the table after registration but when i try to log in it gives the following error.

raise errors.OperationalError("MySQL Connection not available.")
sqlalchemy.exc.OperationalError: (mysql.connector.errors.OperationalError) MySQL Connection not available.

It does not seem look like it is even connecting. This is what i have in my flask app, i removed the connection details but had previously entered in what I had in the databases tab. Any help will be appreciated as I am not sure how to proceed.

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
    username="",
    password="",
    hostname="",
    databasename="",
)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 280
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db)

Was it working before?

So when i open the sql console, i can see the user i created during the registration process in the table. it is when i try to log in that it throws up this error

How are you managing db connections? Could you show the bit of code that is raising the error (of course if there are any details you don't want to show, skip them, or alternatively send contact us via email at support@pythonanywhere.com).