DirectAdmin Error 1045 (28000): Access Denied for User ‘root’@’localhost’ – Fixing MySQL Login Issues
Problem
While trying to access MySQL from the command line on a DirectAdmin server, you may encounter the following error:
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
This typically occurs when the MySQL root password stored in DirectAdmin differs from the password you are manually using, or when MySQL authentication has been modified.
Cause
DirectAdmin maintains its own MySQL credentials in the following configuration file:
/usr/local/directadmin/conf/mysql.conf
If the credentials stored in this file are different from what you are attempting to use, direct login as root may fail.
Solution
Instead of manually entering the MySQL root username and password, retrieve the credentials directly from DirectAdmin’s configuration file.
Run the following command:
mysql --user=`grep "^user=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2` \
--password=`grep "^passwd=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2`
This command:
- Reads the MySQL username from
mysql.conf - Reads the MySQL password from
mysql.conf - Passes both credentials directly to the MySQL client
After executing the command, you should be logged into MySQL successfully.
Verify Stored Credentials
To check what DirectAdmin has stored, run:
cat /usr/local/directadmin/conf/mysql.conf
Example output:
user=da_admin
passwd=your_mysql_password
host=localhost
You can then manually test the login:
mysql -u da_admin -p
Alternative Method
If you only need to view the credentials:
grep "^user=" /usr/local/directadmin/conf/mysql.conf
grep "^passwd=" /usr/local/directadmin/conf/mysql.conf
Security Note
The password stored in mysql.conf is sensitive information. Avoid sharing the file contents publicly and restrict file permissions appropriately.
Conclusion
When MySQL returns:
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
on a DirectAdmin server, the quickest fix is often to use the MySQL credentials stored in DirectAdmin’s configuration file rather than attempting to authenticate with the system’s root credentials.
Using the command below will automatically log you in with the correct credentials configured by DirectAdmin:
mysql --user=`grep "^user=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2` \
--password=`grep "^passwd=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2`
This method is safe, fast, and works on most DirectAdmin installations.



