Home  >  Article  >  Database  >  How to clear cache in mysql

How to clear cache in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-09-11 16:05:466457browse

Mysql clear cache method: use FLUSH syntax to clear the cache. In order to execute FLUSH, you must have reload permission, the syntax is [FLUSH flush_option [,flush_option]].

How to clear cache in mysql

Related learning recommendations: mysql tutorial

Mysql clear cache method :

Clear cache

FLUSH syntax for mysql (clear cache)

FLUSH flush_option [,flush_option]

If you want to clear some internal cache used by MySQL, you should use the FLUSH command. In order to execute FLUSH, you must have reload permission.

flush_option can be any of the following:

  • HOSTS This is the most used and often encountered. Mainly used to clear the host cache table. If some of your hosts change IP numbers, or if you get the error message Host... isblocked, you should clear the host table. When more than max_connect_errors errors occur continuously for a given host when connecting to the MySQL server, MySQL will block further connection requests from that host for security reasons. Clearing the host table allows the host to try connecting again.

  • LOGS Close the current binary log file and create a new file. The name of the new binary log file is added to the number of the current binary file by 1.

  • PRIVILEGES This is also often used. Whenever re-authorization is performed, in order to make the new permissions take effect immediately just in case, it is usually executed. The purpose is to obtain the authorization table from the database. Reload the permissions into the cache.

  • TABLES Close all open tables, and this operation will clear the contents of the query cache.

  • FLUSH TABLES WITH READ LOCK Close all open tables and add a read lock to all tables in the database until unlock tables are explicitly executed. This operation is often used for data backup. when.

  • STATUS Reset most status variables to 0.

  • ##MASTER Delete all binary log files in the binary log index file, reset the index file of the binary log file to empty, and create a new binary log file. However, this is no longer recommended. Use, changed to reset master. As you can imagine, I was very naive in the past. It could be done with one simple command, but it took several commands. The previous method was to find out the name of the current binary log file first, and then use the purge operation.

  • QUERY CACHE Reorganizes the query cache, eliminates fragments, and improves performance, but does not affect the existing data in the query cache. This is the same as Flush table and Reset Query Cache (will Will clear the contents of the query cache) are different.

  • SLAVE is similar to resetting replication. It makes the slave database forget the replication location of the master database, and also deletes the downloaded relay log. Like the Master, it is no longer recommended. Changed to Reset Slave. This is also very useful.

Generally speaking, Flush operations are recorded in binary log files, but

FLUSH LOGS, FLUSH MASTER, FLUSH SLAVE , FLUSH TABLES WITH READ LOCK will not be recorded, so if the above operations are recorded in the binary log file, it will affect the slave database.

Note: The Reset operation actually plays the role of an enhanced version of the Flush operation.

If you want to know more about programming learning, please pay attention to the

php training column!

The above is the detailed content of How to clear cache in mysql. 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