Repairing MariaDB

After a hardware failure, a power outage, or even after an upgrade, it is a good idea to check the tables in our MariaDB databases to make sure they are all right. MariaDB includes several utilities for doing this.

Checking and optimizing tables with mysqlcheck

The mysqlcheck program can check, analyze, optimize, and repair the MariaDB database tables. Basic syntax for the command is as follows:

mysqlcheck [options] [-u username] [-p] database_name [table_name]

Here is an example of running the command to check our test database, and its output:

daniel@gandalf:~$ mysqlcheck -u root -p test
Enter password:
test.employees                                     OK

We can specify multiple databases using the --databases option as follows:

mysqlcheck -u root -p --databases ...

Get Getting Started with MariaDB - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.