These days, I have been working on big jobs in project management. web programs often encounter this problem, but it will be fine again later. At first I suspected that the session was not closed, but then I checked the code, the main cause is the database configuration.
Exception information:Data source rejected establishment of connection, message from server: "Too many connections"
Possible causes
1. The max_connections attribute configuration of mysql is too small.
2. Multiple insert operations may be performed, and the update operation does not close the session.
Solution:
1. Reduce the wait_timeout time of the session in tomcat to 200
2. Provides transaction support for database insert or update operations with large processing capacity. (configured in Spring)
Cause:
The number of concurrent connections set in my. ini (linux: my. cnf) in the mysql installation directory is too small or the system is busy, resulting in the full number of connections
Solution:
Windows: Find the mysql installation directory, open the my. ini file, and findMax_connectionsConfiguration,The default value is 100, and the value is set to 1000., Restart mysql
MYSQL must be restarted to take effect.
Run the command in cmd.
Net stop mysql
Net start mysql
Linux: Find the mysql installation directory and open the my. cnf file.
Add the following three lines under [mysqld ]:
Max_connections = 1000
Max_user_connection= 500
Wait_timeout = 200
// Set max_connections to 1000
// Set max_user_connections to 500
// Wait_timeout indicates that the IDLE (IDLE) connection will be closed after 200 seconds, but it will not affect the working connection.
// Save and exit, and restart MySQL
Sudo stop mysql
Sudo start mysql
// Restart MySQL and run the following command to check whether the modification is successful.
# Mysqladmin-uroot-p variables
Password:
// The following information indicates that the modification is successful.
| Max_connections | 1000
| Max_user_connections | 500
| Wait_timeout | 200