问题描述
使用docker搭建的数据库,是开发测试用的,最近多个同时一起调试使用,经常出现客户端连接报错:
[1040][08004] Too Many Connections
错误的意思是客户端的连接已超过最大连接数,来查看下最大连接数,进入MySQL的命令提示行:
bash-4.4# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19282 Server version: 8.0.27 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like "max_connections"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 151 | +-----------------+-------+ 1 row in set (0.01 sec) mysql>
使用命令show variables like "max_connections"; 显示最大连接数才151,这个默认安装的MySQL(我是用Docker安装的)的最大连接数,所以有必要设置一个高一点的值。
问题解决
修改my.cnf(路径一般是/etc/my.cnf 或者/etc/mysql/my.cnf,如果是用docker安装的,看下my.cnf是否映射到外部宿主机上面的路径)
如下,在[mysqld]的section下,增加max_connections=1000
[mysqld] # 其他配置省略,主要是增加如下max_connections字段配置 max_connections=1000
重启MySQL服务即可
systemctl restart mysqld # or docker: docker restart [mysql-container]
文章评论