When your MySQL / MariaDB service crashes, the following message could give you a headache: Table ./mysql/proc is marked as crashed and should be repaired. Then this message pops up, either your server itself or the MySQL / MariaDB database instance crashed. This article is describing how you can fix this issue.

Advertisements

Ensure MySQL / MariaDB is running

The actual fix for this problem is rather easy. Although this error pops up, your MySQL or MariaDB server instance should run like normal. To check your MySQL Daemon, simply enter the following command:

user@server:~$ sudo systemctl status mysql

If you are running MariaDB, you have to use the following command instead:

user@server:~$ sudo systemctl status mariadb

An output like this should appear where you can see if your MySQL / MariaDB instance is running:

user@server:~$ sudo systemctl status mysql
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql)
Active: active (running) since Sun 2018-06-03 09:37:16 CEST; 2 weeks 1 days ago
CGroup: /system.slice/mysql.service
├─ 933 /bin/sh /usr/bin/mysqld_safe
└─1414 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql ...

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

If the Daemon is not running, the line Active: active (running) should state something like Active: inactive (dead) instead and therefore you have to start the database:

user@server:~$ sudo systemctl start mysql

Or, if you use MariaDB:

user@server:~$ sudo systemctl start mariad

The fix

When you’re sure that MySQL / MariaDB is running, you can issue the following command to solve the error:

user@server:~$ mysqlcheck --auto-repair -A -u root -p

The command will ask you for your MySQL / MariaDB root password. The now started process can take a long time. It checks every single table in your database on corruption. If there is a corruption found, it will be fixed automatically. After the process is finished, you should restart your MySQL Daemon:

user@server:~$ systemctl restart mysql

Or for MariaDB:

user@server:~$ systemctl restart mariadb

From now on, everything should work as normal again.

Don’t forget to do backups

While this is an error which can be fixed easily, this one more time approves, that creating regular backups is the key for a working environment. With issues that aren’t or only hard to fix, a backup can safe you not just money but also a lot of nerves, too. You should also monitoring your services and programs that are running on your servers if you don’t do this already. You could check out monit is a easy to use monitoring solution.

Further links

Advertisements