Automatically optimize tables through Cron

Discussion in 'MySQL' started by ashras99, Feb 4, 2011.

  1. #1
    Anyone can tell me how to optimize the mysql tables weekly automatically? I think this can be done through cron but how...?
     
    ashras99, Feb 4, 2011 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    What do you mean by optimize the mysql tables?
     
    mwasif, Feb 4, 2011 IP
  3. ashras99

    ashras99 Active Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    In PHPmyadmin hopefully you have seen the option of Optimize, Repair the database tables?
     
    ashras99, Feb 4, 2011 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    Ok, yes that can be done through a PHP/Perl script which have MySQL commands like
    OPTIMIZE TABLE table_name;
    Code (markup):
    and schedule it to run according to your need
     
    mwasif, Feb 4, 2011 IP
  5. ashras99

    ashras99 Active Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    during this time, mysql server goes down or unaccessible?
     
    ashras99, Feb 4, 2011 IP
  6. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #6
    Table will be LOCKed state when you run OPTIMIZE TABLE command on the table. OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length row (see manual).

    BTW, why you want to use OPTIMIZE TABLE?
     
    mwasif, Feb 4, 2011 IP
  7. ashras99

    ashras99 Active Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #7
    Database optimizations many documents and scripts you must need to defragment the database weekly.
     
    ashras99, Feb 4, 2011 IP
  8. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #8
    Did you check the MySQL manual I told in my last post? It is only required when you are deleting a large portion of data from the table. Are you doing so?
     
    mwasif, Feb 4, 2011 IP
  9. ashras99

    ashras99 Active Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #9
    No, we are not deleting.
     
    ashras99, Feb 4, 2011 IP
  10. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #10
    Then there is no need you to do this.
     
    mwasif, Feb 4, 2011 IP