MySQL is currently the most popular relational database management system. In order to improve the performance of MySQL, it is sometimes necessary to clear its cache.
Clear the MySQL cache, sometimes called the MySQL internal cache or query cache. This cache is an optimization solution for MySQL query execution, which reduces query execution time by caching results.
So, why do you sometimes need to clear the MySQL cache? There are two main situations:
Now, let’s learn how to clear the MySQL cache.
1. Command to clear MySQL cache
The cache can be cleared through the MySQL flush command, but it should be noted that the flush command will clear all caches, so you need to be careful when using it.
First connect to the MySQL server, you can use the following command:
mysql -u 用户名 -p
Then enter the password, after connecting, you can use the following command to clear the cache:
FLUSH QUERY CACHE;
This command can clear the query cache on the MySQL server and let MySQL re-cache new query results in subsequent queries.
FLUSH TABLES;
This command will close all open tables and instruct MySQL to reopen it when the next table is opened.
RESET QUERY CACHE; FLUSH TABLES;
This command will clear the query cache and table cache. Also tells MySQL to reopen and close all open tables.
2. Tools for clearing MYSQL cache
In addition to using the MySQL flush command to clear the cache, you can also use some third-party cache cleaning tools. These tools make it easier to manage caches and provide other advanced features.
MySQLTuner is an open source MySQL consulting script that checks the security and performance of a MySQL instance and makes recommendations.
This script can also clean the cache, restart the MySQL instance and other functions. It can be installed through the following command:
yum install -y epel-release yum install -y perl perl-DBI perl-DBD-MySQL perl-Time-HiRes wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
Next, run the following command to get started:
perl mysqltuner.pl
MaxScale is a version of MariaDB A proxy tool that can be used to distribute queries on MariaDB and MySQL clusters and provide current limiting and load balancing based on users, transactions, and SQL statements. In addition, MaxScale also provides MySQL cache cleaning function.
MaxScale is free and open source and can be installed through the following command:
yum install maxscale
After the installation is complete, configure the MaxAdmin and MaxScale process passwords in the MaxScale configuration file to use MaxScale.
The above is the method to clear the MySQL cache. I hope it will be helpful to you.
The above is the detailed content of How to clear mysql cache. For more information, please follow other related articles on the PHP Chinese website!