Enable MySQL query cache to speed up database reading

Source: Internet
Author: User

If the MySQL server is busy during website construction or operation, you can enable the query cache to accelerate the response time. add the following items to CNF: (/etc/My. CNF; Debian is in ETC/MySQL

/My. CNF ).

Query_cache_size = 64 m
Query_cache_type = 1
Query_cache_limit = 1048576

In the above syntax settings, query_cache_size is to allocate 256 MB of memory space to the query
Cache; query_cache_type is set to 1, which is used to cache all queries; query_cache_limit
It is the memory space of 1 kb of a specific query statement.

These values can be changed according to your own needs. After setting and archiving, restart MySQL.

Query cache plays an important role in improving database performance.

The configuration is also very simple. You only need to write two rows in the configuration file: query_cache_type and query_cache _ size, and MySQL's query cache is very fast! In addition, once hit, it is directly sent to the client, saving a lot of CPU time.

Of course, non-select statements have an impact on the buffer, and they may cause the data in the buffer to expire. One update
Some table modifications caused by the statement will invalidate all the buffered data in the table. This is the measure that MySQL has not taken to balance the performance. Because, if each update
You need to check the modified data and then withdraw some of the buffer, which will increase the complexity of the Code.

Query_cache_type 0 indicates that no buffer is used. 1 indicates that the buffer is used, and 2 indicates that the buffer is used as needed.
In fact, there is a memory table in MySQL, so you don't need this function. For query cache, MySQL provides the query_cache_type variable to control whether the SQL statements sent to the database are cached. There are three values:

0. Do not cache SQL statements.
1. SQL statements with SQL _no_cache prompt are not cached.
2. cache only the SQL statements with SQL _cache instructions.

 

Switch from: Enable MySQL query cache to speed up database reading

 

There is also a document that can help you learn http://hi.baidu.com/xytel/blog/item/d74d4c1204e4d959f919b827.html

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.