转自:性能测试指标分析-mysql table_open_cache
    MYSQL默认的table_open_cache为64(存疑,看到一些mysql的table_open_cache均为2000),这个数值是偏小的,如果max_connections较大,则容易引起性能问题。
    表现:数据库查询效率慢,show processlist 发现比较多的查询正在opening table。
    进一步确认,执行以下语句:
    mysql> show global status like ‘open%tables%’;
    Opened_tables数值非常大,说明cache太小,导致要频繁地open table,可以查看下当前的table_open_cache设置;
    默认是64,一些资料推荐把这个数值设置为(max_connections* 查询同时用到的表数)。我实践中发现,一般设置为max_connections就没问题了(如果还不够,可以继续加大,但不能设置大得离谱,可能会引发其他问题)。
    4G内存的机器,建议设置为2048即时生效的设置:
    mysql> set global table_open_cache=2048;
    设置后可以观察一下,如果opening table不再怎么出现,说明此修改是有效的,将其添加到mysql的配置文件,这样数据库重启后仍可保留此设置。

    比较适合的值:
    Open_tables / Opened_tables >= 0.85
    Open_tables / table_open_cache <= 0.95

    附:常见命令
    1)show variables like ‘%table_open_cache%’;
    image.png
    2)show global status like ‘open%tables%’;
    image.png
    3)show processlist;
    image.png
    4)show variables like ‘max_connections’; #最大连接数
    image.png