Increase MySQL/MariaDB max_connections online (without a restart)

MySQL/MariaDB makes DBA’s life much easier by allowing to increase the number of max_connections.

nn

You can use SHOW VARIABLE LIKE 'max_connections'; to check the number of max connections allowed.

nn

mysql> SHOW VARIABLE LIKE 'max_connections';n+-----------------+-------+n| Variable_name   | Value |n+-----------------+-------+n| max_connections | 151   |n+-----------------+-------+n1 row in set (0.01 sec)n

nn

You might want to see how many connections you have in your database right now. You can use the below query to check that.

nn

mysql> SELECT COUNT(1) FROM information_schema.processlist;n+----------+n| COUNT(1) |n+----------+n|      100 |n+----------+n1 row in set (0.00 sec)n

nn

Let’s assume, we need to increase maximum connections allowed to 250. Please run below query.

nn

mysql> SET GLOBAL max_connections = 250;nQuery OK, 0 rows affected (0.00 sec)n

nn

You can verify the change by running SHOW VARIABLE LIKE 'max_connections';.

nn

mysql> SHOW VARIABLE LIKE 'max_connections';n+-----------------+-------+n| Variable_name   | Value |n+-----------------+-------+n| max_connections | 250   |n+-----------------+-------+n1 row in set (0.01 sec)n

nn

But our work is not done yet. If service restarts max_connection will reset to the old value. To make the change permanent, we need to change the configuration file. Find the relevant configuration file. It can be one of below files. (Depends on your installation.)

nn

/etc/mysql/mysql.conf.d/mysqld.cnfn/etc/mysql/conf.d/mysql.cnfn/etc/mysql/mysql.cnfn/etc/mysql/my.cnfn/etc/my.cnfn

nn

Once you manage to locate the file, look for the line “max_connections = 151” and change it to “max_connections = 250”. Make sure it is not commented. (If there is a # in the begin of that line please remove that #. )

nn

Tags

nn

    n

  • database
  • n

  • mysql
  • n

  • mariadb
  • n

n

Proudly powered by WordPress

Discover more from Dedunu

Subscribe now to keep reading and get access to the full archive.

Continue reading