Disable Query Caching for Accurate Speed Testing in MySQL
When conducting performance tests on MySQL queries, caching can significantly distort results, obscuring the true execution speed. This article addresses the question of how to disable caching for specific queries in MySQL.
To prevent MySQL from caching the results of a query, use the SQL_NO_CACHE option. This directive, introduced in MySQL 5.7, explicitly instructs the optimizer to bypass the cache and retrieve data directly from the database.
Example:
SELECT SQL_NO_CACHE * FROM table_name;
By incorporating this option into the query, you effectively disable server-side caching for that particular execution. However, it's important to note that other factors like operating system and disk caching can still impact performance. These caches external to MySQL are harder to circumvent.
The above is the detailed content of How to Disable Query Caching for Accurate Speed Testing in MySQL?. For more information, please follow other related articles on the PHP Chinese website!