How do I fix the error “Mysql Server has gone away”?
The MySQL server has gone away (error 2006) has two main causes and solutions:
- Server timed out and closed the connection. To fix, check that
wait_timeoutmysql variable in your my.cnf configuration file is large enough, eg
wait_timeout = 28800
- You may also need to increase the
innodb_log_file_sizemysql variable in your my.cnf configuration to for example
innodb_log_file_size = 128MBor higher.
- Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. To fix, you can increase the maximal packet size limit
max_allowed_packetin my.cnf file, eg. set
max_allowed_packet = 128M, then restart your MySQL server:
sudo /etc/init.d/mysql restart
- Database server ran out of space. This can occur when performing an update to the Matomo database that requires DB Schema changes (Especially for large databases).
Once you’ve made these changes, and restarted your MySQL or MariaDB server, the issue should be fixed and no more error triggered. If not, try increase the
128M values to
256M for example. In websites with a lot of traffic and data, you might even need to increase the value to
If the above changes do not resolve the issue and if you are using MYSQLI adapter in Matomo, try switching to
adapter = PDO\MYSQL in your
You may be interested to learn more about Matomo Analytics to measure your websites and apps and keep control of your analytics data.
Thanks for contacting us! We will get in touch with you shortly.