Change max_connections in MySQL

Normally, the parameter max_connections in MySQL is set to 151 and allowed for one connection more, that is, there may be 152 connections.
If there are more connections, there will be a “too many connections” error.
On an example I use MySQL 5.5.54.

To increase the value, we connect to MySQL:

mysql -u root -p

Let’s see a list of current connections:

show processlist;
SHOW FULL PROCESSLIST\G
show status where `variable_name` = 'Threads_connected';

Let’s see the current value of max_connections:

show variables like "max_connections";

If you need to increase it without restarting MySQL (it will work before restarting MySQL):

set global max_connections = 300;

So that after the restart of MySQL the value of max_connections is preserved, in the configuration file /etc/mysql/my.cnf, in the [mysqld] section we specify it:

max_connections = 300

It should be noted that when the value of max_connections is increased, enough RAM must be installed in the server, otherwise it may become full and the system may crash. More detailed miscalculations and recommendations can be seen in mysqltuner.

Installing and using mysqltuner.pl
See my other articles about MySQL

Leave a comment

Leave a Reply