MySQL Variables query_cache_type 数据库 参数变量解释及正确配置使用
本站中文解释
query_cache_type 是 MySQL 的一个服务器变量,用于控制 MySQL 查询缓存的活动级别,它接受下列可能值:
0:禁用缓存;
1:启用缓存;
2:只查询缓存,不缓存任何新查询。
在 MySQL 中,可以使用如下语句来设置 query_cache_type:
SET GLOBAL query_cache_type = ;
例如,要将 query_cache_type 设置为启用状态(1),可以使用如下语句:
SET GLOBAL query_cache_type = 1;
官方英文解释
query_cache_type
Command-Line Format | --query-cache-type=# |
---|---|
Deprecated | 5.7.20 |
System Variable | query_cache_type |
Scope | Global, Session |
Dynamic | Yes |
Type | Enumeration |
Default Value | 0 |
Valid Values |
|
Set the query cache type. Setting the
GLOBAL
value sets the type for all clients
that connect thereafter. Individual clients can set the
SESSION
value to affect their own use of
the query cache. Possible values are shown in the following
table.
Option | Description |
---|---|
0 or OFF |
Do not cache results in or retrieve results from the query cache. Note that this does not deallocate the query cache buffer. To do that, you should set query_cache_size to 0. |
1 or ON |
Cache all cacheable query results except for those that begin withSELECT SQL_NO_CACHE . |
2 or DEMAND |
Cache results only for cacheable queries that begin with SELECT . |
This variable defaults to OFF
.
If the server is started with
query_cache_type
set to 0, it does not
acquire the query cache mutex at all, which means that the
query cache cannot be enabled at runtime and there is reduced
overhead in query execution.
The query cache is deprecated as of MySQL 5.7.20, and is
removed in MySQL 8.0. Deprecation includes
query_cache_type
.