About MySQL query Cache Mechanism

Source: Internet
Author: User

The MySQL query mechanism is an important part of the MySQL database. The following describes the MySQL query cache mechanism in detail and hopes to help you.

The cache mechanism simply caches the SQL text and query results. If the same SQL statement is run, the server directly retrieves the results from the cache without parsing and executing the SQL statement. If the table is changed, all buffered queries using this table will no longer be valid, and the items related to the query cache value will be cleared. Changes refer to any data or structure changes in the TABLE, including INSERT, UPDATE, DELETE, TRUNCATE, alter table, drop table, or drop database, this also includes queries for tables mapped to changed tables that use MERGE tables. Obviously, the query cache is not suitable for frequently updated tables. For tables that do not often change data and have a large number of identical SQL queries, the query cache will save a lot of performance.

The query must be exactly the same (in bytes) to be considered the same. In addition, the same query string may be considered different for other reasons. Queries using different databases, different protocol versions, or different default character sets are considered to be different queries and cache them separately.

The following SQL query cache is considered different:
SELECT * FROM tbl_name
Select * from tbl_name

Query cache Parameters

Mysql> show variables like '% query_cache % ';
+ ---------- + --- +
| Variable_name | Value |
+ ---------- + --- +
| Have_query_cache | YES |-query whether the cache is available
| Query_cache_limit | 1048576 |-maximum value of a specific query result that can be cached
| Query_cache_min_res_unit | 4096 |
| Query_cache_size | 599040 |-query the cache size
| Query_cache_type | ON |-blocked or supported query Cache
| Query_cache_wlock_invalidate | OFF |
+ ---------- + --- +
 

Use MySQL temporary tables to accelerate queries

How does MySQL modify indexes in a table structure?

Modify Table Structure in MySQL -- add and delete Fields

10 common MySQL command lines

Seven common MySQL command lines

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.