Hi,
From my streamlit UI application, Im trying to connect to MYSql database. Below is the code snippet for fetching the connection.
@st.cache(allow_output_mutation=True, hash_funcs={"_thread.RLock": lambda _: None})
def init_connection():
database = config[“database”]
return mysql.connector.connect(**config)
conn = init_connection()
Not sure what is the issue, but sometimes Im seeing SQL Connection not available. When I redeploy the application, able to get the connection.
Below is the code snippet how Im using this connection
def run_query():
with conn.cursor() as cur:
query = f"SELECT * FROM {database}.employee"
cur.execute(query)
return cur.fetchall()