Streamlit with MariaDB

I’m doing a school project and we’re supposed to make an app that connects to the database our professor gave us. The server type is MariaDB.

Assuming it works similar to MySQL and that I’ve seen guides on how to connect to MySQL servers in streamlit, I gave streamlit a try. I used the same method when connecting to MySQL servers to connect to the MariaDB server of my professor.

When I run the app, there are no errors. Just endless running of the connection initialisation to the server.
Running app_func.<locals>.init_connection()

under secrets.toml, i tried enabling and disabling these two testing if these were the errors. and got no luck

Anyone else tried MariaDB servers with streamlit? or knows if MariaDB is compatible with streamlit

enableCORS = true
1 Like

For sure, it is possible to use also MariaDB together with streamlit.

  • Where does your Streamlit app run?
  • Where does your MariaDB run?
1 Like

My streamlit app runs on streamlit server, and the MariaDB runs on the school server our prof gave us access to.

I tried connecting MySQL online database from another thirdparty site and it works. So my code is working, but the initialization to the MariaDB server isn’t.

  • Can you share some code?
  • Which python library do you use for the connection to MariaDB?

Maybe here you can find some more hints:

Streamlit cloud face issue in mysqlclient installing - #2 by snehankekre

i used “mysql.connector”. just followed the guide in

the following is the function which connects to the database.

def app_func():
    def init_connection():
        return mysql.connector.connect(**st.secrets["mysql"])

    conn = init_connection()

I think this is the part where my code gets stuck

checked the link.

yes i did use mysql-connector-python too (i have it on my requirements.txt). Still the same. Function keeps running endlessly.

Can you give examples of how to connect to a remote MariaDB server? Or maybe does this really only work for MySQL.

i found this list showing the compatible databases and APIs to streamlit, and didnt find MariaDB. maybe it really is unsupported?

To my knowledge there should be no difference in this regard and mariadb should work. But I am not a database specialist.

I would proceed step by step:

  • Write a simple mariadb access (without streamlit) in python and test it on your local machine.
  • Add streamlit and then test that on your local machine.
  • Only then deploy to streamlit cloud and test there.
1 Like

This is correct. To the extent that we have database tutorials in the docs, it’s because someone wrote them, not that Streamlit allows/disallows any given database.

Problems of this nature are frequently due to firewall access or other networking security issues, there is nothing on the Streamlit core Python side or Streamlit Cloud that specifically disallows MariaDB.



Thank you. The issue was on the database server’s end not trusting streamlit’s IP so I had to request to allow streamlit’s stable outbound IP addresses to be whitelisted.