Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear query cache in mysql?

Tags:

sql

mysql

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.

like image 367
AMD Avatar asked Dec 30 '10 09:12

AMD


People also ask

How do I clear the query cache in MySQL?

With the FLUSH QUERY CACHE command you can defragment the query cache to better utilise its memory. This command will not remove any queries from the cache. FLUSH TABLES also flushes the query cache. The RESET QUERY CACHE command removes all query results from the query cache.

What is reset query cache?

The RESET QUERY CACHE statement removes all query results from the query cache. The FLUSH TABLES statement also does this.

What is query cache in MySQL?

The MySQL query cache is a query results cache. It compares incoming queries that start with SEL to a hash table, and if there is a match returns the results from the previous execution of the query. There are some restrictions: The query must match byte-for-byte (the query cache avoids parsing)

How do I view MySQL cache?

To make sure MySQL Query Cache is enabled use: mysql> SHOW VARIABLES LIKE 'have_query_cache'; To monitor query cache stats use: mysql> SHOW STATUS LIKE 'Qcache%';


2 Answers

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 
like image 58
mmdemirbas Avatar answered Sep 23 '22 22:09

mmdemirbas


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

like image 31
Uku Loskit Avatar answered Sep 23 '22 22:09

Uku Loskit