Hey guys! I can’t get, how to establish connection to my local My SQL database using st.experimental_connection() from my cloud app by getting user input…
This we would save things in secrets and handle without any credentials if we need to establish connection to our own MySQL server but what if I need to give access to user so that they can input their credentials and establish conn to their own local MySQL server?
I have tried item assignment to secrets dict as well but not so surprisingly I got a type error saying secrets don’t support item assignment
Thanks for posting!
Do you have some code snippets or repo to share for the community to troubleshoot?
I think this could pose a security challenge for the users to enter their credentials to their db on your site unless you’ve implemented some robust encryption.
If it’s just for testing/dev, maybe add code to check if secrets exist, and if not, then ask the user to enter and pass it back to the connection.
Once you share more details and example code, then we can probe it better.
I haven’t made any code on that lines, as I couldn’t do it @tonykip…I understand that this could pose security issues. But there should be some way in which streamlit has to manage user credentials as well right?
This actually is not for testing purpose but asking for generic use cases where if user feels like they need to establish connection to their local db while using my cloud app, then experimental_connection can’t offer such thing right?
Maybe consider this project Business Card - ETL, where I am providing business card text extraction facility to user… This will work well if user clone and use it, provided, they have either global or local secrets file and provided the structure of the card is as expected by the program… Otherwise if they want to use my cloud app, then they can’t be able to input their own username and password when I use st.experimental_connection…
Here in this project I refrained from using experimental_connection because of that reason and as you can see in the home page of this repo, I have another file which provides access to my own mongodb atlas db in order to support the cloud version of my app… This is what all I was talking about…
Simplifying things: There might be some scenario where user might want to import or export data from my cloud app to their local db. In those kinda situation, how can we establish connection to user’s local db while using same st.experimental_connection…
Hope this makes things clear… If not please feel free to ask more info…
Thanks and Regards,
Hi @Nirmal_Kumar , how are you?
Did you find a way to solve your problem?
I am facing a very similar situation…
@tonykip, hope you are doing well,
I have a similar problem. Actually, is it possible to provide to us a tutorial of “How to deploy project with streamlit and MySQL” ? I found only a documentation related to a local project on streamlit Documentation (Connect Streamlit to MySQL - Streamlit Docs).
Im my case, I have a sucessfull connection between MySQL remote dabatase and streamlit local project.
But when I try to deploy the project on streamlit web, I get some errors. I didn’t find a single person that did it sucessfully and posted on internet. We are really trying to discover how we can do a connection like that.
Thanks for posting!
Have you tried out the recent updates with
Try it out using this demo in the docs → Connect Streamlit to MySQL - Streamlit Docs
I said about this !
@tonykip , could you help me, please?
Thanks for the clarification, for some reason I couldn’t see the previous thread when I responded.
So a deployed app cannot access your local instance of MySQL database directly. The main reason for this is that your local machine is most likely behind a router and a firewall that blocks incoming connections from the internet for security reasons. If you proceed with port forwarding to get incoming connections to port 8501, then you will end up exposing your local network to potential security threats; not advisable.
A more robust solution is to use a cloud database instance like AWS RDS which is already designed to be securely accessible.
Hello @tonykip !
My database is not local, is on a webserver. I can connect to this remote database when my streamlit project is local. But when I deploy the streamlit project, I receive some errors and I didn’t find on the documentation how can I do this. Even if the MySQL database is NOT LOCAL, streamlit isn’t capable of connect?
Updating from here… I found a way to do this connection, but I can’t do an authentication user with data from my MySQL remote database.