Error
Error Code:
1045
MariaDB Error 1045: Access Denied for User
Description
This error indicates that the MariaDB server has rejected a connection attempt due to an authentication failure. It typically occurs when the provided credentials or client host do not match the server's security configuration, preventing successful database access.
Error Message
Access denied for user '%s'@'%s' (using password: %s)
Known Causes
3 known causesInvalid Credentials
The username or password supplied in the connection string is incorrect or does not match any existing user's credentials on the MariaDB server.
Unauthorized Host
The MariaDB user account is configured to permit connections only from specific hosts or IP addresses, and the client's originating host does not match the allowed list.
User Account Missing
The specified database user account attempting to connect does not exist on the MariaDB server, leading to an immediate authentication failure.
Solutions
4 solutions available1. Verify Username and Password easy
Check credentials are correct
1
Test connection with mysql client to verify credentials
mysql -u username -p -h hostname
2
Check if user exists in MariaDB
SELECT User, Host FROM mysql.user WHERE User = 'username';
3
Reset password if forgotten
ALTER USER 'username'@'host' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
2. Fix Host Access Permissions medium
Grant access from the correct host/IP
1
Check which hosts are allowed for this user
SELECT User, Host FROM mysql.user WHERE User = 'username';
2
Create user with correct host if missing
CREATE USER 'username'@'192.168.1.%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'192.168.1.%';
FLUSH PRIVILEGES;
3
Or update existing user to allow from any host
UPDATE mysql.user SET Host='%' WHERE User='username' AND Host='localhost';
FLUSH PRIVILEGES;
3. Create Missing User Account easy
Create the user if it doesn't exist
1
Connect as root user
mysql -u root -p
2
Create the user with password
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
3
Grant necessary privileges
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
4
Verify user was created
SHOW GRANTS FOR 'newuser'@'localhost';
4. Fix Authentication Plugin Issues medium
Handle auth_socket or caching_sha2_password issues
1
Check current authentication plugin
SELECT User, Host, plugin FROM mysql.user WHERE User = 'username';
2
Change to mysql_native_password if needed
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
3
For root user using auth_socket (common on Ubuntu)
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_root_password';
FLUSH PRIVILEGES;