Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the solution to MySQL error Too many connections

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to talk to you about what is the way to solve the MySQL error Too many connections, many people may not know much about it. In order to make you understand better, the editor summarized the following content for you. I hope you can get something according to this article.

MySQL database Too many connections

This kind of error is obviously forgetting mysql_close after mysql_connect

When there is a large number of connect, there will be an error of Too many connections, and the default number of connections for mysql is 100. under what circumstances will this error occur?

Call mysql_close () to close the connection after a normal mysql_connect

However, in the case of a connection error, when the meeting member mysql_real_query () exits incorrectly, he may forget mysql_close ().

So be sure to judge whether close () before the program return, the safest way is to write any function with only one exit!

You can also increase the number of connections allowed by modifying the mysql configuration file!

Sometimes there are errors like this on your server:

The error message is as follows:

Can not connect to MySQL server Error: Too many connections Errno.: 1040 Similar error report has beed dispatched to administrator before.

From the official documentation, we know that the default number of mysql connections for compilation and installation on Linux is 100th.

Documentation: http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html

MySQL officials tell us that we need to change the value of max_connections, so how do we change it? There are two ways.

1. Modify the configuration file

Modify the file / etc/my.cnf and add max_connections=N to [mysqld]. If you don't have this file, please copy the * .cnf file you need from the support-files folder in the compiled source code to / etc/my.cnf. I am using my-medium.cnf, a medium server configuration. For example, my [mysqld] is as follows:

[mysqld] port = 3306 socket = / tmp/mysql.sock skip-locking key_buffer = 160m max_allowed_packet = 1m table_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8m max_connections=1000

Since I am not familiar with mysql, many parameters have not been modified. Ha ha.

2. Users who are not automatically started with mysqld scripts.

Modify the MYSQLHOME/bin/mysqldsafe file for example: / usr/local/mysql/bin/mysqldsafe this file grep − nasty maxConnection`

MYSQLHOME/bin/mysqldsafe file for example: / usr/local/mysql/bin/mysqldsafe this file grep − n'maxconnection'MYSQL_HOME/bin/mysqld_safe

Modify the max_connections parameter value of the corresponding line number

3. Log in to the server mysql: mysql-u root-p

90% if you can't get in, execute the restart command: / etc/init.d/mysql restart (centos system)

Restart mysql at this time to connect to mysql. If there is still time, you can move on to the next step, which requires a permanent cure.

Open the configuration file and add the configuration vi / etc/my.cnf

Wait_timeout = 600interactive_timeout = 600,

Just restart mysql again.

Principle solution

The default number of mysql connections is 100. if you exceed it, you will not be able to connect. The actual number of connections is far less than 100. most of the connections are in sleep.

So either increase the number of connections or kill useless connections and recommend the latter.

After reading the above, do you have any further understanding of the solution to MySQL error Too many connections? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report