共計 5023 個字符,預計需要花費 13 分鐘才能閱讀完成。
這篇文章主要講解了“怎么解決 mysql 中的 ERROR 1135 (HY000) 報錯問題”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“怎么解決 mysql 中的 ERROR 1135 (HY000) 報錯問題”吧!
收到報錯:
[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 一番,有人說可能說磁盤空間滿了,經查看發現果然是磁盤滿了,(這個盤一直空間很緊張(95%),我高度警惕著,天天檢查,可是昨天我執行了個大事務,產生了大量的 binlog,給一下子撐爆了)
馬上刪除了幾天前的 binlog 和一些別的不需要的數據,空間釋放到了 80%,再次登錄 mysql
[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 一番,查到下面這個文檔:
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 中的 ERROR 1135 (HY000) 報錯問題”的內容了,經過本文的學習后,相信大家對怎么解決 mysql 中的 ERROR 1135 (HY000) 報錯問題這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!