MySQL Knowledge summary (cache)

Source: Internet
Author: User

1. Caching mechanism Concepts

The caching mechanism is simply to cache SQL text and query results, and if you run the same SQL, the server takes the results directly from the cache without having to parse and execute the SQL. If the table changes, all buffered queries that use the table are no longer valid, and the related entries for the query cache value are emptied. Changes refer to any data or structure changes in the table, including insert, UPDATE, DELETE, TRUNCATE, ALTER table, drop table, or drop database, etc. Also included are those queries that map to a changed table using the merge table. Obviously, the query cache is not suitable for frequently updated tables, and for some tables that do not change data frequently and have a large number of identical SQL queries, the query cache can save a lot of performance.
The query must be exactly the same (byte-wise) to be considered the same. In addition, the same query string may be considered different for other reasons. Queries that use different databases, different protocol versions, or different default character sets are considered to be different queries and are cached separately.

2. Query cache related parameters
MySQL>like'%query_cache%';

3. A simple example:
MySQL> use zzlp;
MySQL> show Tables;

MySQL>Selectcount(*fromuser;

#Qcache_hits表示sql查询在缓存中命中的累计次数, is the cumulative value of
mysql>like'qcache _hits';

#连续查询两次
mysql>  Select Count (*fromuser;
MySQL>  Selectcount(*fromuser;

MySQL>insertintouserSelectfrom-- after inserting data, All SQL caches associated with this table will be emptied of
mysql>Selectcount(* from user;

MySQL>like'qcache_hits';

MySQL>Selectcount(*fromuser;


MySQL>Selectcount(*fromuser;
MySQL>like'qcache_hits';

MySQL Knowledge summary (cache)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.