27

I tried this at root prompt but didnt help.

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.

4 Answers 4

41

Query cache and query history are 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 CACHE or FLUSH TABLES to clear query cache.

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):

rm -rf ~/.mysql_history

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

ln -s /dev/null $HOME/.mysql_history
Sign up to request clarification or add additional context in comments.

1 Comment

rm -rf seems unnecessary. It’s just one file.
7

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

2 Comments

Is this about clearing the history of mysql or the query-cache? dev.mysql.com/doc/refman/5.1/en/query-cache.html
The question is ambiguous
3

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.

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.

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

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.

Comments

0

I would be cautios with rm with recursive option, I've been always warned to think twice before using -r

Why just don't use

rm ~/.mysql_history

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.