+3 votes
in Databases by (14.6k points)

I am trying to optimize the tables of my database from PHPMYADMIN, but It gives the following error: "MySQL error 2006: mysql server has gone away". How can I fix this error?

1 Answer

0 votes
by (23.4k points)

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

  • Restart MySQL

# systemctl restart mariadb.service

or

# systemctl restart mysql.service

If you still get the same error, increase the value of wait_timeout.

...