Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know if there's a way to permanently set the size of my query cache and to make sure it's always enabled. Right now, I'm just using the set global query_cache_size command to set the size, but when the database is restarted it goes away.

share|improve this question
up vote 2 down vote accepted

You can set this parameter in /etc/my.cnf on Red Hat or /etc/mysql/my.cnf on Debian (other systems have the my.cnf file in various locations):

# vi /etc/my.cnf

Append config directives as follows:

query_cache_size = 268435456
query_cache_type = 1
query_cache_limit = 1048576

Change the values as appropriate to your system!

share|improve this answer

You have to edit MySQL configuration file and change these parameters accourdingly

query_cache_size - 1-2 MB

query_cache_limit - 1-2 MB

query_prealloc_size - Should be more than default if you have complex queries.

share|improve this answer

What worked for me was adding the directives Max Vernon provided a few lines after the other directives under [mysqld] in my.cnf (or my.ini if on XAMPP) as opposed to adding the lines to the end of the configuration file or after [mysqldump] or [mysql].

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.