i have a python script that its always on runing on background
nohup python script.py &
so what script does is: it check on mqtt if any message there and if true it insert it on Database
on_message(client, userdata, msg):
SQL.execute("INSERT INTO logs(deviceID) VALUES (msg)")
i use this way to connect to db but after few hours connection is closed and script is running but its not able to insert to db
mydb = mysql.connector.connect(host="localhost", user="xxxx", passwd="xxxx", database="xxx")
SQL = mydb.cursor()
Questions:
- do i need to open new connection every time before SQL.execute() or better to keep it open?
- can u add code that u think is better to use