Check and Repair All MySQL Databases on Ubuntu

The following command can be used to check and repair all MySQL databases on a Ubuntu or Debian Linux System. I've tested the commands on Ubuntu 20.04 and Debian 10.

Repair MySQL databases on Ubuntu Linux

sudo mysqlcheck --defaults-file=/etc/mysql/debian.cnf --auto-repair --optimize --all-databases

MySQL Repair and Optimize

MySQL database repair on Debian

mysqlcheck --defaults-file=/etc/mysql/debian.cnf --auto-repair --optimize --all-databases

The benefit of the above command is that it uses the debian-sys-maint login to MySQL which is available on every Debian and Ubuntu System, so you don't have to provide the MySQL root login details.

1 thought on “Check and Repair All MySQL Databases on Ubuntu”

  1. Hi there,

    Thank you for providing a possible solution on how to repair the Mysql.
    However when trying to use the above command in terminal, i get the following message.

    mysqlcheck: Got error: 2002: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) when trying to connect

    Could you please help me out a bit? 🙂
    I have tried out various websites about this topic, uninstalled and reinstalled mysql again without any luck.

    I’m using the Linux mint 17.3 (Rosa) OS and I’m a so called Newbie in the Linux world.
    Maybe the solution is to delete the OS entirely and reinstall it?

    Thank you in advance
    Regards Laryea

    Reply

Leave a Comment

*