Forums

Access denied error with MySQL and SQLAlchemy DATABASE_URL

I have a MySQL database called mydatabase. I want to access the database using SQLAlchemy and the mysql connector.

Here is a portion of the sqlalchemy_test.py file:

from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import sessionmaker

# Define DATABASE_URL 
DATABASE_URL = "mysql+mysqlconnector://myname:mypassword@myname.mysql.pythonanywhere-services.com/myname$mydatabase"

# Create an engine
engine = create_engine(DATABASE_URL, pool_recycle=280)

I received an error with mysql.connector:

raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) 1045 (28000): Access denied for user 'myname'@'10.0.4.4' (using password
: YES)

I am able to access the mydatabase database without SQLAlcahemy using the following connector values:

export MYSQL_HOST="myname.mysql.pythonanywhere-services.com"
export MYSQL_USER="myname"
export MYSQL_PASSWORD="mypassword"
export MYSQL_DATABASE="myname\$mydatabase"

I used the Bash terminal, and I am able to log into the mysql shell and access the database via:

mysql -u myname -p myname$mydatabase

I removed the password from the my.cnf file. Per one user's comment in the Forum, I have an eight character password.

What do I have wrong in the sqlalchemey_test.py code?

[formatted by admin]

Could you show real values (you may redact the password), or at least compare them with this help page? It's hard to debug if we don't know what are the real values. Also, is it failing on the create_engine call?