mysql> SHOW VARIABLES LIKE 'have_query_cache';+------------------+-------+| Variable_name | Value |+------------------+-------+| have_query_cache | YES |+------------------+-------+1 row in set (0.26 sec)
代表当前数据库支持查询缓存
查看当前MySQL是否开启了查询缓存 :
1
mysql> SHOW VARIABLES LIKE 'query_cache_type';+------------------+-------+| Variable_name | Value |+------------------+-------+| query_cache_type | OFF |+------------------+-------+1 row in set (0.01 sec)
代表当前没有开启查询缓存
查看查询缓存的占用大小 :
1
mysql> SHOW VARIABLES LIKE 'query_cache_size';+------------------+----------+| Variable_name | Value |+------------------+----------+| query_cache_size | 16777216 |+------------------+----------+
mysql> select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (8.57 sec)mysql> select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (0.00 sec)
SQL1 : select count(*) from tb_item;SQL2 : Select count(*) from tb_item;
仅大小写不同。
1
mysql> select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (0.00 sec)mysql> Select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (2.02 sec)
6) 如果表更改,则使用该表的所有高速缓存查询都将变为无效并从高速缓存中删除。这包括使用MERGE映射到已更改表的表的查询。一个表可以被许多类型的语句,如被改变 INSERT, UPDATE, DELETE, TRUNCATE TABLE, ALTER TABLE, DROP TABLE,或 DROP DATABASE 。
1
2
3
mysql> Select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (0.00 sec)mysql> update tb_item set title='test1'where id=5;Query OK, 1 row affected (0.05 sec)Rows matched: 1 Changed: 1 Warnings: 0
mysql> Select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (1.23 sec)mysql> Select count(*) from tb_item;+----------+| count(*) |+----------+| 2499695 |+----------+1 row in set (0.00 sec)