Applies to: MySQL 8.4 and MariaDB 11.8; tested on MySQL 8.4.11 and MariaDB 11.8.9; configuration file paths checked in the Ubuntu 26.04, Debian 13 and AlmaLinux 10 packages
To see the connection limit, run this in the MySQL or MariaDB client (as root or an admin user):
SHOW VARIABLES LIKE 'max_connections';
+-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 151 | +-----------------+-------+
151 is the default on both MySQL and MariaDB. From the shell: sudo mysql -e "SHOW VARIABLES LIKE 'max_connections'" (on MariaDB, sudo mariadb works too).
1. See how close you are to the limit
SHOW GLOBAL STATUS WHERE Variable_name IN
('Threads_connected','Max_used_connections','Max_used_connections_time',
'Connection_errors_max_connections');
Threads_connected: connections open right now.Max_used_connectionsandMax_used_connections_time: the highest number since the server started, and when it happened.Connection_errors_max_connections: how many connections were refused because the limit was reached. Anything above 0 means users have seen the error.
To see which database user holds the connections:
SELECT user, COUNT(*) AS connections FROM information_schema.PROCESSLIST GROUP BY user;
2. What the error looks like
When every slot is taken, new connections get:
ERROR 1040 (08004): Too many connections
Both servers keep one extra connection for an administrator, so you can still log in and look. According to the MySQL manual, it is reserved for accounts with the CONNECTION_ADMIN (or old SUPER) privilege; MariaDB documents the same. In our tests, root got in while the server was full, and a second root connection was refused.
There are also per-user limits. If one account has too many connections, the error is different:
ERROR 1203 (42000): User app already has more than 'max_user_connections' active connections ERROR 1226 (42000): User 'app' has exceeded the 'max_user_connections' resource (current value: 1)
The first comes from the global max_user_connections setting, the second from a limit on the account itself (ALTER USER ... WITH MAX_USER_CONNECTIONS). On shared hosting these per-user limits are set by the host, and raising them is not the fix: find out why the site keeps so many connections open.
3. Change the limit for now
SET GLOBAL max_connections = 300;
This works at once, without a restart, and is lost when the server restarts. On MariaDB the lowest allowed value is 10: SET GLOBAL max_connections = 3 gave the warning Truncated incorrect max_connections value: '3' and set 10.
On MySQL you can save the change as well:
SET PERSIST max_connections = 300;
MySQL writes it to mysqld-auto.cnf in the data directory, and RESET PERSIST max_connections; removes it again. MariaDB doesn’t support SET PERSIST; it answers with ERROR 1064, a syntax error.
4. Change it permanently in the configuration file
Add the setting to the server section of the configuration file:
- MySQL on Ubuntu:
/etc/mysql/mysql.conf.d/mysqld.cnf(it contains a commented# max_connections = 151line). - MariaDB on Ubuntu and Debian:
/etc/mysql/mariadb.conf.d/50-server.cnf, or a new file such as60-connections.cnfin the same folder. - AlmaLinux and Rocky Linux:
/etc/my.cnf.d/mariadb-server.cnfor/etc/my.cnf.d/mysql-server.cnf.
[mysqld] max_connections = 300
Restart the database (sudo systemctl restart mariadb; for MySQL the service is mysql on Ubuntu and mysqld on AlmaLinux) and check again with SHOW VARIABLES. In our MariaDB test, the value from the file was active after the restart.
MariaDB and max_user_connections: if the server started with max_user_connections = 0 (the default, meaning no limit), you can’t change it at runtime. In our test, SET GLOBAL max_user_connections failed with:
ERROR 1290 (HY000): The MariaDB server is running with the --max-user-connections=0 option so it cannot execute this statement
Set it in the configuration file and restart; after that, SET GLOBAL worked. MySQL changed it at runtime without a restart.
How high should it be?
Raise the limit only when Max_used_connections really reaches it during normal traffic. According to the MySQL manual, every connection thread gets its own memory (a stack and connection and result buffers), so a very high value can make the server run out of RAM under load instead of refusing connections. Often the real cause is elsewhere: slow queries that keep connections busy, or an application that opens connections and never closes them. Idle connections show as Sleep in the process list; close them with wait_timeout rather than raising the limit. If the database keeps restarting under load, see MySQL or MariaDB crashes and restarts often. To find the configuration files on your server, see how to find MySQL, PHP and Apache configuration files.
Official documentation: MySQL: Too many connections and MariaDB server system variables.