
04-25-2011, 08:05 AM
|
|
Aspiring Evangelist
|
|
Join Date: Mar 2011
Posts: 393
|
|
Cron Job to FLUSH QUERY CACHE
My query cache is set quite high but it gets fragmented quite fast. I'd like to routinely flush the cache every 2 hours.
I ran this command in shell logged in as root however, it just gave me the list of mysql options instead.
mysql -u username -ppassword databasename "FLUSH QUERY CACHE"
What am I doing wrong? I'd like to save this as a shell script and run it via cron.
|

04-25-2011, 08:37 AM
|
|
Web Hosting Master
|
|
Join Date: Apr 2007
Posts: 3,481
|
|
Cache is good and there to help so you should be flushing it.
If it using too much RAM simply change your MySQL configuration to reduce the amount of RAM allocated to cache.
That way MySQL will keep it's self in check, without cron's etc...
|

04-25-2011, 09:15 AM
|
|
Aspiring Evangelist
|
|
Join Date: Mar 2011
Posts: 393
|
|
Hey Tom
I think you misunderstood me. We are using query cache and want to continue doing so. Once the cache fills up though, it starts fragmenting. To avoid that, we'd like to flush it say every 6 hours via cron
|

04-25-2011, 07:42 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Mar 2011
Posts: 42
|
|
I think you would need to use -e:
mysql -u username -ppassword databasename -e "FLUSH QUERY CACHE"
|

04-25-2011, 08:14 PM
|
|
Web Hosting Master
|
|
Join Date: Apr 2008
Location: United States, MI
Posts: 555
|
|
Quote:
Originally Posted by zahirw
Hey Tom
I think you misunderstood me. We are using query cache and want to continue doing so. Once the cache fills up though, it starts fragmenting. To avoid that, we'd like to flush it say every 6 hours via cron
|
I do believe that bug is for older versions of MySQL, 5.5 does not have that problem. You're only going to degrade performance with constant flushing.
__________________
Steven Crothers
No BS cloud engineer and Red Hat architect.
|

04-26-2011, 03:15 AM
|
|
Aspiring Evangelist
|
|
Join Date: Mar 2011
Posts: 393
|
|
Quote:
Originally Posted by nafirici
I think you would need to use -e:
mysql -u username -ppassword databasename -e "FLUSH QUERY CACHE"
|
Doesn't work...
|

04-26-2011, 03:28 AM
|
|
--. --. .-- ....
|
|
Join Date: Oct 2010
Location: ON, Canada
Posts: 960
|
|
'FLUSH QUERY CACHE' doesn't actually remove any queries form the cache, it defragments it. However, 'RESET QUERY CACHE' will remove all query results from the query cache.
__________________
█ GG Web Hosting
█ Backup, Digital (SSL) Certificates, Domains, Hosting, Privacy Policy, Software
█ S/W: Peel Ads, Softaculous, WHMCS Addons (Abuse Mon., Affiliate Peel Ads, Client Stat., Ord. Prevention, Ord. Stat., Softaculous NOC, Sys. Cleanup)
█ Authorized Reseller Program
|

04-26-2011, 03:34 AM
|
|
Aspiring Evangelist
|
|
Join Date: Mar 2011
Posts: 393
|
|
Yes, how do I execute the flush query cache query in shell
|

04-26-2011, 03:47 AM
|
|
--. --. .-- ....
|
|
Join Date: Oct 2010
Location: ON, Canada
Posts: 960
|
|
Quote:
Originally Posted by zahirw
Yes, how do I execute the flush query cache query in shell
|
It should be something like this:
Code:
mysql -u {username} -p{password} -e "FLUSH QUERY CACHE"
__________________
█ GG Web Hosting
█ Backup, Digital (SSL) Certificates, Domains, Hosting, Privacy Policy, Software
█ S/W: Peel Ads, Softaculous, WHMCS Addons (Abuse Mon., Affiliate Peel Ads, Client Stat., Ord. Prevention, Ord. Stat., Softaculous NOC, Sys. Cleanup)
█ Authorized Reseller Program
|

04-26-2011, 03:54 AM
|
|
Aspiring Evangelist
|
|
Join Date: Mar 2011
Posts: 393
|
|
|

04-26-2011, 03:55 AM
|
|
--. --. .-- ....
|
|
Join Date: Oct 2010
Location: ON, Canada
Posts: 960
|
|
Quote:
Originally Posted by zahirw
Didn't work
|
What I gave you is the correct command line to run the query; unless you need to connect to specify a hostname that is. We run that on a few of our servers every several hours. Does the user that you're passing have the proper permissions to perform that? Do you receive an error?
__________________
█ GG Web Hosting
█ Backup, Digital (SSL) Certificates, Domains, Hosting, Privacy Policy, Software
█ S/W: Peel Ads, Softaculous, WHMCS Addons (Abuse Mon., Affiliate Peel Ads, Client Stat., Ord. Prevention, Ord. Stat., Softaculous NOC, Sys. Cleanup)
█ Authorized Reseller Program
Last edited by GGWH-James; 04-26-2011 at 04:02 AM.
|

04-26-2011, 12:26 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Mar 2011
Posts: 42
|
|
Quote:
Originally Posted by zahirw
Doesn't work...
|
I've also tested this and worked fine for me. Do you have the correct permissions? Is there some sort of an error that you're getting? I would also recommend using RESET QUERY CACHE because GGWH-James is correct, FLUSH QUERY CACHE doesn't remove any queries from the cache and RESET does.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|