Forums

Getting mysql connection error, but all parameters seem to be OK

Hi,

I'm using Flask. I'm getting mysql connection error. All parameters seem to be right. What could be the problem?

 class Config(object):
     ...

     SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}?charset=utf8".format(
        username="<my_username>",
        password="<my_password",
        hostname="<my_username>.mysql.pythonanywhere-services.com",
        databasename="<my_username>$my_new_database")

     SQLALCHEMY_TRACK_MODIFICATIONS = False

config = Config()

app = Flask(__name__)
app.config.from_object(config)

The error I get is:

Error running WSGI application
2023-05-11 14:18:32,690: sqlalchemy.exc.DatabaseError: (mysql.connector.errors.DatabaseError) 2003 
    (HY000): Can't connect to MySQL server on 'localhost:3306' (111)
2023-05-11 14:18:32,690: (Background on this error at: https://sqlalche.me/e/20/4xp6)

What am I missing?

That code is not using those settings - it is trying to connect to the default (localhost:3306). There appears to be a bug in your code that is preventing those database settings from being used.