Home  >  Article  >  Database  >  MySQL database's own cache settings and paging

MySQL database's own cache settings and paging

黄舟
黄舟Original
2017-08-07 13:27:521672browse

MySQL itself provides a function that can cache query results. Note: Strictly based on the case of the sql statement.

Database MySQL's own cache settings use:

1. You need to enable MySQL's own cache function

# show variables like “%cache%”

MySQL databases own cache settings and paging

2.query_cache_type: The startup state of MySQL's own cache is on by default, but there is no space size

query_cache_size: The size of MySQL's own cache, the unit is B (bytes)

If you need to set MySQL's own cache to 32 M

# set global query_cache_size = 1024 * 1024 * 32;

Do some comparison tests

 query_cache_size=0;

MySQL databases own cache settings and paging

3. Query

MySQL databases own cache settings and paging

4. Enable MySQL’s own cache (32M space)

MySQL databases own cache settings and paging

#5. When the word case of the query statement is modified, the query result remains unchanged, but MySQL’s own cache thinks this is a different query. Will be cached here (MySQL's own cache is strictly based on the case of the sql statement)

MySQL databases own cache settings and paging

Paging:

1.

1). Generally, when paging, it is handled like this

# select * from news  limit offset,number;

When As the number of pages increases, the time it takes for MySQL to execute the query becomes significantly longer

2). Mainly because MySQL operates like this when performing the limit operation

First take out the offset+number data, discard the offset data, and return the number data.

MySQL databases own cache settings and paging

MySQL databases own cache settings and paging

MySQL databases own cache settings and paging

2.

1). Generally, in order to prevent the occurrence of this kind of behavior in MySQL, you can use:

# select * from news where id > 1000 limit 10;

2). Through the following comparison test, it is found that in the second type of paging processing, you can also use Primary key ID index can obviously speed up. So paging can be handled this way in the future.

MySQL databases own cache settings and paging

MySQL databases own cache settings and paging

Notes

Note: Strictly based on the case of the sql statement.

The above is the detailed content of MySQL database's own cache settings and paging. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn