Forums

To connect PythonAnywhere to a MySQL database

Hi there, it is good to see you here.

I am trying to connect PythonAnywhere to a MySQL database. My connection to MySQL database from Bash Console in Dashboard, it works fine!

https://ibb.co/GxnhDMx

mysql -u kamus5 -h kamus5.mysql.pythonanywhere-services.com  -p 'kamus5$comment2'

I am also trying to connect MySQL database using PythonAnywhere using this connection string :

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format( username="kamus5", password="Mm688688", hostname="kamus5.mysql.pythonanywhere-services.com", databasename="kamus5@comment2",)

app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI

app.config["SQLALCHEMY_POOL_RECYCLE"] = 299 app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

Moreover, I switched the following ports: 299 to 3306 without success. It turns out Something went wrong :-( ... In my case, what is the connection string for PA to connect MySQL? Any help for this issue? I followed part 1 "A beginner's guide to building a simple database-backed Flask website on PythonAnywhere"

Thank you very much for your guidance.

Regards, Kamus

databasename should be kamus5$comment2 like in the bash command above not kamus5@comment2 like in the connection string you pasted above.

fjl, this is my first website. With your valuable help, I finally got it. I had this issues for a few days. Without you, probably I can't make it. Thank you so much! Kamus

Glad to hear that you made it work!