MySQL缓存的查询和清除命令使用详解
Mysql 查询缓存 query_cache_size=10M query_cache_type=1 可以用如下命令查看是否开启,其中have_query_cache为是否开启,query_cache_limit 指定单个查询能够使用的缓冲区大小,缺省为1M;query_cache_min_res_unit为系统分配的最小缓存块大小,默认是4KB,设置值大对大数据查询有好处,但如果你的查询都是小数据 查询,就容易造成内存碎片和浪费;query_cache_size和query_cache_type就是上面我们的配置;query_cache_wlock_invalidate表示当有其他客户端正在对MyISAM表进行写操作时,如果查询在query cache中,是否返回cache结果还是等写操作完成再读表获取结果。 mysql> show variables like '%query_cache%'; +------------------------------+----------+ | Variable_name | Value | +------------------------------+----------+ | have_query_cache | YES | | query_cache_limit | 1048576 | | query_cache_min_res_unit | 4096 | | query_cache_size | 10485760 | | query_cache_type | ON | | query_cache_wlock_invalidate | OFF | +------------------------------+----------+ 6 rows in set (0.00 sec) 2.测试 mysql> select count(*) from wei ; +----------+ | count(*) | +----------+ | 4194304 | +----------+ 1 row in set (3.92 sec) mysql> select count(*) from wei ; +----------+ | count(*) | +----------+ | 4194304 | +----------+ 1 row in set (0.00 sec) 我们可以通过如下命令查看现在缓存的情况 mysql> show status like 'qcache%'; +-------------------------+----------+ | Variable_name | Value | +-------------------------+----------+ | Qcache_free_blocks | 1 | | Qcache_free_memory | 10475424 | | Qcache_hits | 1 | | Qcache_inserts | 1 | | Qcache_lowmem_prunes | 0 | | Qcache_not_cached | 0 | | Qcache_queries_in_cache | 1 | | Qcache_total_blocks | 4 | +-------------------------+----------+ 8 rows in set (0.00 sec) 其中各个参数的意义如下:
FLUSH flush_option [,flush_option] 如果你想要清除一些MySQL使用内部缓存,你应该使用FLUSH命令。为了执行FLUSH,你必须有reload权限。
一般来讲,Flush操作都会记录在二进制日志文件中,但是FLUSH LOGS、FLUSH MASTER、FLUSH SLAVE、FLUSH TABLES WITH READ LOCK不会记录,因此上述操作如果记录在二进制日志文件中话,会对从数据库造成影响。注意:Reset操作其实扮演的是一个Flush操作的增强版的角色。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |