Problem: Too many connections error occurred and you can’t access via PHPMyAdmin or command line.
This is because no more connection can be made, so you have to stop MySQL service and change the setting.
Solution: first stop MySQL service, I user MariaDB so the service will be mariadb:
systemctl stop mariadb
systemctl start mariadb
then enter MySQL prompt via MySQL, and enter below query to check current maximum connection:
SHOW VARIABLES LIKE "max_connections";
The default value is 151. You can set a higher one like
SET GLOBAL max_connections = 1000;
3/3/2020: And you should add a timeout parameter to close any connections that no longer used by user. Append parameter in /etc/my.cnf:
sudo vim /etc/my.cnf
Then add wait_timeout = 600 under [mysqld] to timeout any idle connection exceed 10 minutes.