ERROR 1135 (HY000): Can't create a new thread

收到报错:
[root@i-iivphroy ~]# mysql -uroot -p********* -h192.168.0.254
ERROR 1135 (HY000): Can't create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug
马上google一番,有人说可能说磁盘空间满了,经查看发现果然是磁盘满了,(这个盘一直空间很紧张(95%),我高度警惕着,天天检查,可是昨天我执行了个大事务,产生了大量的binlog,给一下子撑爆了)
马上删除了几天前的binlog和一些别的不需要的数据,空间释放到了80%,再次登录mysql
[root@i-iivphroy ~]# mysql -uroot -p******* -h192.168.0.254
依旧报错:
ERROR 1135 (HY000): Can't create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug
再次google一番,查到下面这个文档:
This error was the bane of my life for a while, and it was very hard to get a definitive answer as to what was causing it, I hope this saves you some trouble.
My website occasionally got large traffic spikes, and at the top of these peaks, I would start to see errors like these:
MySQL error #1135: Can’t create a new thread (errno 11). If you are not out of available memory, you can consult the manual for a possible OS-dependent bug.
I looked in the my.cnf file on the db server and looked at the open files limit, because a process is counted as an open file, but it seemed fine:
[mysqld_safe]
open-files-limit=10240
I also checked that maximum connections was high enough, it was at 2048.
What the open-files-limit in my.cnf files does is it tells the init script to use ulimit to whatever number you put in there.
After a lot of digging around various places, and much frustration, I discovered that by default linux has a hard limit of 1024 open files for all non super-users, so even though I had set a high open-files-limit, it was capped at 1024 by the OS. I also discovered how to raise it;
/etc/security/limits.conf
This file is used by PAM to set things like maximum processes, max open files, memory usage etc and these limits can be set on a per-user basis, so I added these lines:
mysql soft nofile 4096
mysql hard nofile 4096
大体的意思是说,这个报错的原因:由于:mysql的配置文件/etc/my.cnf的参数open-files-limit设置的比linux的max user processes的数值大,需要通过修改linux的配置文件 /etc/security/limits.d/90-nproc.conf来扩大linux系统的限制,也就是这个错是由于linux的max user processes阈值太小了。
马上查看我的相关配置:
mysql的open-files-limit,如下所示:
[root@i-iivphroy ~]# cat /etc/my.cnf
[mysqld_safe]
open-files-limit=85216
linux的max user processes,如下所示红色部分:
[root@i-iivphroy ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 62842
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 62842
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
将查看果然是前面文档描述的情况,马上修改 max user processes
方法一:
[root@i-iivphroy ~]# cat /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
其中nofile对应open_files
nproc对应max_user_processes
但是在 Linux  6.4之后,如果只修改了该文件中的nproc,那么其他非root用户对应的max_user_processes并不会改变,仍然是1024,这个是因为受到了下面这个文件的影响
/etc/security/limits.d/90-nproc.conf
修改/etc/security/limits.d/90-nproc.conf将
* soft nproc 1024
修改为:
* soft nproc 65535
或者
修改/etc/security/limits.conf,将
* soft nofile 10240
修改为
Oracle   soft nofile 10240
方法二:这样为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。也就是说,当用户shell执行了bash时,运行这个文件,如果这个服务器上有多个用户,最好是用方法一。
修改了/etc/bashrc,成功了,并且不用重启。
vi /etc/bashrc
添加 :
ulimit -u 65535
退出session,从新开session再次ulimit -a 发现已经变化了
[root@i-iivphroy ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 62842
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 65535
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
并且把mysql的open-files-limit改小。
[root@i-iivphroy ~]# cat /etc/my.cnf
[mysqld_safe]
open-files-limit=65000
重启了mysql服务,问题解决。。。。
原因分析:
操作系统连接数太小。(比如centos 6 默认的  max user process只有 1024个。当mysql process大于这个值时 就会出现Can't create a new thread的问题)
连接数超限处理的办法:
ulimit -a
查看max user processes 这一项
要是这个值比较的小 当mysql中process的数目超过这个数的时候 就会抱标题相应的错误。
一个过程process可以视为一个打开的文件
也就是说 下面几个参数共同控制这mysql的 create a new thread
1) mysql的 /etc/my.cnf
open-files-limit=65535
2)linux 参数 open files和max user processes
[root@S243 ~]# ulimit
unlimited
[root@S243 ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1032207
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 50000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 65535
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
总结:本来从来没有报错这个错的mysql数据库,怎么突然就被linux的 max user processes所限制呢?很显然是因为我的磁盘满了,导致mysql无法提供正常服务,但是业务还在不断的请求数据库,process在队列中排队,等我数据库可以提供服务的时候,大量的排队中的process在mysql中产生,导致process数据量急剧增加,超过linux的 max user processes的阈值,报出错误。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29654823/viewspace-2135578/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29654823/viewspace-2135578/

ERROR 2003 HY000: Can't connect to MySQL server on 'localhost:3306' 10061 是一个MySQL数据库连接错误。这个错误表示无法连接到MySQL服务器。通常,这个错误是由于以下几个原因之一引起的: 1. MySQL服务器没有正确启动。 2. MySQL服务器的端口号不正确。 3. 防火墙或网络设置阻止了与MySQL服务器的连接。 4. MySQL服务器配置文件中的配置错误。 对于解决这个错误,你可以尝试以下几个步骤: 1. 确保MySQL服务器已经正确启动。你可以尝试通过命令行或者服务管理工具来启动MySQL服务器。 2. 检查MySQL服务器的端口号是否正确。默认情况下,MySQL服务器使用3306端口。如果你的MySQL服务器使用了其他端口,你需要相应地进行配置。 3. 检查防火墙或网络设置,确保允许与MySQL服务器的连接。你可以尝试暂时关闭防火墙来验证是否是防火墙导致的问题。 4. 检查MySQL服务器的配置文件,确保配置正确。特别是检查bind-address选项是否正确设置为允许连接的IP地址。 如果你尝试了以上步骤仍然无法解决问题,你可能需要进一步检查网络配置、MySQL服务器日志以及相关的错误信息来找出问题的具体原因。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法](https://blog.csdn.net/m0_67402236/article/details/126012580)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [解决MySQL报错ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)](https://blog.csdn.net/wangpaiblog/article/details/121667877)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值