Solution to the problem that the number of MySQL connections is limited to 214 in CentOS 7

Solution to the problem that the number of MySQL connections is limited to 214 in CentOS 7

Find the problem

Recently, I encountered a problem in the project. Due to too many connections, the prompt "Too many connections" appeared and I needed to increase the number of connections.

I modified in /etc/my.cnf:

max_connections = 2000

However, the actual number of connections is always limited to 214:

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set

think

If I set the number of connections to less than 214, for example 200, then the actual number of connections is 200, which means there is no problem with my configuration file.

Check the MySQL official documentation, which says:

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.
Increasing open-files-limit may be necessary. Also see Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.

It probably means that the maximum number of connections that MySQL can support is limited by the operating system. If necessary, you can increase the open-files-limit. In other words, the number of connections is related to the number of file opens.

Workaround

[root@sqzr ~]# ulimit -n
1024

It can be seen that the maximum file descriptor limit of the operating system is 1024.

To change the maximum file descriptor limit for MySQL in Linux, edit the /usr/lib/systemd/system/mysqld.service file and add the following to the end of the file:

LimitNOFILE=65535
LimitNPROC=65535

After saving, execute the following command to make the configuration take effect

$ systemctl daemon-reload
$ systemctl restart mysqld.service

The actual number of connections has reached 2000.

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 |
+-----------------+-------+
1 row in set

refer to

https://dev.mysql.com/doc/refman/5.7/en/too-many-connections.html

https://www.oschina.net/question/853151_241231

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Python connects to the database MySQL decompressed version installation configuration and encountered problems
  • Detailed explanation of how to view the current number of MySQL connections
  • Mysql view the maximum number of connections and modify the maximum number of connections
  • Summary of tips for setting the maximum number of connections in MySQL
  • How to set the number of mysql connections (Too many connections)
  • Perfect solution to the problem that MySQL cannot connect to the database through localhost
  • How to use Java Web to connect to MySQL database
  • Python 3.x database connection example (pymysql method)
  • PHP mysql operation mysql_connect connection database instance detailed explanation
  • Summarize two ways to modify the maximum number of connections in MySQL
  • How to set and get the number of Mysql connections

<<:  Implementation of adding visit count function in github+Jekyll blog in one minute with JS

>>:  ffmpeg Chinese parameter description and usage examples

Recommend

How to create a web wireframe using Photoshop

This post introduces a set of free Photoshop wire...

Detailed examples of the difference between methods watch and computed in Vue.js

Table of contents Preface introduce 1. Mechanism ...

How to successfully retrieve VMware Esxi root password after forgetting it

Prepare a CentOS6 installation disk (any version)...

How much do you know about JavaScript inheritance?

Table of contents Preface The relationship betwee...

Complete steps to install mysql5.7 on Mac (with pictures and text)

I recently used a Mac system and was preparing to...

How to delete extra kernels in Ubuntu

Step 1: View the current kernel rew $ uname -a Li...

Guide to Efficient Use of MySQL Indexes

Preface I believe most people have used MySQL and...

Steps to repair grub.cfg file corruption in Linux system

Table of contents 1. Introduction to grub.cfg fil...

MySQL 8.0.12 Installation and Usage Tutorial

Recorded the installation and use tutorial of MyS...

Full analysis of Vue diff algorithm

Table of contents Preface Vue update view patch s...

htm beginner notes (must read for beginners)

1. What is HTML HTML (HyperText Markup Language):...

Recommend a cool flashing alarm button

The effect is as follows: The code is as follows ...

3 codes for automatic refresh of web pages

In fact, it is very simple to achieve this effect,...

How to write the parent and child directories of HTML relative paths

How to indicate the parent directory ../ represent...