MySQL query_cache_type parameter and usage details

MySQL query_cache_type parameter and usage details

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:
  • MySQL Query Cache Graphical Explanation
  • MySQL optimization query_cache_limit parameter description
  • Reasons why MySQL cancelled Query Cache
  • MySQL cache startup method and parameter details (query_cache_size)
  • Misunderstandings about MySQL query_cache
  • Analysis of MySQL Query Cache Principle

<<:  Simple web design concept color matching

>>:  jQuery Ajax chatbot implementation case study

Recommend

Share 5 JS high-order functions

Table of contents 1. Introduction 2. Recursion 3....

In-depth explanation of MySQL common index and unique index

Scenario 1. Maintain a citizen system with a fiel...

Syntax alias problem based on delete in mysql

Table of contents MySQL delete syntax alias probl...

Play and save WeChat public account recording files (convert amr files to mp3)

Table of contents Audio transcoding tools princip...

How to implement JavaScript output of Fibonacci sequence

Table of contents topic analyze Basic solution Ba...

Specific use of Linux which command

We often want to find a file in Linux, but we don...

Detailed explanation of Angular component life cycle (I)

Table of contents Overview 1. Hook calling order ...

Vue implements picture verification code when logging in

This article example shares the specific code of ...

Design theory: On the issues of scheme, resources and communication

<br />This problem does not exist in many sm...

js and jquery to achieve tab status bar switching effect

Today we will make a simple case, using js and jq...

How to handle forgotten passwords in Windows Server 2008 R2

What to do if you forget Windows Server 2008R2 So...

How to build and deploy Node project with Docker

Table of contents What is Docker Client-side Dock...

CentOS 7 Forgot Password Solution Process Diagram

need Whether it is a Windows system or a Linux sy...

How to set up swap partition SWAP in Linux 7.7

The Swap partition of the Linux system, that is, ...