Introduction
The max_connections setting in MySQL defines the maximum number of simultaneous database connections allowed on the server. If this limit is too low, users may face “Too many connections” errors. By default, MySQL sets this value to 151 connections.
Prerequisites
Before making changes, ensure you have:
a. Root access to the server (SSH or WHM Terminal)
b. Basic knowledge of MySQL configuration
c. Access to MySQL configuration file (/etc/my.cnf)
Implementation
Step 1: Login to Server
Access the server via SSH or WHM Terminal as root user
Step 2: Check Current Value
Run the below command to verify current connections limit:
mysql -e "show variables like 'max_connections';"
Step 3: Edit MySQL Configuration
Open the MySQL config file:
vi /etc/my.cnf
Step 4: Modify max_connections
Find or add the following line:
max_connections=151
Change it to your required value (example):
max_connections=200
Step 5: Save Changes
Save and exit the file
Step 6: Restart MySQL Service
Apply changes by restarting MySQL:
/usr/local/cpanel/scripts/restartsrv_mysql
Step 7: Verify Changes
Check again to confirm the update:
mysql -e "show variables like 'max_connections';"
Conclusion
You can increase or modify MySQL max_connections by editing the configuration file and restarting the MySQL service. Adjust this value based on your server capacity and traffic to avoid connection errors while maintaining performance.