Categories
SysOps

How to increase the maximum permitted connections to MariaDB server

Increase the maximum permitted number of simultaneous connections to the MariaDB server.

The moment you see the following message will mean that you have reached the concurrent connections limit.

ERROR 1040 (HY000): Too many connections

Inspect the current limit of simultaneous connections.

$ sudo mariadb --skip-column-names --batch --execute 'show variables like "max_connections"'
max_connections 164

Increase the current limit of simultaneous connections.

$ sudo mariadb --skip-column-names --batch --execute 'set global max_connections = 200'

Increase the current limit of simultaneous connections when the server is started.

$ echo -e "[mariadb]\nmax_connections = 201\n" | sudo tee /etc/mysql/mariadb.conf.d/51-max_connections.cnf
[mariadb]
max_connections = 200

Inspect the current limit of simultaneous connections.

$ sudo mariadb --skip-column-names --batch --execute 'show variables like "max_connections"'
max_connections 200

Inspect the maximum number of simultaneous connections since the server started.

$ sudo mariadb --skip-column-names --batch --execute 'show global status like "Max_used_connections"'
Max_used_connections    151

Inspect the number of connection attempts to the server.

$ sudo mariadb --skip-column-names --batch --execute 'show global status like "Connections"'
Connections     1293

Inspect the number of currently open connections.

$ sudo mariadb --skip-column-names --batch --execute 'show global status like "Threads_connected"'
Threads_connected       160