MySQL 如何清除mysql中的查询缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4561292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:08:56  来源:igfitidea点击:

How to clear query cache in mysql?

mysqlsql

提问by AMD

I tried this at root prompt but didnt help.

我在 root 提示符下尝试过这个,但没有帮助。

mysql> RESET QUERY CACHE;

IT showed

这显示了

Query OK, 0 rows affected (0.00 sec)

But history is still there.

但历史仍然存在。

How do I clear or delete history for queries that i typed.

如何清除或删除我输入的查询的历史记录。

回答by mmdemirbas

Query cacheand query historyare different things.

查询缓存查询历史是不同的东西。

Query Cache

查询缓存

MySql stores executed queries with their results in a query cache, so it can quickly respond when the same query requested (cache hit). Run RESET QUERY CACHEor FLUSH TABLESto clear query cache.

MySql 将执行的查询及其结果存储在查询缓存中,因此当请求相同的查询(缓存命中)时,它可以快速响应。运行RESET QUERY CACHEFLUSH TABLES以清除查询缓存。

Command History File

命令历史文件

MySql stores commands executed from its own shell in a history file. It is located under your home directory (Unix): ~/.mysql_history. Remove this file to clear history up to now (from shell):

MySql 将在它自己的 shell 中执行的命令存储在一个历史文件中。它位于您的主目录 (Unix) 下:~/.mysql_history. 删除此文件以清除迄今为止的历史记录(从 shell)

rm -rf ~/.mysql_history

If you want to disable history completely, create the history file as a symlink to /dev/null(from shell):

如果要完全禁用历史记录,请将历史记录文件创建为/dev/null(来自 shell)的符号链接:

ln -s /dev/null $HOME/.mysql_history

回答by Uku Loskit

Mysql runs its own shell. You can delete this history by deleting the file that the history is read from, which is stored in ~/.mysql_history

Mysql 运行自己的 shell。您可以通过删除读取历史记录的文件来删除此历史记录,该文件存储在~/.mysql_history

回答by BuvinJ

If, in fact, we are answering how to clear the "history" (not the cache), and we're talking about a 'nix platform... there is another important history file to delete potentially. I.e. /root/.mysql_history.

事实上,如果我们正在回答如何清除“历史”(而不是缓存),并且我们正在谈论一个 'nix 平台......还有另一个重要的历史文件可能会被删除。即/root/.mysql_history

When accessing MariaDB (i.e. a MySQL fork if you were not aware), it's typical to launch it as sudo. In which which case your client input history is written to /root...instead of your home directory.

访问 MariaDB 时(如果您不知道,则为 MySQL 分支),通常以sudo. 在这种情况下,您的客户端输入历史将被写入/root...而不是您的主目录。

If you want to clear all recent input on BOTH the mysql client and the bash terminal for security purposes, try executing the following:

如果出于安全目的要清除 mysql 客户端和 bash 终端上的所有最近输入,请尝试执行以下操作:

rm -rf ~/.mysql_history
sudo rm -rf /root/.mysql_history
history -cw
clear

I've used that successfully on CentOS and Debian running MySQL or MariaDB.

我已经在运行 MySQL 或 MariaDB 的 CentOS 和 Debian 上成功使用了它。