2

I keep receiving the following error in my Webapp

OperationalError: (_mysql_exceptions.OperationalError) (1045, "Access denied for user 'dbadmin'@'xx.xx.xx.x' (using password: YES)")

MySQL Azure:

  • Hosted in Region > France Central
  • Allowed Access to Azure Services
  • Created through Azure portal with username "dbadmin" and server "jetbase"

SQLAlchemy db_uri looks like this

mysql://dbadmin@jetbase:'mysecretpassword'@jetbase.mysql.database.azure.com:3306/jetdb

Webapp:

Hosted in France Central as well

The same docker image when run locally on my dev computer, can access the database (I manually added the ip in the client IP addresses under Security.)

Can someone please help me debug this ?

Shankar ARUL
  • 12,642
  • 11
  • 68
  • 69
  • According to the connection string, it seems that you're using the default MySQL driver through SQLAlchemy, which is mysql-python, right? I believe mysql-python is legacy. Can you try to use MySQL-Connector-python (version 1.2.3+) or PyMySQL (version 0.9.3+) ? https://docs.sqlalchemy.org/en/13/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector or https://docs.sqlalchemy.org/en/13/dialects/mysql.html#module-sqlalchemy.dialects.mysql.pymysql – Benjamin Talmard Oct 04 '19 at 20:08
  • Actually, PyMySQL might be the best option according to SQLAlchemy doc. – Benjamin Talmard Oct 04 '19 at 21:21

2 Answers2

4

Here's the wierd thing, my password had an exclamation mark '!' and turns out it wasnt getting parsed properly and I kept getting the error 'Access denied for user@XX.XX.XX.XX (Password = yes)

I switched it to a "*" and it works fine now.

I also had to remove the single quotes around the password from the db_uri

mysql://dbadmin@jetbase:mysecretpasswordwithoutquotes@jetbase.mysql.database.azure.com:3306/jetdb

Ps: The strange thing is that, the same docker container when run locally on my computer with the password containing a !, works fine. it works from MySQL work bench as well but just fails from App services (webapp) in Azure. I'm guessing Azure App services encodes the db_uri and messes up the "!" in the password

Shankar ARUL
  • 12,642
  • 11
  • 68
  • 69
1

I can give 2 ideas, with the provided information :

  • the encoding of database URL in your web app client. We have similar DB url syntax (with "@" in username) for our PG instances. In our servers, we replaced it with "%40" for it to work.
  • account dbadmin is not allowed from you webserver IP (maybe the IP is not static, maybe it is not the one you think of, it really depends on the hosting of your webapp). I imagine you double checked that already.

We can try debugging together if you want at StationF