我想知道有没有办法减少mysql中打开的文件。
详细信息:
mysql 5.0.92
使用的引擎:MyISAM
显示像“Opened_tables”这样的全局状态:150K
显示像“%open%”这样的变量:
open_files_limit 200000 table_open_cache 40000
尝试过的解决方案:
重新启动服务器:打开的表计数器为 0 但从我的观点来看这不是一个好的解决方案,因为您需要每周重新启动,因为计数器会快速增加
FLUSH TABLES:就像 mysql 文档所说的那样,它应该强制关闭所有正在使用的表,但这并没有发生
那么对这件事有什么想法吗?
最佳答案
一般情况下,多开的表没什么好担心的。如果您接近操作系统限制,您可以在内核设置中增加此限制:
How do I change the number of open files limit in Linux?
MySQL 为每个 session 独立打开表以获得更好的并发性。
The table_open_cache and max_connections system variables affect the maximum number of files the server keeps open. If you increase one or both of these values, you may run up against a limit imposed by your operating system on the per-process number of open file descriptors. Many operating systems permit you to increase the open-files limit, although the method varies widely from system to system.
这里有详细解释
http://dev.mysql.com/doc/refman/5.5/en/table-cache.html
编辑
要验证您的假设,您可以通过 SET GLOBAL table_open_cache := newValue
暂时减少 max_connections
和 table_open_cache
。
无需重启服务器即可动态调整该值。
在 MySQL 5.1 之前,此变量称为 table_cache
我想说的是,降低这个值甚至可能对性能产生负面影响,因为并发读取的可能性较小(队列变长),相反,您应该尝试增加操作系统限制并增加 max_open_files
,但也许我只是不明白这里的意义
关于Mysql减少打开的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14519166/