Get your free beta license ↗
Databases · MariaDB

The database refuses connections with “Too many connections”

Last updated 30 Nov 2026
Summary

MariaDB refuses site and client connections with ERROR 1040 (08004): Too many connections when it reaches max_connections, which defaults to 151. To fix it, find what holds the connections and raise the limit if the server has enough memory.

Symptoms

Clients receive this error when they try to connect.

Output
ERROR 1040 (08004): Too many connections

WordPress and other applications show their database connection errors at the same time.

Cause

MariaDB accepts up to max_connections connections at once. The distribution sets it to 151, and UrbeStack leaves that value to you.

A slow query, a site under heavy load, or connections an application leaves open can fill the available slots.

Resolution

  1. Run these commands as root to see the peak number of simultaneous connections since MariaDB started and what holds the connections now. MariaDB allows one additional connection for an administrator.

    mariadb -N -e "SHOW GLOBAL STATUS LIKE 'Max_used_connections'"
    mariadb -e "SHOW PROCESSLIST"
  2. In the process list, the User and db columns show which site holds each connection. The Time column shows how long each has run.

  3. Each connection uses memory. Raise the limit only as far as the server's memory allows. This command raises it to 300 immediately, until MariaDB restarts.

    mariadb -e "SET GLOBAL max_connections=300"
  4. To keep the setting after a restart, add max_connections = 300 under [mysqld] in /etc/my.cnf.d/mariadb-server.cnf on AlmaLinux or /etc/mysql/mariadb.conf.d/50-server.cnf on Ubuntu. Then run urbestack-service-restart --name mariadb.