The actual procedure of opening files in the MySQL database

Source: Internet
Author: User
The following articles mainly describe how the MySQL database correctly calculates the actual operation flow of the number of opened files. Everyone knows that every time a MyISAM table is opened, two file descriptors must be used for it, so let's verify how the MySQL database calculates the number of opened files. From Manual 6.4.8.HowMySQLOpensandClosesTables

The following articles mainly describe how the MySQL database correctly calculates the actual operation flow of the number of opened files. Everyone knows that every time a MyISAM table is opened, two file descriptors must be used for it, so let's verify how the MySQL database calculates the number of opened files. Test from the manual 6.4.8. How MySQL Opens and Closes Tables can be

The following articles mainly describe how the MySQL database correctly calculates the actual operation flow of the number of opened files. Everyone knows that every time a MyISAM table is opened, two file descriptors must be used for it, so let's verify how the MySQL database calculates the number of opened files.

Test

We can see from the manual "6.4.8. How MySQL Opens and Closes Tables" that every time a MyISAM table is opened, we need two file descriptors for verification.

1. Restart mysqld

 
 
  1. /etc/init.d/mysql restart

2. Check that several files are opened.

 
 
  1. lsof | grep /home/mysql
  2. ...
  3. mysqld 24349 mysql 5u unix 0x000001041e8de040 4244009 /home/mysql/mysql.sock
  4. mysqld 24349 mysql 6u REG 8,33 2048 30425188 /home/mysql/mysql/host.MYI
  5. mysqld 24349 mysql 7u REG 8,33 0 30425189 /home/mysql/mysql/host.MYD
  6. mysqld 24349 mysql 8u REG 8,33 2048 30425153 /home/mysql/mysql/user.MYI
  7. mysqld 24349 mysql 9u REG 8,33 892 30425155 /home/mysql/mysql/user.MYD
  8. mysqld 24349 mysql 10u REG 8,33 5120 30425126 /home/mysql/mysql/db.MYI
  9. mysqld 24349 mysql 11u REG 8,33 3080 30425148 /home/mysql/mysql/db.MYD
  10. mysqld 24349 mysql 12u REG 8,33 4096 30425154 /home/mysql/mysql/tables_priv.MYI
  11. mysqld 24349 mysql 13u REG 8,33 0 30425157 /home/mysql/mysql/tables_priv.MYD
  12. mysqld 24349 mysql 14u REG 8,33 4096 30425143 /home/mysql/mysql/columns_priv.MYI
  13. mysqld 24349 mysql 15u REG 8,33 0 30425156 /home/mysql/mysql/columns_priv.MYD
  14. mysqld 24349 mysql 16u REG 8,33 4096 30425127 /home/mysql/mysql/procs_priv.MYI
  15. mysqld 24349 mysql 17u REG 8,33 0 30425136 /home/mysql/mysql/procs_priv.MYD
  16. mysqld 24349 mysql 18u REG 8,33 1024 30425173 /home/mysql/mysql/servers.MYI
  17. mysqld 24349 mysql 19u REG 8,33 0 30425174 /home/mysql/mysql/servers.MYD
  18. mysqld 24349 mysql 20u REG 8,33 2048 30425182 /home/mysql/mysql/event.MYI
  19. mysqld 24349 mysql 21u REG 8,33 0 30425183 /home/mysql/mysql/event.MYD
  20. ...

We can see that a total of eight tables are opened, and each table has two file descriptors of the MySQL database, which seems to be correct.

3. Check the status result again.

 
 
  1. mysql>show global status like 'open_%';
  2. +------------------------+-------+
  3. | Variable_name | Value |
  4. +------------------------+-------+
  5. | Open_files | 17 |
  6. | Open_streams | 0 |
  7. | Open_table_definitions | 15 |
  8. | Open_tables | 8 |
  9. | Opened_files | 52 |
  10. | Opened_tables | 15 |
  11. +------------------------+-------+

4. flush tables and check again

 
 
  1. mysql>flush tables;
  2. mysql> show global status like 'open_%';
  3. +------------------------+-------+
  4. | Variable_name | Value |
  5. +------------------------+-------+
  6. | Open_files | 1 |
  7. | Open_streams | 0 |
  8. | Open_table_definitions | 0 |
  9. | Open_tables | 0 |
  10. | Opened_files | 52 |
  11. | Opened_tables | 15 |
  12. +------------------------+-------+
  13. lsof | grep /home/mysql
  14. ...
  15. mysqld 24349 mysql 5u unix 0x000001041e8de040 4244009 /home/mysql/mysql.sock
  16. mysqld 24349 mysql 22u unix 0x00000102378ff980 4244128 /home/mysql/mysql.sock
  17. ...

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.

The above content introduces how to calculate the number of opened files in the MySQL database.

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.