Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6222831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:23:03+00:00 2026-05-24T08:23:03+00:00

I am trying to set up a cron job that everyday optmizes the mysql

  • 0

I am trying to set up a cron job that everyday optmizes the mysql database using debian on a virtual machine.

First I have tried using the mysqlcheck like this:

0 * * * * mysqlcheck -Aao –auto-repair -u root -p[password] > /dev/null

I got this error: mysqlcheck: Got error: 1045: Access denied for user ‘root’@’localhost’ (using password: YES) when trying to connect

after googling this error I found Dave Stoddard Comment who was experiencing the same problem:

0 * * * * /usr/local/bin/mysqlcheck --defaults-file=/root/.my.cnf --all-databases --auto-repair 2>&1 | grep -v "OK" | mail -s "Database Problem" root

or 0 * * * * /usr/local/bin/mysqlcheck --defaults-file=/root/.my.cnf --all-databases --auto-repair 2>&1 | grep -v "OK" | mail -s "Database Problem" root

Error from above:

/bin/sh: root: command not found
/bin/sh: /usr/local/bin/mysqlcheck: No such file or directory
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:23:04+00:00Added an answer on May 24, 2026 at 8:23 am

    seriously, you might over-doing,
    your approach will causing some unnecessary table lock,
    which mean it easily freezing your application that required database access

    the optimization is required only when the table is too fragmented
    meaning contains free-space,
    an optimization able to impact the index key and data file

    what is free-space?

    this query will return list of table need to be optimized

    select TABLE_SCHEMA, TABLE_NAME
    from information_schema.tables 
    where data_free>0;
    

    build using a simple bash script

    chk="select concat(TABLE_SCHEMA,'.', TABLE_NAME) from information_schema.tables where data_free>0;"
    
    for tbl in $(mysql -u root -pxxx -N <<< $chk)
    do
      mysql -u xxx -pxxx -N <<< "optimize table $tbl"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying top set cron job using cpanel interface. But am getting response
I'm trying to set up a Cron job for deleting MySQL records where a
I am trying to learn how to do my first cron job using CodeIgniter.
I'm trying to set a simple cron script to do some database updating, and
I am trying to set up a cron job to, every 15 min, run
I'm trying to set up a cron job as a sort of watchdog for
I'm trying to set a cron job, namely echoing hi every minute. When I
I am trying to set up cron job to run a rake task daily.
I am trying to setup a cron job in my Grails web application using
I am trying to setup an end-of-day automated email using a CRON job. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.