When you have a web application (site, blog, forum, etc.) that has high demand, meaning a large number of users visit it, this translates into increased server consumption. If the web app uses a MySQL – MariaDB database and the queries are extremely high (due to poor web programming or a large number of users using the site), there’s a chance that MySQL – MariaDB will display this error:
1 2 3 | ..... mysqli_connect(): (HY000/1040): Too many connections ..... |
What does the error MySQL – MariaDB: Too Many Connections mean?
It means that too many requests are coming into MySQL – MariaDB, more than it can accept, more than it can queue or wait for.
How to fix it?
Simple, we need to increase the maximum limit for requests (connections) that MySQL – MariaDB support. To fix this problem:
Edit config file for MySQL – MariaDB.
If have a distro from RHEL (RedHat, Fedora, Centos, CentOS Stream, AlmaLinux, Rocky, etc):
1 | /etc/my.conf.d/server.cnf |
If have a distro from Debian (Kubuntu, Ubuntu, etc):
1 | /etc/mysql/my.cnf |
EDIT:
1 2 | max_connections = 500 max_user_connections = 10 |
This will increase the maximum number of total connections from 100 (which is the default) to 500 and to a maximum of 10 connections per user (meaning database users, not visitors).
We save and exit, then restart the MySQL – MariaDB service, and that’s it. This change is permanent.