The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

FLUSH QUERY CACHE once per day for database

Discussion in 'Database Discussions' started by ASTRAPI, Jul 13, 2014.

  1. ASTRAPI

    ASTRAPI Well-Known Member

    Joined:
    Jul 8, 2008
    Messages:
    321
    Likes Received:
    0
    Trophy Points:
    16
    Hi

    How can i run at 5 AM the FLUSH QUERY CACHE for my sql?

    What is the correct syntax and do i have to use a cronjob or is there any other way?

    Thanks
     
  2. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Just add it to the root crontab (/var/spool/cron/root)

    Code:
    0 5 * * *  mysql -e 'FLUSH QUERY CACHE'
    
    Or put the above command in a shell script and call the shell script via cron, which is typically how I would do it.

    Maybe also check that this is the query you actually want to run:

    MySQL :: MySQL 5.5 Reference Manual :: 13.7.6.3 FLUSH Syntax
     
  3. ASTRAPI

    ASTRAPI Well-Known Member

    Joined:
    Jul 8, 2008
    Messages:
    321
    Likes Received:
    0
    Trophy Points:
    16
    I got that recommendation from mysqltuner :)

    So:

    crontab -e

    Edit:
    0 5 * * * mysql -e 'FLUSH QUERY CACHE'

    Is this syntax ok to flush the query cache?

    And that's it? No sql info or anything else for login ?

    The cache is 256mb is it ok or too big to run this command on it?

    Thanks
     
    #3 ASTRAPI, Jul 13, 2014
    Last edited: Jul 13, 2014
  4. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    the mysql root credentials are defined in /root/.my.cnf which is why when you type 'mysql' via CLI when logged in as root, you don't have to provide credentials. It should work this way via cron as well unless something is weird with your environment.

    I don't see an issue running this command periodically.
     
  5. ASTRAPI

    ASTRAPI Well-Known Member

    Joined:
    Jul 8, 2008
    Messages:
    321
    Likes Received:
    0
    Trophy Points:
    16
    Ok thanks :)

    Is this global and can run it as you recommend it or i must select on which database it must run?
     
    #5 ASTRAPI, Jul 13, 2014
    Last edited: Jul 13, 2014
  6. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    It's a global command, just run it as written.
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,675
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page