MariaDB – raise number of connections

With Centos 7 come replacement of MySQL with MariaDB.

I was already curious into it and quite happy once it come to new server with Centos.

It’s very easy to use, but I has trouble to raise max_connections to my usual number (I use 10.000 as I connect to DB from many connections).

Here is the solution.

The issue is that you can’t have more max_connections than open_files_limit.

Indication is at the log

Changed limits: max_open_files: 1024 max_connections: 214 table_cache: 400

So you got to /etc/my.cnf and under [mysqld] add

open_files_limit=12000
max_connections=10000

But it’s not enough. Because of the systemd there are some limits in starting the mysql server – it’s already started with mysql user.

So you need to go to /etc/security/limits.conf and add

mysql soft nofile 4096
mysql hard nofile 10240

Then settings for systemd

mkdir -p /etc/systemd/system/mariadb.service.d
vi /etc/systemd/system/mariadb.service.d/limits.conf

And then enter this to to the file:

[Service]
LimitNOFILE=infinity

that worked to me. After restart of the mysql by

systemctl daemon-reload
systemctl restart mariadb

I got the connections fixed:

mysql
MariaDB [(none)]> select @@max_connections;
+-------------------+
| @@max_connections |
+-------------------+
| 10000             |
+-------------------+
MariaDB [(none)]> SHOW VARIABLES LIKE 'open%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 65536 |
+------------------+-------+

That’s all.

One comment

  1. Aaron says:

    Thank you for that. was a big help today 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *