How to Optimize your MySQL tables from the command line

All the MySQL tables have the be optimized once in a while. Ideally, once a week perhaps.

You can do that by either going to your phpMyAdmin or, if you're a badass command line hacker, running the following command:

mysqlcheck -o --user=root --password='YourPassword' -A
Code language: JavaScript (javascript)

Create a cron job

I'm using Ubuntu 18.04.

The best way to deal with this is by creating a cron job that will run automatically.

Edit your cron:

crontab -e

Add the following line (will run the command weekly):

@weekly mysqlcheck -o --user=your_user --password='your_password' -A &> /dev/null
Code language: JavaScript (javascript)

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

Leave a Reply

Add <code> Some Code </code> if you need to.