Solve a MySQL/MariaDB "Too many connections" error

Change max_connections

The max_connections variable will need to be changed in two places:

Show the Current max_connections Value

To see the current number of max_connections log in to the MySQL/MariaDB command line client with the command:

mysql -u root -p

Use the command:

SHOW variables;

This will output a list of all of the variables which are set for MySQL/MariaDB. Scroll up through the list to find the value for max_connections.

Update my.cnf

Open the file /etc/my.cnf for editing with the command:

sudo nano /etc/my.cnf

Directly beneath the first line:

[mysqld]

Add a line:

max_connections=[desired new maximum number]

For example, to set max_connections to 200, the first two lines of the file will read:

[mysqld]
max_connections=200

Save and exit the file.

SET GLOBAL

Log in to the MySQL/MariaDB command line client with the command:

mysql -u root -p

Set the new max_connections value with the command:

SET GLOBAL max_connections=[desired new maximum number];

For example, to set max_connections to 200, the command is:

SET GLOBAL max_connections=200;

Exit MySQL/MariaDB with the command:

quit;

Click to rate this post!
[Total: 0 Average: 0]

Share and Enjoy !

Shares
Get Weekly KBV Tips !

Learn and improve day to day Knowledge & lifestyles.