Software⏱️ 4 min read📅 2026-06-15

How to Fix: mysql version 8.0.11 and Symfony 4 error "MySQL server has gone away"

Error fixing MySQL server has gone away in Symfony 4 with MySQL version 8.0.11.

Quick Answer: Adjust MySQL variables wait_timeout and max_allowed_packet in the my.cnf file to resolve the issue.

The error 'MySQL server has gone away' is a frustrating issue that affects Symfony 4 users who are using MySQL version 8.0.11 and connecting to their database using a user account instead of the root login. This error occurs when the MySQL server times out after a certain period of inactivity, causing the connection to be lost and resulting in an error message.

This issue can be particularly challenging to resolve, especially for those who are not familiar with MySQL configuration settings. However, by following the steps outlined below, you should be able to identify and fix the root cause of this problem.

🔍 Why This Happens

  • The primary reason why this error occurs is due to an incorrect configuration of the MySQL server variables 'wait_timeout' and 'max_allowed_packet'. These variables control how long the server waits for a client to send data before timing out, and the maximum amount of data that can be sent in a single packet, respectively.
  • Another possible cause of this error is if the MySQL connection is not being properly closed after use. This can happen when the application or script is not properly handling the connection, causing it to remain open indefinitely.

🚀 How to Resolve This Issue

Adjusting MySQL server variables

  1. Step 1: Open the file '/etc/mysql/my.cnf' in a text editor and locate the section that starts with '[mysqld]'. This section contains various configuration options for the MySQL server.
  2. Step 2: Search for the 'wait_timeout' variable and set its value to a higher number, such as 3600 (1 hour). This will increase the time the server waits for client activity before timing out. Also, search for the 'max_allowed_packet' variable and set its value to a higher number, such as 1024K (1MB).
  3. Step 3: Save the changes to the file and restart the MySQL server to apply the new configuration. You can do this by running the command 'service mysql restart' or 'systemctl restart mysql' depending on your Linux distribution.

Ensuring proper connection closing

  1. Step 1: Check your application or script code to ensure that the MySQL connection is being properly closed after use. This can be done by adding a 'close' statement after each query or operation.
  2. Step 2: If you are using an ORM (Object-Relational Mapping) tool like Doctrine, make sure that it is properly configured to handle connections and close them when necessary.

✨ Wrapping Up

By following these steps, you should be able to resolve the 'MySQL server has gone away' error in Symfony 4. Remember to regularly check your MySQL configuration settings and ensure that your application or script is properly handling connections to avoid this issue in the future.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions