Repair or optimize MySQL database on a shell
To fight fragmented databases, it is always a good idea to re-optimize your MySQL database especially if you have a lot of varying characters (VARCHAR). The basic way is via a SQL query. bash> mysql
mysql> OPTIMIZE TABLE foo;
But easier is to do it on the shell. Here is the solution:
mysqlcheck -op database_name
The ‘o’ refers to optimize. And the ‘p’ is the option for password requirement. You’ll be prompted for the password. If you’re logged in as user ‘john’ in your SSH, the MySQL username will be ‘john’. If that’s not what you want, use option ‘u’