How to calculate the number of opened files in MySQL (2) _ MySQL

Source: Internet
Author: User
How to calculate the number of opened files in MySQL (2) bitsCN.com

4. flush tables and check again

Mysql> flush tables;
Mysql> show global status like 'open _ % ';
+ ------------------------ + ------- +
| Variable_name | Value |
+ ------------------------ + ------- +
| Open_files | 1 |
| Open_streams | 0 |
| Open_table_definitions | 0 |
| Open_tables | 0 |
| Opened_files | 52 |
| Opened_tables | 15 |
+ ------------------------ + ------- +
Lsof | grep/home/mysql
...
Mysqld 24349 mysql 5u unix 0x000001041e8de040 4244009/home/mysql. sock
Mysqld 24349 mysql 22u unix 0x00000102108ff980 4244128/home/mysql. sock
...
We can see that after the flush operation, all file descriptors are released.
The test shows that the other opened file descriptor is used by the slow query log.
If a large number of MyISAM tables exist, pay special attention to whether the number of opened files exceeds the limit.
II. Principles
Next, take a closer look at the parameters related to the maximum number of files:
Table_cache (The new version is changed to table_open_cache) The number of cached open tables.
Open_files_limit If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit ().
If this value is 0 then mysqld will reserve max_connections * 5 or max_connections + table_cache * 2 (whichever is larger)
Number of files.
If open_files_limit is not set to 0, the result calculated by the setrlimit () function prevails. if it is set to 0, the actual value is max_connections * 5 or max_connections + table_cache * 2.
Therefore, to solve the problem that the number of opened files exceeds the limit, you also need to combine the system kernel limits (ulimit-n), mysqld's own limits (open_files_limit), and the number of table caches (table_open_cache) and other factors.
However, in actual tests, we found that this was not the case. open_files_limit adopted the kernel's maximum limit, not the above calculation results.
1. View kernel restrictions
Ulimit-n
65535
2. modify my. cnf restrictions

Vi/etc/my. cnf
...
Open_files_limit = 10000
...
3. restart mysqld
/Etc/init. d/mysql restart
4. View Results

Mysql> show global variables like '% open % ';
| Open_files_limit | 65535 |
| Table_open_cache | 1000 |
5. check if open_files_limit is not set.

Vi/etc/my. cnf
...
# Open_files_limit = 10000
...
Restart
/Etc/init. d/mysql restart
View
Mysql> show global variables like '% open % ';
| Open_files_limit | 65535 |
| Table_open_cache | 1000 |

BitsCN.com

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.