mysql connection error: ERROR 1040 (HY000): Too many connections

1. The maximum number of connections mysql See: show variables like '% max_connections%';

  2. Check the maximum number of connections the server's response:

3. Set the maximum number of connections: set GLOBAL max_connections = 2256; (this arrangement, after the restart is mysql failure)

For maximum connections mysql server ideal value setting ranges are: maximum connection server response value a percentage value of the upper limit of the server connected to values ​​above 10%, if 10% or less, the maximum on-mysql server connection limit is set too high . The number of connections exceeds the value of MySQL set max_connections and wait_timeout have relationships with. Wait_timeout larger the value, the longer the wait idle connections, this will result in larger number of current connections. wait_timeout too much malpractice 28800 (ie 8 hours), which is reflected in the large number of MySQL SLEEP process can not be released in time, a drag on system performance, but also can not refer to this set is too small, or you may encounter. " problem MySQL has gone away "and the like, generally speaking, I think the wait_timeout to 10 is a good choice, but in some cases may also be a problem, for example, there is a CRON script, two of SQL queries interval longer than 10 seconds, then this setting there is a problem (of course, this is not not solve the problem, you can look mysql_ping from time to time in the program, so that the server knows you're alive, recalculate wait_timeout time)

4. show global variables like 'wait_timeout';

10 SET = Global the wait_timeout 5. The;
6. The maximum number of connections can also change the configuration file

The mac under /usr/local/mysql/support-files/my.cnf, Should I do not know, you can find the installation directory where mysql

[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port        = 3306
socket      = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 50M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
max_connections = 1000
max_user_connections = 1000 

7. manually to release some useless connection. show processlist

 kill pid; (where pid is the process list to find and kill the process ID)

8.too many connections when unable to log issues,

To prevent problems when too many connections can not log occurs,

mysql manual has the following description:

mysqld actually allows max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege. By granting the SUPER privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use SHOW PROCESSLIST to diagnose problems even if the maximum number of unprivileged clients are connected.

Therefore, it must be given only SUPER privileges of the root user, and all accounts database connection can not be given the SUPER privilege. Speaking in front of the error is because the root user can not log in to our application directly configurations

View all current users of the database:

select user,host,password from mysql.user;

Giving super user privileges (super and ALL PRIVILEGES can):

GRANT super ON *.* TO 'mysql'@'localhost'

Guess you like

Origin www.cnblogs.com/guanbin-529/p/12629851.html