Dash connect mysql

I have a multi-page Dash application. For now, in each page, I will put connect mysql in the callbacks.
I want to set up a connection to mysql ( work for all pages ) and keep it forever . In callbacks, I just need to write sql query. Is there any way to do that?

Are you saying you want to create an initial connection to a mysql database then run queries in callbacks? Or are you looking to set up a new connection each time there is a callback.

Assuming the first, which makes more sense, you should be able to just connect to the database once at startup by putting

import mysql.connector

mydb = mysql.connector.connect(YOURREDENTIALS)

mycursor = mydb.cursor()

Then inside callback functions run whatever queries you’d like