Plesk

MySQL/MariaDB fails to start on a Plesk for Linux server: Can’t open and lock privilege tables

Applicable to:

  • Plesk for Linux

Symptoms

Cause

Tables in the mysql database are missing or corrupted.

Resolution

  1. Connect to the Plesk server via SSH.

  2. Stop the MariaDB/MySQL service:

    # systemctl stop mariadb

    # systemctl stop mysql

  3. Add skip-grant-tables to the my.cnf file:

    3.1. Open the my.cnf file in a text editor. In this example, we are using the vi editor:

    • on CentOS/RHEL-based distributions

      # vi /etc/my.cnf

    • on Debian/Ubuntu-based distributions

      # vi /etc/mysql/my.cnf

    3.2. Add the skip-grant-tables directive under the [mysqld] section:

    [mysqld]
    skip-grant-tables

    3.3. Save the changes and close the file.

  4. Start the MariaDB/MySQL service:

    # systemctl start mariadb

    # systemctl start mysql

  5. Create a database dump of the mysql database:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -uadmin --skip-extended-insert mysql > /root/mysql_dump.`date +%F.%s`.sql

  6. Move the mysql directory to /root:

    # mv /var/lib/mysql/mysql/ /root

  7. List all available Plesk daily dumps (the default dumps folder is /var/lib/psa/dumps):

    # ls -lat `cat /etc/psa/psa.conf | grep DUMP_D | grep -v "#" | awk '{print $2}'`/mysql.daily.dump*

    -rw------- 1 root root 236253 Dec 3 01:51 /var/lib/psa/dumps/mysql.daily.dump.0.gz
    -rw------- 1 root root 229653 Jul 2 01:48 /var/lib/psa/dumps/mysql.daily.dump.1.gz
    -rw------- 1 root root 222485 Apr 1 01:56 /var/lib/psa/dumps/mysql.daily.dump.2.gz

  8. Restore the mysql database from the most recent Plesk daily dump:

    # zcat /var/lib/psa/dumps/mysql.daily.dump.0.gz | sed -n '/-- Current Database: `mysql`/,/-- Current Database:*/p' | mysql -uadmin mysql

  9. Remove the skip-grant-tables directive which was added on step 3.

  10. Start the MariaDB/MySQL service:

    # systemctl restart mariadb

    # systemctl restart mysql