Ways to resolve MySQL error too many connections

Source: Internet
Author: User

MySQL database Too many connections
This error is obviously mysql_connect after forgetting Mysql_close;
When a large number of connect, there will be too many connections error, mysql default connection is 100, and under what circumstances will this error occur?

After normal mysql_connect call Mysql_close () to close the connection
However, when the connection error occurs, the Mysql_real_query () error exits, may forget mysql_close ();
So before the program return, be sure to determine whether close (), the surest way to write any function is only one exit!
There is also the ability to increase the number of allowed connections by modifying the MySQL configuration file!

Sometimes your server is often the error that occurs:
The error message is as follows:
Can not connect to MySQL server

Error:too Many connections
Errno.: 1040

Similar Error Report have beed dispatched to administrator before.

From the official documentation know Linux compiled installed MySQL default connection for 100
Document: Http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html

MySQL official tells us that we need to modify the value of max_connections, then how can we modify it? There are two ways
1. Modify the profile file
Modify/ETC/MY.CNF This file, add Max_connections=n in [mysqld], if you do not have this file, please copy the *.cnf file you need from the Support-files folder in the source code to/ETC/MY.CNF. I am using the MY-MEDIUM.CNF, medium server configuration. For example, my [mysqld] content 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

Because MySQL is not very familiar with, so many parameters are not modified. Ha ha..

2. Users who are not automatically started using the Mysqld script.
Modify the $mysql_home/bin/mysqld_safe file
For example:/usr/local/mysql/bin/mysqld_safe this file
Grep-n ' max_connection ' $MYSQL _home/bin/mysqld_safe
Modify the Max_connections parameter value for the corresponding line number

Ways to troubleshoot MySQL error too many connections

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.