Overview
This article provides steps to resolve the "MySQL server has gone away" error encountered by Amavis when connecting to a MariaDB database. The issue typically occurs when the database server terminates idle persistent connections before Amavis can reuse them.
Symptoms and Cause
The mail log displays the following Amavis notification:
Aug 3 01:00:20 el7p17 amavis[114160]: (114160-02) NOTICE: reconnecting in response to: err=2006, HY000, DBD::mysql::st execute failed: MySQL server has gone away at (eval 130) line 173.
This error indicates that Amavis attempted to use a persistent database connection that was dropped by the MariaDB server due to timeout settings. Consequently, Amavis must re-establish the connection.
Resolution
To prevent premature connection drops, adjust the wait_timeout parameter in your MariaDB configuration files. Follow these steps:
- Open the primary configuration file located at /etc/my.cnf.
- Verify that no conflicting values exist within the /etc/my.cnf.d/ directory, as files in this directory may override default settings.
- Add or modify the [mysqld] section to include the recommended timeout value:
[mysqld]
wait_timeout = 28800
- Save the configuration file.
- Restart the MariaDB service to apply the changes:
systemctl restart mariadb
Troubleshooting and Verification
After restarting the service, monitor the mail logs to confirm that Amavis successfully maintains persistent connections without triggering reconnection notices. If the error persists:
- Confirm that the MariaDB service is running correctly.
- Check for additional timeout parameters such as interactive_timeout or connection pool limits in your application configuration.
- Review system resource utilization to ensure the database server is not terminating connections due to memory constraints.