Cannot connect to MySQL

I have looked at the MySQL issues posted here but I am unable to find a resolution. I have created my app using codespaces on the browser and i dont have a local version of my app running on my computer and only using Streamlit cloud. It seems I am making a mistake with the DSQL configurattion information and I cannot figure out what it is.
Below is my code, the requirements.txt file and secrets.toml which I have added to the settings under the secrets tab.

Python Code
import streamlit as st
import sqlalchemy

Everything is accessible via the st.secrets dict:

st.write(“DB username:”, st.secrets[“db_username”])
st.write(“DB password:”, st.secrets[“db_password”])
st.write(st.secrets)

Initialize connection.

#conn = st.connection(‘mysql’, type=‘sql’)
conn = st.experimental_connection(‘dbx’, type=‘sql’)

Perform query.

#df = conn.query(‘SELECT * from Individual;’, ttl=600)
dbxx = conn.query(‘SELECT * from Individual’)

Print results.

#for row in df.itertuples():

st.write(f"{row.FirstName} has a :{row.Ethnicity}:")

st.dataframe(dbxx)

SECRETS in settings of app
[connections.dbx]
type=“sql”
dialect=“mysql”
username=“xxxxxx”
password=“XXXXXXXXX”
host=“mysql-xxxxxxxxxxx.us-east-1.rds.amazonaws.com
port=3306 # Port number
database=“DivIndexXXXX”

Results and Error :
DB username: xxxxx
DB password: XXXXXXXXX

{'type': 'sql', 'dialect': 'mysql', 'db_username': 'xxxxx', 'db_password': 'XXXXXX', 'host': 'mysql-xxxxxxxxxxxxxx.us-east-1.rds.amazonaws.com', 'port': 3306, 'database': 'DivIndexXXXX'}

StreamlitAPIException: Missing SQL DB connection configuration. Did you forget to set this in secrets.toml or as kwargs to st.connection?
Traceback:

File "/workspaces/Streamlit/streamlit_app.py", line 111, in <module>
    conn = st.experimental_connection('dbx', type='sql')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  • Why do you use deprecated st.experimental_connection instead of st.connection?
  • Based on the error message, I suspect that the secrets are not formatted correctly and are therefore not recognized.

Thanks @Franky1 . I have now changed the connection from experimental_connection.
I am going to look at my secrets file formatting line by line. The only thing I can see that may be a problem is that the url for my host carries over to the next line as below. Is that a problem and if it is, whats the syntax for the formatting if it carries over to a second line?

[connections.dbx]
type=“sql”
dialect=“mysql”
username=“admin”
password=“Gusmao12#”
host=“mysql-odago1.c7qqsqywxqpq.us-east-1.
rds.amazonaws.com
port=3306 # Port number
database=“DivIndex01”

And I have put it into a toml parser and i got confirmation that it is valid . Pls see attached . Ignore the misplaced arrow on the screenshot

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.