MySQL disconnects automatically after some time.
If you experience MySQL timeouts, it could be due to heavy or very long MySQL queries.
You can try using mysql_reconnect command before every query, and it should be fine.
MySQL server timeout can occur for many reasons but most commonly it is caused by either an application bug, a network timeout issue, or due to the MySQL server restarting.
These steps could solve the issue. (By setting no time to MySQl.)
- Edit your my.cnf (MySQL config file)
sudo nano /etc/mysql/my.cnf
- Add the timeout configuration and adjust it to fit your server.
wait_timeout = 28800 interactive_timeout = 28800
- Save the changes (CTRL +
X , Y ,ENTER)
- Restart MySQL
sudo service mysql restart
The new changes will be applied once it restarts. Hope this will help you.