How to Solve MySQL / MariaDB Error 1040 “Too Many Connections”

Published on May 9, 2020 25 sec read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

In this article, I’m going to share how to solve MySQL / MariaDB error 1040 “Too Many Connections”.

Table of Contents

  1. Check Connections
  2. Solution 1
  3. Solution 2

Check Connections

Login to your server and enter this command to login to MySQL/MariaDB client:

mysql -u root -p

Then run this command to see max connections limit:

SHOW VARIABLES LIKE "max_connections";

By default, max connection is 151.

Solution 1

To set new max_connections value, run this command:

SET GLOBAL max_connections=[new maximum number];

For example, let’s set max connection to 300:

SET GLOBAL max_connections=300;

Solution 2

Open the file /etc/my.cnf to edit with the command:

sudo nano /etc/my.cnf

Under the [mysqld] section add the following line:

[mysqld]
max_connections=300
That’s all. Thank you. 🙂

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

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