IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機版|論壇轉貼|軟件發(fā)布

您當前所在位置:首頁數(shù)據(jù)庫MYSQL → 詳解MySQL數(shù)據(jù)庫資源不足的錯誤解決方案

詳解MySQL數(shù)據(jù)庫資源不足的錯誤解決方案

時間:2015/6/28來源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評論(0)

前幾天,在管理系統(tǒng)的時候遇到一個奇怪的問題, 今天才有機會安裝好mysql環(huán)境來重現(xiàn)此問題,由于不是最原始的環(huán)境, 所以未必能夠完全重現(xiàn), 我只能努力重現(xiàn)關鍵問題了.. 我覺得此問題有點特別, 故在此大概的回想下當時的情景..

工作時, 執(zhí)行了一個su – mysql 的命令, 遇到了下面這樣一個錯誤..

view sourceprint?1 [root@dbmain ~]# su - mysql 

2 su: cannot set user id: Resource temporarily unavailable

這是一個Shell中由于資源不足引起的問題, 當時下意識的先運行ulimit,看看ulimit的基本限制.

view sourceprint?01 [root@dbmain ~]# ulimit -a 

02 core file size    (blocks, -c) 0 

03 data seg size     (kbytes, -d) unlimited 

04 scheduling priority (-e) 0 

05 file size   (blocks, -f) unlimited 

06 pending signals     (-i) 25600 

07 max locked memory (kbytes, -l) 32 

08 max memory size   (kbytes, -m) unlimited 

09 open files    (-n) 1024 

10 pipe size      (512 bytes, -p) 8 

11 POSIX message queues     (bytes, -q) 819200 

12 real-time priority  (-r) 0 

13 stack size  (kbytes, -s) 10240 

14 cpu time   (seconds, -t) unlimited 

15 max user processes  (-u) 25600 

16 virtual memory    (kbytes, -v) unlimited 

17 file locks    (-x) unlimited

又看了看,/etc/security/limits.conf

view sourceprint?01 oracle  soft    nproc   2047 

02 oracle  hard    nproc   16384 

03 oracle  soft    nofile  1024 

04 oracle  hard    nofile  65536 

05 oracle  soft    memlock  12582912 

06 oracle  hard   memlock  12582912 

07   

08 grid  soft    nproc   2047 

09 grid  hard    nproc   16384 

10 grid  soft    nofile  1024 

11 grid  hard    nofile  65536 

12 grid  soft    memlock  12582912 

13 grid  hard   memlock  12582912 

14   

15 mysql soft    nproc  500 

16 mysql hard    nproc  500 

17 mysql soft    nofile  1024 

18 mysql hard    nofile  65536 

19 mysql soft    memlock  12582912 

20 mysql hard    memlock  12582912

經(jīng)過分析,懷疑也只有process/file這兩個出現(xiàn)資源緊張的概率比較大.. 因此就先ps -ef 看系統(tǒng)中該用戶的進程數(shù)量..

view sourceprint?1 [root@dbmain ~]# ps -ef | grep mysql 

2 root      4733     1  0 10:30 ?  00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/dbmain.pid 

3 mysql     4788  4733  0 10:30 ?  00:00:04 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/dbmain.err --pid-file=/var/lib/mysql/dbmain.pid 

4 root     15171 17507  0 13:26 pts/2    00:00:00 mysql -uroot -p 

5 root     20792 17163  0 15:30 pts/1    00:00:00 grep mysql

從這個輸出,,我們暫時排除nproc超標的可能性.

由此, 就根據(jù)此進程的pid進入其proc目錄查看當前打開的文件數(shù)量..

發(fā)現(xiàn)有大量socket的文件連接.. 但是其數(shù)量遠遠未達到文件數(shù)的限制, 由此懷疑可能是MySQL的線程也會消耗掉linux系統(tǒng)的nproc基數(shù), 因此嘗試調整/etc/security/limits.conf文件的nproc參數(shù)的值.

發(fā)現(xiàn)調整過后, su – mysql 確實可以成功執(zhí)行了,,后面又將此參數(shù)改回, 重新執(zhí)行su – mysql,,此問題又再次重現(xiàn)..由此確認,,使用MySQL的系統(tǒng), 在設置MySQL的參數(shù)max_connections之外, 還需要考慮設置/etc/security/limits.conf文件的大小, MySQL是線程模式執(zhí)行的, 其線程數(shù)也會被統(tǒng)計在nproc中, 這可能掩蓋或造成對此問題的誤判..  

關鍵詞標簽:MySQL,數(shù)據(jù)庫,資源不足

相關閱讀

文章評論
發(fā)表評論

熱門文章 10款MySQL數(shù)據(jù)庫客戶端圖形界面管理工具推薦10款MySQL數(shù)據(jù)庫客戶端圖形界面管理工具推薦MySQL常用維護管理工具MySQL常用維護管理工具Linux VPS/服務器上輕松導入、導出MySQL數(shù)據(jù)Linux VPS/服務器上輕松導入、導出MySQL數(shù)據(jù)MySQL復制的概述、安裝、故障、技巧、工具MySQL復制的概述、安裝、故障、技巧、工具

相關下載

人氣排行 MySQL數(shù)據(jù)庫啟動失敗1067進程意外終止的解決辦法總結Mysql 1045錯誤解決辦法10款MySQL數(shù)據(jù)庫客戶端圖形界面管理工具推薦MySQL服務器進程CPU占用100%解決辦法MySQL導出導入命令的用例MySQL無法啟動、無法停止各種解決方法總結三種常用的MySQL建表語句Mysql清空表的實現(xiàn)方法