MySQL Default link number is 100 maximum is 16384.
principle: Try every means not to restart
Cause:
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!
View Links:view current number of connections
./mysqladmin-uroot-1370150 threads:1 (current number of connections) questions:79 Slow queries:0 opens:33 Flush Tables:1 Open tables:26 Queries per second avg:0.000
./mysql-uroot-p1234.com-e " show status | grep-i Threads delayed_insert_threads 0slow_launch_threads 0threads_cached 1threads_connected 1threads_created 2 threads_running 1 # # (current number of connections)
' threads% ' ; +-------------------+-------+| Variable_name | Value |+-------------------+-------+| threads_cached | 1 | | threads_connected | 1 | | threads_created | 2 | | Threads_running | 1 | # # #当前连接数 in Set (0.00 sec)
View the maximum number of connections
[[email protected] bin] # ./mysql-uroot-p1234.com-e ' Show variables ' | grep max_connectionsmax_connections 500
Global ' max_conn% ' ; +--------------------+-------+| Variable_name | Value |+--------------------+-------+| max_connect_errors | Ten | | | max_connections | ## Maximum number of connections in Set (0.00 sec)
Workaround:Try to do everything without restartingThis situation is generally not into the database, modify the configuration file to restart, for the online database risk is too big, into the database with SQL modification, now is not going to go
Method 1:using the GDB tool without going into the database without restarting the database method is as follows:
[[email protected] bin]#gdb-p $ (cat/data/mydata/xxx.pid)-ex "Set max_connections=500"-batch[New LWP 7667][new LWP4816][new LWP341][new LWP338][new LWP337][new LWP336][new LWP335][new LWP331][new LWP330][new LWP329][new LWP328][new LWP327][new LWP326][new LWP325][new LWP324][new LWP323][new LWP322][thread debugging using libthread_db enabled]0x00000035654df1b3inchPoll () from/lib64/libc.so.6
How to view MySQL PID locationfind in config file my.cnfusing Ps-ef | grep mysql lookup
' %pid% ' ; +---------------+----------------------+| variable_name | Value |+---------------+----------------------+| pid_file in Set (0.00 sec)
After the modification, try to re-enter the database and view the number of links
After this method is set, only temporarily, after the database restarts, will become the original value, to want to permanently, after the configuration file modification my.cnf
Method 2If you have access to the databaseEnter the database
Set the new maximum number of connections to 200:mysql> set GLOBAL max_connections=200
Displays the currently running query:mysql> show processlist
Show current status:mysql> show status
Exit Client:mysql> Exit
After this method is set, only temporarily, after the database restarts, will become the original value, to want to permanently, after the configuration file modification my.cnf
Method 3:need to restart databaseModify My.conf
max_connection = 1000;
Simulate MySQL connection too many script content
# !/bin/bashSet j=2 while true "j=j+1"/usr/local/mysql/ Bin/mysqlslap-a-C 500-i 10-uroot-p1234.comdone
Run this script, and then cause the number of MySQL connections to be too large to connect, try several times to make sure you cannot connect and test with the GDB tool
MySQL number of connections too many solutions