Jupyter’s %sql magic yields an ‘Access Denied’ error for AWS Aurora MySQL, although external tests succeed. How can I correctly construct the SQLAlchemy URL?
import sqlalchemy as sa
params = {
'drivername': 'mysql',
'username': 'alpha',
'password': 'pass123',
'host': 'aws.cluster',
'port': 3306,
'database': 'demo_db'
}
conn_url = sa.engine.URL.create(**params)
Connecting to Aurora, I found that specifying the driver explicitly can make a difference. In my experience, using ‘mysql+pymysql’ as the drivername instead of just ‘mysql’ resolves the issue. This ensures that SQLAlchemy uses the proper adapter, which aligns with the connection settings that work externally. Ensuring that the adapter and any other required connection parameters, such as SSL options if needed, are correctly specified in the SQLAlchemy URL helped bypass the ‘Access Denied’ error in the Jupyter environment.