LightYear
/Docs
DocsTroubleshootingResolve MySQL Connection Errors

Resolve MySQL Connection Errors

Fix common MySQL connection errors including too many connections, access denied, and lost connection.

intermediate
8 min read
LightYear Docs Team
Updated April 24, 2026
mysqldatabaseconnectiontroubleshooting
Ready to get started?

MySQL connection errors are among the most common application issues. This guide covers the most frequent errors and their resolutions.

Error: Too Many Connections

Symptoms: ERROR 1040 (HY000): Too many connections

Cause: The number of simultaneous connections has reached max_connections.

Check current connections:

>_BASH
$mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected';"
OUTPUT
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 151   |
+-------------------+-------+
>_BASH
$mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"
OUTPUT
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+

Resolution: Increase max_connections:

>_BASH
$mysql -u root -p -e "SET GLOBAL max_connections = 300;"

To make it permanent, edit /etc/mysql/mysql.conf.d/mysqld.cnf:

INI
[mysqld]
max_connections = 300

[!NOTE] Increasing max_connections requires more RAM. Each connection uses approximately 1 MB. Consider using a connection pooler (ProxySQL, PgBouncer) for high-traffic applications.

Error: Access Denied

Symptoms: ERROR 1045 (28000): Access denied for user 'user'@'host'

Cause: Wrong password, user does not exist, or the user is not allowed to connect from that host.

Check user grants:

>_BASH
$mysql -u root -p -e "SELECT user, host FROM mysql.user WHERE user='myapp_user';"
OUTPUT
+------------+-----------+
| user       | host      |
+------------+-----------+
| myapp_user | localhost |
+------------+-----------+

If the application connects from 10.0.1.10 but the user is only allowed from localhost, add the correct host:

SQL
CREATE USER 'myapp_user'@'10.0.1.10' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON myapp.* TO 'myapp_user'@'10.0.1.10';
FLUSH PRIVILEGES;

Error: Lost Connection

Symptoms: ERROR 2013 (HY000): Lost connection to MySQL server during query

Cause: Query timeout or packet size exceeded.

Check and increase timeouts:

>_BASH
$mysql -u root -p -e "SHOW VARIABLES LIKE 'wait_timeout';"
INI
[mysqld]
wait_timeout = 600
interactive_timeout = 600
max_allowed_packet = 64M

Check MySQL Error Log

>_BASH
$tail -50 /var/log/mysql/error.log

Monitor Slow Queries

Enable the slow query log to find performance bottlenecks:

INI
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
>_BASH
$tail -f /var/log/mysql/slow.log

Was this article helpful?

Your cookie choices for this website

This site uses cookies and related technologies, as described in our privacy policy, for purposes that may include site operation, analytics, and enhanced user experience. You may choose to consent to our use of these technologies, or manage your own preferences. Cookie policy