Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of connection timeout after 8 hours of idle time in mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report