mysql cache settings

Some sql runtimes are time-consuming, consume system resources, and cannot be further optimized, and each time data is obtained, it does not change much.
Then cache the information obtained by this sql statement for the next execution.
This saves system resources.

View query cache size


mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.58 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.64 sec)

mysql> show variables like 'query_%';
+------------------------------+----------+
| Variable_name                | Value    |
+------------------------------+----------+
| query_alloc_block_size       | 8192     |
| query_cache_limit            | 1048576  |
| query_cache_min_res_unit     | 4096     |
| query_cache_size             | 67108864 |
| query_cache_type             | OFF      |
| query_cache_wlock_invalidate | OFF      |
| query_prealloc_size          | 8192     |
+------------------------------+----------+
7 rows in set (0.00 sec)

mysql> set global query_cache_size=64*1024*1024;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set global query_cache_size=0;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show variables like 'query_%';
+------------------------------+---------+
| Variable_name                | Value   |
+------------------------------+---------+
| query_alloc_block_size       | 8192    |
| query_cache_limit            | 1048576 |
| query_cache_min_res_unit     | 4096    |
| query_cache_size             | 0       |
| query_cache_type             | OFF     |
| query_cache_wlock_invalidate | OFF     |
| query_prealloc_size          | 8192    |
+------------------------------+---------+
7 rows in set (0.00 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.77 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.59 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.60 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.63 sec)

mysql> set global query_cache_size=64*1024*1024;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.58 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.58 sec)

mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.61 sec)

mysql> 

cache invalidation

If the data of the data table changes, or the structure of the data table changes, the cache is invalid.

what not to use caching

The data obtained by the sql statement changes each time

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325786851&siteId=291194637