Exception error due to insufficient MySQL database resources

Source: Internet
Author: User

A few days ago, I encountered a strange problem in the management system. Today I have the opportunity to install the MySQL environment to reproduce this problem. Because it is not the most primitive environment, it may not be completely reproduced, I can only try to reproduce the key issues .. I think this problem is a bit special, so I would like to look back at the situation here ..

At work, I executed a su-mysql command and encountered the following error ..

 
 
  1. [root@dbmain ~]# su - mysql   
  2. su: cannot set user id: Resource temporarily unavailable  

This is a problem caused by insufficient resources in Shell. At that time, we subconsciously ran ulimit first to see the basic limits of ulimit.

 
 
  1. [root@dbmain ~]# ulimit -a   
  2. core file size          (blocks, -c) 0   
  3. data seg size           (kbytes, -d) unlimited   
  4. scheduling priority             (-e) 0   
  5. file size               (blocks, -f) unlimited   
  6. pending signals                 (-i) 25600   
  7. max locked memory       (kbytes, -l) 32   
  8. max memory size         (kbytes, -m) unlimited   
  9. 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 

Again,/etc/security/limits. conf

 
 
  1. oracle              soft    nproc   2047   
  2. oracle              hard    nproc   16384   
  3. oracle              soft    nofile  1024   
  4. oracle              hard    nofile  65536   
  5. oracle              soft    memlock        12582912   
  6. oracle              hard   memlock        12582912   
  7. grid              soft    nproc   2047   
  8. grid              hard    nproc   16384   
  9. grid              soft    nofile  1024   
  10. grid              hard    nofile  65536   
  11. grid              soft    memlock        12582912   
  12. grid              hard   memlock        12582912   
  13. mysql             soft    nproc  500   
  14. mysql             hard    nproc  500   
  15. mysql             soft    nofile  1024   
  16. mysql             hard    nofile  65536   
  17. mysql             soft    memlock  12582912   
  18. mysql             hard    memlock  12582912 

After analysis, it is suspected that only the process and file have a high probability of resource shortage. Therefore, ps-ef is used to check the number of processes of the user in the system ..

 
 
  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 

From this output, we temporarily exclude the possibility of nproc exceeding the standard.

Then, enter the proc directory based on the pid of the process to view the number of currently opened files ..

A large number of socket file connections are found .. however, the number of files is far from the limit, and it is suspected that the MySQL thread may also consume the nproc base of the Linux system, so try to adjust/etc/security/limits. the value of the nproc parameter in the conf file.

After the adjustment is found, su-mysql can indeed be successfully executed, and this parameter will be changed back later, and then re-executed su-mysql. This problem is reproduced again .. it is confirmed that, in addition to setting the MySQL parameter max_connections, you must also consider setting/etc/security/limits. the size of the conf file. MySQL is executed in thread mode, and the number of threads is also counted in nproc. This may mask or cause a false judgment on this issue ..

Edit recommendations]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.