Iām new to streamlit and docker, so my question may be dumbā¦
Iāve used mysql.connector to connect to my local mysql database and I tried to make a docker image of my app.
Iāve followed the docs to make the docker image and the app can be opened, but here comes the error āDatabaseError: 2003 (HY000): Canāt connect to MySQL server on ālocalhost:3306ā (99)ā
The code works fine if I use the standard āstreamlit run app.pyā on the IDE
def authenticate_user(username, password):
db_connection = mysql.connector.connect(
host='localhost',
user= xxxxxxx,
password= xxxxxxx,
database="my_db"
)
cursor = db_connection.cursor()
query = f"SELECT * FROM login_info WHERE login_id = '{username}' AND login_password = '{password}'"
cursor.execute(query)
result = cursor.fetchone()
if result:
user_data = {
"name": result[1],
"department": result[2],
"id": result[4],
"permission": bool(result[5]),
}
is_superior_query = f"SELECT name1 FROM relationship WHERE name1 = '{result[1]}' AND relationship='up'"
cursor.execute(is_superior_query)
superior_employee = cursor.fetchone()
if superior_employee:
user_data['isLeader'] = True
else:
user_data['isLeader'] = False
cursor.close()
db_connection.close()
return user_data
else:
cursor.close()
db_connection.close()
return None
What do I need to do to make sure the mysql db can be correctly reached? And Iād love to know the answer for both the local db and the non-local ones bc eventually Iāll switch to the company db and company network and thatās why I need a docker to deploy the app rather than use the streamlit cloud services
Thanks in advance