使用druid连接池遇到的问题

使用druid连接池遇到的问题:

一月 06, 2021 3:09:50 下午 com.alibaba.druid.pool.DruidAbstractDataSource info
信息: {dataSource-102} failContinuous is true
一月 06, 2021 3:09:50 下午 com.alibaba.druid.pool.DruidDataSource error
严重: create connection SQLException, url: jdbc:mysql://localhost:3307/test?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&&rewriteBatchedStatements=true, errorCode 1040, state 08004
java.sql.SQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

解决方法:

1、临时解决

(1)CMD连接MySQL服务器:

C:\Users\Admin>mysql -uroot -p
Enter password: ****
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

(2)如果遇到如上报错,可以尝试指定主机名和端口号之后再重新连接:

C:\Users\Admin>mysql -h localhost -uroot -P3307 -p

(3)查看最大连接数:

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 10000 |
+-----------------+-------+
1 row in set, 1 warning (0.01 sec)

(4)设置最大连接数:

mysql> set GLOBAL max_connections=10000;
Query OK, 0 rows affected (0.00 sec)

2、永久解决

(1)打开my.ini文件,找到max_connections字段,修改最大连接数:

max_connections=10000

(2)重启 MySQL 服务

CMD输入services.msc打开服务界面,找到MySQL服务,重启服务!

版权声明:本文为qq_36448452原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。