If you encounter the “ERROR 1045 (28000): Access denied for user ‘root’@’localhost’” error while accessing MySQL on a Plesk Linux server, follow these steps to regain access.

Step 1: Retrieve the MySQL Admin Password

Run the following command to find the admin password stored in Plesk:

cat /etc/psa/.psa.shadow

Example Output:

FfRBehWy

Step 2: Log in to MySQL Using Admin Credentials

Use the retrieved password to log in as the admin user:

mysql -u admin -pFfRBehWy

Once logged in, you will see:

Welcome to the MySQL monitor.
Your MySQL connection id is 2555
Type ‘help;’ or ‘\h’ for help.

Step 3: Enable Passwordless MySQL Login (Optional)

To avoid entering the password every time, create a configuration file:

vi /root/.my.cnf

Add the following content:

[mysql]
user = admin
password = FfRBehWy

[mysqldump]
user = admin
password = FfRBehWy

Save and exit the file. Now, you can run mysql and mysqldump commands without entering the password.

By admin