It may be possible that your database is very heavy (i.e. many records) and the value of variable wait_time is very low in the MySQL configuration file. Although the default value of wait_time is 28800 seconds, do not set such high value as a bad code can cause issues. Here are the steps:
- If you have root access, open my.cnf (MySQL) or mariadb.cnf (MariaDB) in an editor.
# vi /etc/mysql/mariadb.cnf
- Update the following variables.
net_read_timeout=60
net_write_timeout=60
connect_timeout=60
wait_timeout=120
interactive_timeout=150
long_query_time=10
# systemctl restart mariadb.service
or
# systemctl restart mysql.service
If you still get the same error, increase the value of wait_timeout.