Fix MariaDB missing tables on Manjaro/Arch linux

Here is how to fix the missing tables in MariaDB that you may encounter on a fresh install on Manjaro or Arch linux.

SNP 006 #931 Filed cmd

Installed MariaDB on Manjaro recently but it failed to start up after. Logs had the following errors in them.

shell
[ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
[ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.db' doesn't exist
[ERROR] Aborting

So to solve this you need to reinstall the system tables of MariaDB.

First you need to stop MariaDB if you have it running.

shell
systemctl stop mariadb

Then you need to delete all installed tables. In my case there were none, but you might need this step.

shell
sudo rm -R /var/lib/mysql/*

And after that you can reinstall the tables with this command.

shell
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Now MariaDB should start up without errors.

shell
systemctl start mariadb