Databases 10 min read

Resolving MySQL “Server Has Gone Away” for a Read‑Only User: The Impact of init_connect and SUPER Privilege

The article explains why a newly created read‑only MySQL 5.7 user receives a “MySQL server has gone away” error, analyzes the role of the init_connect variable and SUPER privilege, and provides a step‑by‑step fix by correcting the init_connect setting.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Resolving MySQL “Server Has Gone Away” for a Read‑Only User: The Impact of init_connect and SUPER Privilege

A colleague created a read‑only MySQL 5.7 user with create user 'readuser'@'%' identified by 'readuser'; and GRANT SELECT ON *.* TO 'readuser'@'%' IDENTIFIED BY "readuser"; , but logging in with mysql -ureaduser -preader returned the error “MySQL server has gone away”. The MySQL process was running, root could connect, and even TCP/IP connections failed.

Reference to the official MySQL documentation (B.3.2.7) lists many possible causes, including server timeout, killed threads, insufficient privileges, client‑side timeouts, oversized packets, and errors in the init_connect command.

After exhaustive checks, the author discovered that granting the SUPER privilege to the new user ( grant super on *.* TO 'readuser'@'%'; ) allowed the login, indicating that the problem was related to init_connect . The variable was set to the literal string 'SET NAMES utf8mb4' (including the single quotes), which caused a syntax error for non‑SUPER users during connection initialization.

Running show variables like '%init_connect%'; confirmed the value. The MySQL error log showed the same syntax error, proving the root cause. The correct fix is to set a proper init_connect value without stray quotes:

set global init_connect = "set names utf8mb4";

With the corrected init_connect , the read‑only user can connect without needing SUPER privileges. The article also notes that init_connect is executed for every non‑SUPER connection, making it a common source of hidden login failures when misconfigured.

In emergency situations, fixing the init_connect variable resolves the immediate issue, but understanding the underlying mechanism helps prevent similar problems and improves overall DBA troubleshooting skills.

MySQLtroubleshootinginit_connectRead-Only Userserver-gone-awaySUPER privilege
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.