MySQL exceeds maximum number of connections solution

Source: Internet
Author: User
Tags mysql code

MySQL exceeded the maximum number of connections, I believe many people first reaction is to view the MySQL process, see if there is a slow query, of course, this approach is entirely correct!
But most of the time the real problem isn't here.
Today has encountered the same problem, blindly view the MySQL process and slow query log, no fruit.
Later the boss raised a little bit, look at the Nginx log, found that there are one or two access to the execution time is relatively long, and then use the top command to view the server load, surprised, incredibly ultra-high!
Finally, it was found that a web streaming host has been hung, resulting in increased load on several other web hosts, resulting in lower execution efficiency of the PHP-FPM.
So what does this have to do with MySQL? The reason is very simple, because the PHP execution time is too long, the MySQL connection is slow to release, will cause the connection number to appear excessively.
Finally summary: In fact, a lot of times, the root cause of a problem is not so directly presented, need to track their own.
Boss has a very practical words: The problem first check log (MySQL, PHP, nginx, etc.)


windows2003 System

Ways to increase the number of default MySQL connections

Method One: Enter the MySQL installation directory to open the MySQL profile My.ini or my.cnf find max_connections=100 Modify for max_connections=1000 service to restart MySQL

Method Two: MySQL maximum number of connections default is 100 client login: Mysql-uusername-ppassword

Sets the new maximum number of connections to 200:mysql> set GLOBAL max_connections=200

Displays the currently running query:mysql> show processlist

Display current status:mysql> show status

Exit Client:mysql> Exit

View the current maximum number of connections: Mysqladmin-uusername-ppassword variables

Linux system

The manual compilation version of the MySQL 5.0.33 below CentOS 4.4 illustrates:

The code is as follows Copy Code

Vi/usr/local/mysql/bin/mysqld_safe

Find Safe_mysqld edit it, find the two lines where the mysqld starts, and then add the arguments back:

The code is as follows Copy Code

-O max_connections=1500

The specific point is the following location:

Use Description:

The code is as follows Copy Code

Then $NOHUP _niceness $ledir/$MySQLD
$defaults--basedir= $MY _basedir_version
--datadir= $DATADIR $USER _option
--pid-file= $pid _file
--skip-external-locking
-O max_connections=1500
>> $err _log 2>&1 Else
Eval "$NOHUP _niceness $ledir/$MySQLD
$defaults--basedir= $MY _basedir_version
--datadir= $DATADIR $USER _option
--pid-file= $pid _file
--skip-external-locking $args
-O max_connections=1500 >>
$err _log 2>&1 "

Save.

The code is as follows Copy Code

# Service MySQLd Restart
#/usr/local/mysql/bin/mysqladmin-uroot-p variables

Enter the password for the root database account to see

Max_connections 1500 that the new changes have taken effect.

There is another way,

To modify the original code:

Unlock the original MySQL code, into the inside of the SQL directory modification mysqld.cc found the following line:

The code is as follows Copy Code

{"Max_connections", Opt_max_connections,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, Get_ulong, Required_arg, 100, 1, 16384, 0, 1,
0},

Change it to:

The code is as follows Copy Code

{"Max_connections", Opt_max_connections,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, Get_ulong, Required_arg, 1500, 1, 16384, 0, 1,
0},

Save to exit, and then./configure Make;make Install can achieve the same effect. The above related content is to revise the MySQL maximum connection number 3 kinds of methods Introduction, hope you can have the harvest.

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.