Jump to content

How can I Optimize MySQL DB via Cron


Coastie

Recommended Posts

I\'d like to set up a script to optimize a MySQL DB once a week from cron.

 

I know how to config the crontab, but I am not sure what the syntax of the script should be. I have one to dump my DB and also to move it to a backup server.

 

To dump, I use something like:

 

mysqldump -u User -pPassword --opt DB_Name| gzip > /path/to/save/backup/BACKUPSQL.$(date +%a).gz

 

That creates the BACKUPSQL file with the current day of the week.

 

Now I can\'t use mysqldump to optimize the DB, so would it be something like this?

 

mysql -u User -pPassword OPTIMIZE  TABLE  `c_ban_users` ,  `c_messages` ,  `c_reg_users` ,  `c_users`

 

I just used phpmychat as an example DB.

 

Where do I tell it which DB to optimize?

 

Also can I use a wildcard such as * to mean all tables, or do I need to list them?

 

Thank You,

Link to comment
Share on other sites

setup an sql file that will have the statement, we\'ll call it optimize.sql:

optimize table tbl1, tbl2, tbl3

 

now in the cron you want something like ( i think i have the right syntax ):

 

/path/to/mysql/bin/mysql -uuser -ppassword databasename < optimize.sql
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.