r/flask • u/73200021220 • 4d ago
Ask r/Flask Error while connecting to MySql database in PythonAnywhere.
3
u/Choppin22g 4d ago
Like the above user, if you can connect from a client like MySQL workbench or dBeaver then we can start from there
2
u/73200021220 4d ago
I followed there instructions and was able to connect to MySQL workbench. Thats how I setup my schema.
Flask app also is able to connect to the database in local dev env.I cloned the the repo into pythonanywhere. Created venv. Installed all requirements. But it dose not connect to the database.
2
u/Choppin22g 4d ago
If it’s a MySQL database, I’m thinking your port is off if the default was not changed. Try 3306
1
u/73200021220 4d ago
Repo - https://github.com/ZafirChowdhury/b2bWeb
Cloned my repo. Added the ssl.ca and key.py manually.
I store my passwords and api keys there.I double checked port is fine.
2
u/Choppin22g 4d ago
What authentication plugin is your user using?
0
u/73200021220 4d ago
I am not sure what are you asking.
But here is my database connection code.
I am using mysql connector for python.
import mysql.connector
import key
ssl_ca = "/ca.pem"
db = mysql.connector.connect(
host = "b2b-zafirchowdhury69-c101.j.aivencloud.com",
port = 10728,
user = "avnadmin",
password = key.get_database_password(),
database = "b2b",
ssl_ca=ssl_ca
)
1
u/Choppin22g 4d ago
So you can connect to that database using a database client from your computer?
1
u/73200021220 4d ago
Yes.
I can connect with MySQL workbench.
I can connect it with my flask development server.1
u/Choppin22g 4d ago
I found that in their website they recommend using flask, sequel alchemy to connect to their database, and this is what their connection string would look like
‘mysql://<your_username>:<your_mysql_password>@<your_mysql_hostname>/<your_database_name>’
1
1
u/Choppin22g 4d ago
not sure if you have a paid account of not but i send a link to you below this comment
1
u/73200021220 4d ago
I have the opposite problem. I cannot access my external MySQL server from pythonanywhere.
→ More replies (0)
1
3
u/SpaceParmesan 4d ago
Well this is not a lot of info to go off of. First, is this database you are trying to access public, or is it behind some protection?
Can you sign into the mysql from your local computers terminal?