MySQL modify the maximum number of connections

1. MySQL modify the maximum number of connections

1.1. Common mistakes

(1) When the number of logged-in users is too many, the configured number of mysql connections is too small, or the connection is not closed normally, and the number of connections exceeds the maximum number of connections, the following errors will be encountered:

Data source rejected establishment of connection,  message from server: "Too many connections"

1.2, modification method

(1) View the currently configured maximum number of connections and the current maximum number of connections used.

#Currently configured maximum number of connections

show variables like 'max_c%';

#The maximum number of connections currently used

show global status like 'Max_%';

 

(2) The maximum number of connections is set as: the maximum number of connections used/the maximum number of configured connections ≈ 85% is more appropriate, but the maximum number of connections used is subject to the application of the maximum number of connections configured, so the configuration of the maximum number of connections is too small In the case of , first configure a larger number of connections as much as possible, and then set the optimal maximum number of connections after obtaining the maximum number of connections used over a period of time.

(3) Modify the my.ini configuration file of mysql. The location of my.ini of different versions is different. The my.ini file of version 5.5.58 is in: C:\Program Files\MySQL\MySQL Server 5.5 directory, and the version 5.7.11 In the my.ini file C:\ProgramData\MySQL\MySQL Server 5.7 folder, add the following lines:

#Set the maximum number of connections

set-variable=max_connections=1000

#Set the maximum number of connections per user to 500

set-variable=max_user_connections=500

¥ means that idle connections will be closed after 200 seconds, but working connections are not affected.

set-variable=wait_timeout=200

1.3. Other commands

1.3.1、show [full] processlist

#Check the number of connections of the current user, root can see all, other accounts can only see themselves

#View the first 100

show processlist;

#view all

show full processlist;

 

1.3.2、show status

Detailed documentation on the official website of Show Status:

https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html#statvar_Aborted_clients

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325027635&siteId=291194637