'"Access denied for user '…'" when I didn't provide a username for the database
I am getting the following error while trying to run a python application that uses the following regex entry
database:
host: 127.0.0.1
name:
password:
port: 3306
user:
I am getting the following error on console.log when I am trying to run the application using the database.
super().__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'ahmed'@'localhost' (using password: NO)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)
I am pretty new to command line based MySQL and ubuntu itself
Solution 1:[1]
If we fail to provide a username and password to the MySQL dialect then the drivers (mysqldb and pymysql, at least) attempt to log into the MySQL server without a password using the current username from the OS.
import sqlalchemy as sa
engine = sa.create_engine(
sa.engine.URL.create(
"mysql+pymysql",
host="192.168.0.199",
database="test",
)
)
with engine.connect() as conn:
"""
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError)
(1045, "Access denied for user 'gord'@'192.168.0.179' (using password: NO)")
"""
You will either need to provide SQLAlchemy with a valid username and password for the MySQL server, or create a MySQL user named "ahmed" without a password that has permission to access the database for your application.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gord Thompson |
