Two ways to turn off query caching (QC) for MySQL

Source: Internet
Author: User
Tags mysql query

MySQL Query Cache caches the select query, which is on by default when installed, but if the table is insert, UPDATE, DELETE, TRUNCATE, ALTER table, drop table, or drop Databa SE and other operations, the previous cache is invalid and deleted. This will also affect the performance of our database in some way. So it's unwise to turn on caching for some frequent change tables. There is another situation when we test database performance, we also close the cache, to avoid the impact of the cache on our test data. Here are two scenarios that do not use caching: The first: The schema first looks at the cache of the database is turned on show variables like "%cache%"; MySQL close query cache (QC) two ways to view cache hit situation show status like "%qcache%"; MySQL Close the query cache (QC) two methods and then query the table two times, you can see, the second obvious cache of data. Then look at the two ways that the hit cache becomes 1MySQL shut down the query cache (QC) and start shutting down the cache. There are two ways to turn off caching, one temporary, one permanent. The temporary direct re-command line executes the set global Query_cache_size=0set global query_cache_type=0 permanently modifies the configuration file my.cnf, adding the following configuration. Query_cache_type=0query_cache_size=0 We use permanent modification method MySQL close the query cache (QC) Two methods notice to restart the database, and then go to see MySQL close query cache (QC) two methods and then start querying The cache is obviously not hit. MySQL close query cache (QC) Two methods The second scenario: if we turn on the cache again we make some changes to the SQL statement select Sql_no_cache COUNT (*) from users; Do not cache Select Sql_cache count (*) from users; Cache (also can not add, the default cache is already turned on) first look at the database cache open in the MySQL close query cache (QC) two methods cache hit to 0MySQL close query cache (QC) two methods and then start the query, two times after the query found that the cache hit rate is still 0, obviously no query cache. MySQL close query cache (QC) of the two methods and then do not add Sql_no_cache query, it is clear that the cache hit is 1, start the query cache MySQL close query cache (QC) two methods

Two ways to turn off query caching (QC) for MySQL

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.