Articles in this section

Unable to access Plesk: Permission denied /var/lib/mysql/mysql.sock

Plesk for Linux kb: technical

Applicable to:

  • Plesk for Linux

Symptoms

  • Plesk interface does not load with one of the following error messages in a web browser:

    PLESK_INFO: ERROR: PleskDBException: Unable to connect to database: mysql_connect(): Permission denied /var/lib/mysql/mysql.sock (Error code: 2002). 


    PLESK_INFO: ERROR: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Permission denied' in /usr/local/psa/admin/externals/Zend/Db/Adapter/Pdo/Abstract.php

  • MariaDB service fails to start. One of the following error messages is logged in /var/log/mariadb/mariadb.log:

    CONFIG_TEXT: systemd[1]: Starting MariaDB database server...
    mariadb-prepare-db-dir[4030]: chmod: changing permissions of Б─≤/var/lib/mysqlБ─≥: Operation not permitted
    mariadb-prepare-db-dir[4030]: Initializing MySQL database
    mariadb-prepare-db-dir[4030]: chown: changing ownership of Б─≤/var/lib/mysqlБ─≥: Operation not permitted
    mariadb-prepare-db-dir[4030]: Cannot change ownership of the database directories to the 'mysql'
    mariadb-prepare-db-dir[4030]: user. Check that you have the necessary permissions and try again.
    mariadb-prepare-db-dir[4030]: Initialization of MySQL database failed


    CONFIG_TEXT: [ERROR] InnoDB: Operating system error number 13 in a file operation.
    [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
    [ERROR] InnoDB: Cannot open datafile for read-only: './mysql/gtid_slave_pos.ibd' OS error: 81

  • When accessing a database in MariaDB using the mysql utility, the operation fails with:

    CONFIG_TEXT: ERROR 1018 (HY000): Can't read dir of './db-name/' (errno: 13)

Cause

MySQL data directory /var/lib/mysql/ and directories/files inside have invalid permissions.

Resolution

  1. Connect to your Plesk server via SSH.
  2. Set proper permissions on the MySQL data directory and directories/files inside:

    # chown -R mysql:mysql /var/lib/mysql

    # find /var/lib/mysql/* -type d -exec chmod 0700 {} \;

    # find /var/lib/mysql/* -type f -exec chmod 0660 {} \;

    • on RHEL/AlmaLinux-based distributions:

      # chmod 755 /var/lib/mysql

    • on Debian/Ubuntu-based distributions:

      # chmod 700 /var/lib/mysql

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.