Skip to content

MySQL Connection not available after sometime #260

Answered by assinchu
assinchu asked this question in Q&A
Discussion options

You must be logged in to vote

If someone is having similar issue: They can use below snippet to re connect to MySQL when there is disconnect

vn = MyVanna(config={'api_key': '', 'model': 'gpt-3.5-turbo'})

conn_details = {
'user': '',
'password': '',
'host': '',
'database': ''
}
import mysql.connector

def connect_to_mysql(conn_details):
try:
# Establish a connection
conn = mysql.connector.connect(**conn_details)
if conn.is_connected():
print('Connected to MySQL database!')
# Print the connection details
print('Connection details:', conn_details)
return conn
except mysql.connector.Error as e:
print(f'Error connecting to MySQL database: {e}')
return None

Connect to MySQL

connection = connect_to_mysql(conn_details)

You def…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@andreped
Comment options

@assinchu
Comment options

@assinchu
Comment options

Answer selected by zainhoda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants