Hi there,
I need some help with connecting to a mysql database. I am trying to run a python script called init_db.py that, as the name suggests, initializes database tables using sqlalchemy and needs to connect to the database. the lines of interest are:
db_url = os.environ.get('DATABASE_URI') if db_url.startswith("mysql"): engine = create_engine(db_url, pool_recycle=280) else: engine = create_engine(db_url) # Test connection with engine.connect() as connection: print("Connection successful!") However, when I try to run the script using the following bash command:
DATABASE_URI="mysql://rmheu:<password>@rmheu.mysql.eu.pythonanywhere-services.com:3306/rmheu$dms_database" python scripts/init_db.py
I get the following error:
An error occurred: (MySQLdb.OperationalError) (1045, "Access denied for user 'rmheu'@'10.0.0.146' (using password: YES)")
The error suggests it is an authentication error, but having changed my password and trying again multiple times I am thinking it has more to do with my connection string. I have also tried adding '+mysqlclient' or '+PyMySQL' after 'mysql' (those give me different errors), and changed 'rmheu$dms_database' to 'dms_database'. What am I missing here? Any help is much appreciated.