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

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.


Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.