MySQL Query cache summary

Source: Internet
Author: User
Tags mysql query

The current query cache correlation parameter status can be viewed from the following SQL: SHOW VARIABLES like '%query_cache% ';The output is similar to the following: Query_cache_typeThe query cache type has 0, 1, and 23 values. 0 does not use the query cache. 1 means that the query cache is always used.     2 means the query cache is used on demand.    If Query_cache_type is 1 and you do not want to use the data in the query cache, you can use the following Sql:select Sql_no_cache * from my_table WHERE condition; If the value is 2, the sql_cache switch parameter is required to use the cache: SELECT Sql_cache * from my_table WHERE condition; query_cache_sizeBy default, Query_cache_size is 0, which indicates that the memory reserved for the query cache is 0, and the query cache cannot be used.    So we need to set the value of Query_cache_size: Set GLOBAL query_cache_size = 134217728; Note that the above values do not take effect if they are set too small. For example, I use the following SQL to set Query_cache_size size: set GLOBAL query_cache_size = 4000; SHOW WARNINGS;The following results are returned: Cache ConditionThe query cache can be seen as a mapping of SQL text and query results. If the SQL for the second query is exactly the same as the SQL for the first query (note that it must be exactly the same, even if more than one space or case is different) and the query cache is turned on, then the second query takes the result directly from the query cache.    You can see the number of cache hits (a cumulative value) by using the following SQL: Show STATUS like ' qcache_hits '; In addition, even if the exact same SQL is used, different character sets, different protocols, and so on will be considered as different queries and cached separately. Cache data Failure TimeWhen the structure or data of a table changes, the data in the query cache is no longer valid. Having these insert, UPDATE, DELETE, TRUNCATE, ALTER table, drop table, or drop database causes the cache data to be invalidated. So the query cache is suitable for applications with a large number of identical queries and is not suitable for applications with large amounts of data updates. You can use the following three SQL to clean up the query cache:1, FLUSH QUERY CACHE; Cleans up query cache memory fragmentation. 2, RESET QUERY CACHE; Removes all queries from the query cache. 3, FLUSH TABLES; Closes all open tables, and the operation empties the contents of the query cache.

MySQL Query cache summary

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.