溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么解決mysql中的ERROR 1135 (HY000)報(bào)錯(cuò)問題

發(fā)布時(shí)間:2021-11-18 15:48:37 來源:億速云 閱讀:477 作者:iii 欄目:MySQL數(shù)據(jù)庫

這篇文章主要講解了“怎么解決mysql中的ERROR 1135 (HY000)報(bào)錯(cuò)問題”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么解決mysql中的ERROR 1135 (HY000)報(bào)錯(cuò)問題”吧!

收到報(bào)錯(cuò):

[root@i-iivphroy ~]# mysql -uroot -p*********  -h292.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一番,有人說可能說磁盤空間滿了,經(jīng)查看發(fā)現(xiàn)果然是磁盤滿了,(這個(gè)盤一直空間很緊張(95%),我高度警惕著,天天檢查,可是昨天我執(zhí)行了個(gè)大事務(wù),產(chǎn)生了大量的binlog,給一下子撐爆了)

馬上刪除了幾天前的binlog和一些別的不需要的數(shù)據(jù),空間釋放到了80%,再次登錄mysql

[root@i-iivphroy ~]# mysql -uroot -p******* -h292.168.0.254

依舊報(bào)錯(cuò):

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一番,查到下面這個(gè)文檔:

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

大體的意思是說,這個(gè)報(bào)錯(cuò)的原因:由于:mysql的配置文件/etc/my.cnf的參數(shù)open-files-limit設(shè)置的比linux的max user processes的數(shù)值大,需要通過修改linux的配置文件 /etc/security/limits.d/90-nproc.conf來擴(kuò)大linux系統(tǒng)的限制,也就是這個(gè)錯(cuò)是由于linux的max user processes閾值太小了。

馬上查看我的相關(guān)配置:

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對應(yīng)open_files

nproc對應(yīng)max_user_processes

但是在Linux 6.4之后,如果只修改了該文件中的nproc,那么其他非root用戶對應(yīng)的max_user_processes并不會改變,仍然是1024,這個(gè)是因?yàn)槭艿搅讼旅孢@個(gè)文件的影響

/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

方法二:這樣為每一個(gè)運(yùn)行bash shell的用戶執(zhí)行此文件,當(dāng)bash shell被打開時(shí),該文件被讀取。也就是說,當(dāng)用戶shell執(zhí)行了bash時(shí),運(yùn)行這個(gè)文件,如果這個(gè)服務(wù)器上有多個(gè)用戶,最好是用方法一。

修改了/etc/bashrc,成功了,并且不用重啟。

vi /etc/bashrc

添加 :

ulimit -u 65535

退出session,從新開session再次ulimit -a 發(fā)現(xiàn)已經(jīng)變化了

[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服務(wù),問題解決。。。。

原因分析:

操作系統(tǒng)連接數(shù)太小。(比如centos 6 默認(rèn)的  max user process只有 1024個(gè)。當(dāng)mysql process大于這個(gè)值時(shí) 就會出現(xiàn)Can't create a new thread的問題)

連接數(shù)超限處理的辦法:

ulimit -a

查看max user processes 這一項(xiàng)

要是這個(gè)值比較的小 當(dāng)mysql中process的數(shù)目超過這個(gè)數(shù)的時(shí)候 就會抱標(biāo)題相應(yīng)的錯(cuò)誤。

一個(gè)過程process可以視為一個(gè)打開的文件

也就是說 下面幾個(gè)參數(shù)共同控制這mysql的 create a new thread

1) mysql的 /etc/my.cnf

open-files-limit=65535

2)linux  參數(shù)   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中的ERROR 1135 (HY000)報(bào)錯(cuò)問題”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么解決mysql中的ERROR 1135 (HY000)報(bào)錯(cuò)問題這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI