Ubuntu MySQL/MariaDB Maintenance

This is just meant to be a simple list of cron jobs that I’ve used to maintain my Ubuntu MySQL/MariaDB database … nothing fancy. They go into sudo crontab -e:

9 * * * * mysql -u root -p[PUT YOUR ROOT DB PASSWORD HERE] -e "PURGE BINARY LOGS BEFORE (NOW() - INTERVAL 18 HOUR);"
8 * * * * mysqlcheck -Ao --auto-repair -u root -p[PUT YOUR ROOT DB PASSWORD HERE]

The first cronjob runs at 9:00 am every day and will remove any BINLOGs from /var/lib/mysql that are older than 18 hours. These logs can grow fast, but this should keep them tidy.

The second cronjob runs at 8:00 am every day and does an autorepair of all databases.

Remember to replace the entire [PUT YOUR ROOT DB PASSWORD HERE] line, even the square brackets. There should be no spaces between -p and your password. This is in root’s crontab so it should be safe from snoopers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.