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
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
build using a simple bash script