Hi folks, happy Monday. I am attempting to deploy my application which connects to a Google Cloud MySQL database. My application uses pymysql to query the database. I am not entirely sure how to pass the secrets.toml contents to the pymysql.connect() argument.
Has anyone successfully used Secrets in pymysql? Thanks so much!
Hi @thanks_paul , and welcome to the Streamlit community!
Have you tried passing your secrets variables where required in pymysql.connect()?
Maybe @BeyondMyself can help, as I believe he recently managed to deploy an app relying on pymysql, see related post here:
import streamlit as st
import pymysql
import pandas as pd
import webbrowser as web
username=st.text_input(âPlease input your username:â)
pwd=st.text_input(âPlease input your passwordâ,type=âpasswordâ)
db = pymysql.connect(host=âlocalhostâ, user=ârootâ, password=âabcdeâ, database=âpythonâ, charset=âutf8â)
sql=âselect * from pwdâ
cursor = db.cursor()
cursor.execute(sql)
db.commit()
df=pd.read_sql(sql,con=db)
if username=="":
st.info(âYou do not have input user name yetâ)
elif pwd==""âŚ
Charly
@thanks_paul @Charly_Wargnier
yes, use pymysql to connect the database is a mature solution.
see the link:
import streamlit as st
import pymysql
import pandas as pd
import webbrowser as web
username=st.text_input(âPlease input your username:â)
pwd=st.text_input(âPlease input your passwordâ,type=âpasswordâ)
db = pymysql.connect(host=âlocalhostâ, user=ârootâ, password=âabcdeâ, database=âpythonâ, charset=âutf8â)
sql=âselect * from pwdâ
cursor = db.cursor()
cursor.execute(sql)
db.commit()
df=pd.read_sql(sql,con=db)
if username=="":
st.info(âYou do not have input user name yetâ)
elif pwd==""âŚ