当前位置:网站首页>【问题记录】03 连接MySQL数据库提示:1040 Too many connections
【问题记录】03 连接MySQL数据库提示:1040 Too many connections
2022-07-04 06:23:00 【joinclear】
1、报错信息如下:
连接MySQL数据库提示:1040 Too many connections:
2、原因:
由于数据库连接数量,超过了数据库的最大连接数。
PS:因为这些数据库连接数,处于sleep状态,但是还没有被清除掉。
查看原因:
1)登录数据库
登录服务器,输入命令:
mysql -uroot -p
输入数据库登录密码后,登录成功。
2)查看数据库进程状态
show status like 'Threads%';

treads_cached :缓冲池中的线程数。
Threads_connected:当前连接(运行和睡眠)中的线程数。
Threads_created :创建过连接的线程数。
Threads_running:当前运行(没有睡眠)中的线程数。
总共连接了:152个。
3)查看数据库最大连接数
show variables like '%max_connection%';

最大连接数:151个,小于当前连接总数152,所以提示:Too many connections。
4)查看清除Sleep连接数时间
show variables like 'wait_timeout';

清除时间间隔为:28800秒(8小时),连接后8小时清除掉。
3、解决方法:
解决方法优先按下面1、2、3的顺序:
1)排查代码问题
看看到底哪里产生的连接数过多,有可能是代码比如定时任务引起的问题。
2)增加最大连接数
set GLOBAL max_connections=1000;
比如,改为1000个连接数:
3)改小清除Sleep连接数时间
set GLOBAL wait_timeout=14400;
改成4小时清除或者更短的时间间隔。
边栏推荐
猜你喜欢

Bicolor case

SQL join, left join, right join usage

Win10 clear quick access - leave no trace

如何避免 JVM 内存泄漏?

Learn about the Internet of things protocol WiFi ZigBee Bluetooth, etc. --- WiFi and WiFi protocols start from WiFi. What do we need to know about WiFi protocol itself?

Component、Container容器常用API详解:Frame、Panel、ScrollPane

体验碎周报第 102 期(2022.7.4)

JSON Web Token----JWT和傳統session登錄認證對比

QT QTableWidget 表格列置顶需求的思路和代码
![[March 3, 2019] MAC starts redis](/img/ff/88638fcdc8d24dc268781c224e8195.jpg)
[March 3, 2019] MAC starts redis
随机推荐
ES6 modularization
Learn about the Internet of things protocol WiFi ZigBee Bluetooth, etc. --- WiFi and WiFi protocols start from WiFi. What do we need to know about WiFi protocol itself?
AWT common components, FileDialog file selection box
Component、Container容器常用API详解:Frame、Panel、ScrollPane
C realize Snake games
C實現貪吃蛇小遊戲
px em rem的区别
R统计绘图-随机森林分类分析及物种丰度差异检验组合图
Which water in the environment needs water quality monitoring
APScheduler如何设置任务不并发(即第一个任务执行完再执行下一个)?
Invalid revision: 3.18.1-g262b901-dirty
High performance parallel programming and optimization | lesson 02 homework at home
Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
Understanding of cross domain and how to solve cross domain problems
198. House raiding
Nexus 6p从8.0降级6.0+root
Is the insurance annuity product worth buying? Is there a hole?
C language - Blue Bridge Cup - Snake filling
JSON Web Token----JWT和傳統session登錄認證對比
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people