Home > Software engineering >  How to change the default link time of pymysql
How to change the default link time of pymysql

Time:10-31

In my project, I used pandas and pymysql to read the database. The default setting is that pymysql will automatically disconnect after 8 hours if you do not perform any operation after creating a link.

I used close () to close the link, but the database shows that the link exists and has not been operated for more than 80000 seconds

python 3.10.5

I tried to close it with close(), but it didn't seem to work

CodePudding user response:

I gauss you can try to change "wait_timeout" in mysql system setting which default is 28800s

CodePudding user response:

To set the timeout for read and write mysyql operations, use the following parameters that can be passed to pymysql.connections.Connection(..) when you establish the connection:

read_timeout – The timeout for reading from the connection in seconds (default: None - no timeout) Similarly, you have: write_timeout – The timeout for writing to the connection in seconds (default: None - no timeout)

  • Related