MySQL查询caching已启用,但未被使用

我检查了查询caching已启用

mysql> SHOW VARIABLES LIKE 'have_query_cache'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | have_query_cache | YES | +------------------+-------+ 1 row in set (0.00 sec) 

但似乎没有被使用

 mysql> SHOW STATUS LIKE 'Qcache%'; +-------------------------+----------+ | Variable_name | Value | +-------------------------+----------+ | Qcache_free_blocks | 1 | | Qcache_free_memory | 16759648 | | Qcache_hits | 0 | | Qcache_inserts | 0 | | Qcache_lowmem_prunes | 0 | | Qcache_not_cached | 21555882 | | Qcache_queries_in_cache | 0 | | Qcache_total_blocks | 1 | +-------------------------+----------+ 8 rows in set (0.00 sec) 

任何原因?

系统variablesquery_cache_type也需要设置为非零,因为caching的存在并不意味着它可以被使用。

请注意,并非所有查询都可以caching。

例如,如果一个查询包含NOW()这样的函数,它将不会被caching。 请查看无法caching哪些查询的详细说明: https : //dev.mysql.com/doc/refman/5.7/en/query-cache-operation.html

您还应该检查在configuration文件中将您的设置写入了哪个位置。

我的问题是,我把我的qchace设置在文件的末尾。 虽然这些设置是通过执行mysql> SHOW STATUS LIKE 'Qcache%'; 实际上没有查询被caching。

将设置放在文件的不同位置,然后重新启动正在工作的mysql服务器。

在这里你可以看到我的MySQL 5.6的configuration:

 [mysqld] bind-address=* #skip-networking # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock query_cache_type = 1 query_cache_size =256M thread_concurrency=2 sort_buffer_size=25M key_buffer=128M # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 

有一个MySQL 5.6的错误 ,在5.6.9中修复:“ if the db name (or table name) has a '-' (minus), it does not work ”,仅在InnoDB上。