A brief discussion on the maximum number of open files for MySQL system users

A brief discussion on the maximum number of open files for MySQL system users

What you learn from books is always shallow, and you will never know that this will cause more downtime... I will record a stupid troubleshooting process of mine.

Last week, a system that had just been launched started to report that it could not be logged in again. Because this system has been having this problem recently and the developers have been looking for the problem, we didn't pay much attention to it. So I logged into the operating system, used mysql -uroot -p to log into the database, and then nothing happened and I couldn't log in...

To explain, MySQL is installed under the mysql user. Although the database parameters are tuned during installation, no adjustments are made at the operating system level. Therefore, the maximum number of open files for the mysql user is limited to the default 1024, which can be queried using ulimit -n. Then when I logged into the database with the mysql root account, I also logged in under the mysql system user, and then looked at the server load at the time. The CPU and memory were all normal, but there were a large number of applications connecting to the database.

At this point the problem should be clear. The number of mysql files opened by the system user may have reached the maximum limit, and of course no more connections can be opened.

However, I didn't think of this at the time. What I thought of was not to change the system user to log in, not to stop the application, but to restart the database. . . Moreover, this database runs more than just this one business, although none of them are important businesses. . .

So I prepared to restart the database, still executing mysqladmin -uroot -p shutdown under the mysql user. There is no doubt that this will definitely not respond. The reason is the same as the previous root account cannot connect to the database. After ctrl+C, the following error is reported

^Cmysqladmin: connect to server at 'localhost' failed
error: 'Lost connection to MySQL server at 'waiting for initial communication packet', system error: 4'

Then I did something even more stupid, even though I thought I might lose data, and I killed the mysql process. . . Then restart mysql and the system will be available. It was really stupid. After I finished it, I immediately remembered that there were many better ways to deal with it, but I chose the stupidest one.

When I logged into the database again today, I found that several parameters were different from what I wrote in the configuration file, such as max_connections, table_open_cache, etc., which were all set to the default values. I looked at the last startup log and there were indeed warnings.

2019-03-15T08:14:03.038750Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 12010)
2019-03-15T08:14:03.038911Z 0 [Warning] Changed limits: max_connections: 214 (requested 2000)
2019-03-15T08:14:03.038916Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 5000)

Obviously, mysql calculated the maximum number of files that the instance needs to open based on the parameter setting, which exceeds the maximum limit of the current system user, so the parameter is not used and the default value is used. Of course, the database is available after startup, and you can also manually set the parameters after startup.

set global max_connections=2000;
set global table_open_cache=5000;

However, the problem I encountered before is likely to occur, that is, the number of database connections does not reach the max_connections limit, and the user still cannot connect. It should be noted that under normal circumstances, even if the number of connections is full, MySQL will still reserve a connection for the root user, which means that the root user can log in to the database to view the problem.

The solution is also very simple. Just increase the limit value of the operating system user mysql and add the new limit value after the configuration file /etc/security/limits.conf.

mysql soft nofile 32768
mysql hard nofile 65535

The above is a detailed explanation of the maximum number of open files for MySQL system users that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL database case sensitivity issue
  • Python uses adbapi to implement asynchronous storage of MySQL database
  • Can MySQL's repeatable read level solve phantom reads?
  • Copy fields between different tables in MySQL
  • MySQL Optimization Solution Reference
  • Explanation of MySQL index types Normal, Unique and Full Text
  • Summary of MySQL database and table sharding
  • The difference between MySQL database stored procedures and transactions
  • Detailed explanation of MySQL Limit performance optimization and paging data performance optimization
  • Mysql view the maximum number of connections and modify the maximum number of connections

<<:  Share the problem of Ubuntu 19 not being able to install docker source

>>:  In-depth understanding of Vue-cli4 routing configuration

Recommend

Let's learn about MySQL database

Table of contents 1. What is a database? 2. Class...

CSS code for arranging photos in Moments

First, you can open Moments and observe several l...

A brief discussion on the characteristics of CSS float

This article introduces the characteristics of CS...

Implementation code for operating mysql database in golang

Preface Golang provides the database/sql package ...

In-depth discussion on auto-increment primary keys in MySQL

Table of contents Features Preservation strategy ...

MySQL Database Basics: A Summary of Basic Commands

Table of contents 1. Use help information 2. Crea...

Share JS four fun hacker background effect codes

Table of contents Example 1 Example 2 Example 3 E...

Teach you how to use docker-maven-plugin to automate deployment

1. Introduction to docker-maven-plugin In our con...

Solve the cross-domain problem of get and post requests of vue $http

Vue $http get and post request cross-domain probl...

JS Object constructor Object.freeze

Table of contents Overview Example 1) Freeze Obje...

MySQL 5.7 installation and configuration method graphic tutorial

This tutorial shares the installation and configu...

CSS element hiding principle and display:none and visibility:hidden

1. CSS element hiding <br />In CSS, there ar...

Index Skip Scan in MySQL 8.0

Preface MySQL 8.0.13 began to support index skip ...

Solution to the CSS height collapse problem

1. High degree of collapse In the document flow, ...

Docker data storage tmpfs mounts detailed explanation

Before reading this article, I hope you have a ba...