Overriding MySql Max Connections
by z3n on Apr.06, 2010, under Tips & Hints
Problem:
MySQL has reached max connections and you can’t login, even being root.
Solution:
You can either edit my.cnf raising the limit and logging in or you can do this hack:
gdb -p $(cat /var/run/mysqld/mysqld.pid) \ -ex "set max_connections=5000" -batch
What’s the difference?
By changing my.cnf you will need to restart the server, if you got the limit reached long time ago lots of queued connections will instantly flood the server once you reset it, making impossible to access it within a few seconds. So you will need to keep restarting it over and over again until all the queue is gone. In some cases you can’t even restart it, server gets stuck trying to close connections, then you need to kill mysqld, but that can generate broken tables. Sometimes only a full system restart fixes the issue.
By changing the value with the hack, you will be able to raise the max connections without restarting mysqld, which allows you to login and check what’s going on, even run some scripts to clean up idle/stuck connections, making things easier.