Home  >  Article  >  Database  >  How to solve the MySQL prompt "too many connections" error

How to solve the MySQL prompt "too many connections" error

WBOY
WBOYforward
2023-06-03 16:27:467384browse

Discover the problem

When I recently used mysql5.7 to connect to the company's system database, I found an error message and a mysql too many connection exception. After querying, I learned that the error was caused by the number of connections exceeding the default configuration of the mysql system.

Solution process

1. First log in to the mysql terminal and enter show variables like max_connections to view the maximum number of connections.

Modify the maximum number of connections: set GLOBAL max_connections=1000. After configuring, check the maximum number of connections again.

How to solve the MySQL prompt too many connections error

#2. The reason for exceeding the number of connections is that the number of mysql connections is maintained for too long. You can modify itThe keep-alive mechanism show global variables like 'wait_timeout', which is the maximum sleep time.

Modify set global wait_timeout=300; to automatically kill the thread.

How to solve the MySQL prompt too many connections error

The changes made are only temporary and will be reset if MySQL is restarted. You can modify the mysql configuration /etc/my.cnf.

group_concat_max_len = 10240
# 最大睡眠时间
wait_timeout=300
# 超时时间设置
interactive_timeout = 500

How to solve the MySQL prompt too many connections error

After the modification is completed, restart mysql5.7.

How to solve the MySQL prompt too many connections error

Find MySQL in the task manager, right-click and restart.

The reason why mysql limits the maximum number of connections

The reason is because the underlying Linux operating system limits the number of file handles that a process can open to 1024, resulting in the maximum number of mysql connections being 214

How to solve the MySQL prompt too many connections error

The above is the detailed content of How to solve the MySQL prompt "too many connections" error. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete