How long does a python3 mysql connection remain active?

Viewed 44

I have a python3 script that uses a global $CONN variable as a MySQL connection. But MySQL connection breaks automatically sometimes. Is there any time limit for MySQL connection in python3?

1 Answers

You can set the connection times as follow:

con.query('SET GLOBAL connect_timeout=28800')
con.query('SET GLOBAL wait_timeout=28800')
con.query('SET GLOBAL interactive_timeout=28800')

The numbers are in seconds, so 28800 seconds = 8 hours.

If you want to see the currently configured times, execute this query on the database:

SHOW VARIABLES LIKE '%timeout';

Related