mysql 的缓存记录方式

来源:互联网 发布:java service生命周期 编辑:程序博客网 时间:2024/05/10 15:48

     MySQL的缓存是对查询语句进行缓存。就是说

SELECT * FROM table1进行查询 和

SELECT * FROM table1 LIMIT 1

SELECT * FROM table1 LIMIT 2等几条查询的缓存是不同的。三条语句都不会利用另外两条语句的缓存,而是需要自己重新去查询。对缓存的结果,只要表记录发生改变,缓存就失效。如

当前表结构为 create table helloworld (id int)engine=innodb;

表内容为:

insert into helloworld(id) values(1);

insert into helloworld(id)  values(2);

insert into helloworld(id) values(3);

 

select * from helloworld;

select * from helloworld where id=1;

select * from helloworld where id =2;

select * from helloworld where id =3;

select * from helloworld limit 1;

上面几条语句都不会使用彼此的缓存,而当该语句进行查询后,该语句的执行结果就会被缓存了。

但是对表的修改导致表的缓存失效。

insert/update对表进行操作后,表的缓存就会失效。

是不是说对更新频繁的表其实可以关闭该缓存了。

 

原创粉丝点击