MySQL on Arch Linux – Fatal Error: Can’t Open and Lock Privilege Tables

installationlinuxmariadb-10.1MySQL

MySQL fails to start on arch Linux.

mysqld[3440]: [Note] /usr/bin/mysqld (mysqld 10.1.22-MariaDB) starting as process 3440 ...
mysqld[3440]: [Note] InnoDB: Using mutexes to ref count buffer pool pages
mysqld[3440]: [Note] InnoDB: The InnoDB memory heap is disabled
mysqld[3440]: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysqld[3440]: [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysqld[3440]: [Note] InnoDB: Compressed tables use zlib 1.2.11
mysqld[3440]: [Note] InnoDB: Using Linux native AIO
mysqld[3440]: [Note] InnoDB: Using SSE crc32 instructions
mysqld[3440]: [Note] InnoDB: Initializing buffer pool, size = 128.0M
mysqld[3440]: [Note] InnoDB: Completed initialization of buffer pool
mysqld[3440]: [Note] InnoDB: Highest supported file format is Barracuda.
mysqld[3440]: [Note] InnoDB: The log sequence numbers 0 and 0 in ibdata files do not match the log sequence number 1600719 in the ib_logfiles!
mysqld[3440]: [Note] InnoDB: Restoring possible half-written data pages from the doublewrite buffer...
mysqld[3440]: [Note] InnoDB: 128 rollback segment(s) are active.
mysqld[3440]: [Note] InnoDB: Waiting for purge to start
mysqld[3440]: [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.35-80.0 started; log sequence number 1600719
mysqld[3440]: [Note] InnoDB: Dumping buffer pool(s) not yet started
mysqld[3440]: [Note] Plugin 'FEEDBACK' is disabled.
mysqld[3440]: [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
mysqld[3440]: [Note] Recovering after a crash using mysql-bin
mysqld[3440]: [Note] Starting crash recovery...
mysqld[3440]: [Note] Crash recovery finished.
mysqld[3440]: [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
mysqld[3440]: [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
mysqld[3440]: [Note] Server socket created on IP: '::'.
mysqld[3440]: [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

I have reinstalled the packages but I still end up with the same problems.

Best Answer

The arch wiki helped me solve this pretty quickly.

Install mariadb, afterwards run the following command before starting the mariadb.service:

mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
mysql_secure_installation

Arch does not hold your hand, with this type of thing. I guess if you install mysql / mariadb from source this is expected.

This answer also helped me to figure out what I was looking for. https://stackoverflow.com/a/22179751/619760