How to solve the problem of connection timeout after 8 hours of idle time in mysql
I would like to share with you how to solve the problem of connection timeout after 8 hours of free time in mysql. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it.
Solve the problem of connection timeout after 8 hours of idle time in mysql
I found a rule in the project that when the application program and the connection are established, if the application sentence does not access the database for more than 8 hours, the database will be disconnected. At this point, a second visit will throw an exception.
1. The general solution is to add the "autoReconnect=true" option to the database connection string. But this only works for versions prior to 4. It is not valid in the latest mysql. In fact, there is also a simple way to solve this problem, which is to modify the startup parameters of mysql. By default, the timeout time for mysql is 28800 seconds, which is exactly 8 hours. Just add a 0.
Similarly, you can add this parameter to the "my.ini" file.
Mysqld-nt-default-table-type=innodb-interactive_timeout=288000
2. Starting from the root cause, set the wait_timeout of mysql to 31536000 (one year).
Www.2cto.com
Mysql > show variables
| | wait_timeout | 28800 |
| | interactive_timeout | 28800 |
Modify this parameter in the "my.ini" file
[mysqld]
Wait_timeout=31536000
Interactive_timeout=31536000
Restart the service, OK!
The above is all the contents of this article entitled "how to solve the problem of connection timeout after 8 hours of idle time in mysql". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!