The purpose of setting up MySQL query cache is:Cache the query results so that you can directly retrieve them from the result set the next time you execute the same query; this is much faster than searching again. The end result of query caching is that it backfires:There are two objective reasons why query cache does not improve performance: 1. Use the hash value of the SQL statement as the key and the result set of the SQL statement as the value; this raises a problem such as select user from mysql.user and SELECT user FROM mysql.user These two will be treated as different SQL statements. At this time, even if the result set already exists, it will not be used. 2. When the lower-level table on which the query is based is modified, the query cache related to this table will be invalidated. If the system has a large degree of concurrency, this overhead is considerable; the operation of invalidating the result set also requires concurrency. Access control means there will also be locks. When the concurrency is large, Waiting for query cache lock will occur. 3. Whether to use it or not depends on the business model. How to configure the query cache:The query_cache_type system variable controls whether the query cache feature is enabled or disabled. When query_cache_type=0, it means closed, 1 means open, and 2 means caching only when SQL_CACHE is explicitly specified in the select. The setting of this parameter is a bit strange. 1. If the query cache is closed beforehand, but set @@global.query_cache_type=1; an error will be reported ERROR 1651 (HY000): Query cache is disabled; restart the server with query_cache_type=1 to enable it 2. If it was opened beforehand and you try to close it, the closure is incomplete and the query will still try to find the cache. The best way to turn off query cache is to set query_cache_type=0 in my.cnf and then restart mysql. Query cache-related system variables:have_query_cache indicates whether this MySQL version supports query cache. query_cache_limit indicates the maximum value allowed to cache a single result set. query_cache_min_res_unit The minimum memory that each cached result set should occupy. query_cache_size The memory size used for the query cache. How to monitor the query cache hit rate:Qcache_free_memory The current remaining space size of the query cache. Qcache_hits The number of query cache hits. Qcache_inserts The number of query cache insertions. That is to say, the cache hit rate is Qcache_hits/(Qcache_hits+Qcache_inserts) Generally, it is not possible to set this alone. You have to combine it. It is recommended to read the following article You may also be interested in:
|
<<: Simple web design concept color matching
>>: jQuery Ajax chatbot implementation case study
Sublime Sublime Text is a code editor (Sublime Te...
This article example shares the specific code of ...
Preface In databases such as Oracle and SQL Serve...
Tabs: Category + Description Tag bar: Category =&...
Table of contents A chestnut to cover it Paramete...
Question: After the computer restarts, the mysql ...
1. Problems encountered In the process of distrib...
Table of contents Multiple uses of MySQL Load Dat...
When we work in a terminal or console, we may not...
Search online to delete duplicate data and keep t...
Table of contents Preface React Functional Compon...
Table of contents Preface Actual Combat 1. No loc...
This article shares the specific code for the WeC...
The methods of installing nginx and multiple tomc...
When releasing a project, you will often encounte...