MySQL number of connections too many solutions

Source: Internet
Author: User

MySQL Default link number is 100 maximum is 16384. principle: Try every means not to restartCause:

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-p1234.com statusuptime: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    2threads_running    1 # # (current number of connections)   
Mysql> Show status like ' threads% '; +-------------------+-------+| Variable_name    | Value |+-------------------+-------+| threads_cached    | 1    | | threads_connected | 1    | | threads_created  | 2    | | Threads_running  | 1    |   # # #当前连接数 +-------------------+-------+4 rows 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
Mysql> show global variables like ' max_conn% '; +--------------------+-------+| Variable_name      | Value |+--------------------+-------+| max_connect_errors | |    | | max_connections    |  |## Maximum number of connections +--------------------+-------+2 rows 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][ne W LWP 4816][new lwp 341][new LWP 338][new LWP 337][new LWP 336][new lwp 335][new LWP 331][new LWP][new LWP 329][new lwp 328][new LWP 327][new LWP 326][new LWP 325][new LWP 324][n EW LWP 323][new LWP 322][thread debugging using libthread_db enabled]0x00000035654df1b3 in poll () from/lib64/l Ibc.so.6                
How to view MySQL PID locationfind in config file my.cnfusing Ps-ef | grep mysql lookup
Mysql> Show variables like '%pid% '; +---------------+----------------------+| variable_name | Value                |+---------------+----------------------+| pid_file      |/data/mydata/xxx.pid |+---------------+------ ----------------+1 Row 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=2while True do let        "j=j+1"/usr/local/mysql/bin/mysqlslap-a-C 500-i 10-uroot-P1234.comdo NE 

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

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.