Databases 9 min read

Using GDB to Adjust MySQL max_connections Without Restart

This article explains how to troubleshoot and resolve the MySQL "Too many connections" error by using GDB to modify the max_connections parameter on a running MySQL 5.7 instance without restarting, including step‑by‑step commands, sysbench load testing, and two practical methods.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Using GDB to Adjust MySQL max_connections Without Restart

Background

In daily MySQL operations, unreasonable parameter settings can cause various issues. A common problem is an improperly set maximum connection count, which leads to "Too many connections" errors during traffic spikes.

Error Information

ERROR 1040 (HY000): Too many connections

Cause

The issue is simply that concurrent connections exceed the configured max_connections limit.

Solution

Reset the value of max_connections .

Pain Points

When the error Too many connections appears, the MySQL client cannot modify the connection count dynamically.

Changing the configuration and restarting the server makes the new max_connections value take effect, but restarting is often unacceptable in production.

GDB Tool

To avoid restarting, we use the gdb tool to modify MySQL parameters on‑the‑fly.

gdb is typically a debugger, but it also supports online modification of configuration variables.

Process

We simulate a MySQL instance where the connection limit is reached and then use gdb to adjust it.

1. Prepare a MySQL 5.7.40 instance.

2. Create an empty database jiangshifeng .

mysql> create database jiangshifeng;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| jiangshifeng       |
| mysql              |
| performance_schema|
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use jiangshifeng;
Database changed
mysql> show tables;
Empty set (0.00 sec)

3. Set the instance's max_connections to 10.

mysql> set global max_connections=10;
Query OK, 0 rows affected (0.01 sec)

mysql> show variables like '%max_conn%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 100   |
| max_connections    | 10    |
+--------------------+-------+
2 rows in set (0.00 sec)

4. Install gdb :

yum install -y gdb

5. Use sysbench to generate load: create 11 tables with 20,000,000 rows each and 15 client threads.

sysbench /usr/share/sysbench/oltp_common.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=jiangshifeng --db-driver=mysql --tables=11 --table-size=20000000 --report-interval=15 --threads=15  prepare

6. After the load, connecting with the MySQL client yields the error:

ERROR 1040 (HY000): Too many connections

7. Modify max_connections using gdb :

Method 1

gdb -p $(pidof mysqld) -ex "set max_connections=50" -batch

Method 2

# Find MySQL process ID
ps -ef | grep mysql
# Attach gdb to the process
gdb -p 1582
(gdb) p max_connections
$1 = 10
(gdb) set max_connections=50
(gdb) p max_connections
$4 = 50
(gdb) q

8. Verify the change by reconnecting; max_connections is now 50 and the sysbench workload continues normally.

mysql> show variables like '%max_conn%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 100   |
| max_connections    | 50    |
+--------------------+-------+
2 rows in set (0.10 sec)

Summary

We demonstrated how to use gdb to modify max_connections without restarting MySQL; the same approach can be applied to other parameters.

Although the experiment succeeded, such operations carry unknown risks and should not be considered foolproof.

Proper capacity planning and adherence to best practices are essential to avoid hitting connection limits.

Setting max_connections too high can cause resource exhaustion; load testing helps determine an appropriate value.

MySQLTroubleshootingGDBDatabase Tuningsysbenchmax_connections
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.