Error
Error Code:
1698
MySQL Error 1698: Access Denied for User
Description
This error indicates that the MySQL server rejected a connection attempt from a specified user and host. It commonly occurs when the provided credentials (username, password, or host) do not match any authorized user accounts, or when the client is trying to connect to a user that does not exist or has incorrect authentication settings.
Error Message
Access denied for user '%s'@'%s'
Known Causes
4 known causesIncorrect Credentials
The username or password provided during the connection attempt does not match the credentials stored for the user in MySQL.
User Not Found
The MySQL server does not have a user account defined with the specified username.
Restricted Host Access
The user account is configured to allow connections only from specific hostnames or IP addresses, and the current connection source is not permitted.
Authentication Plugin Mismatch
The client's connection software or library is unable to authenticate with the method configured for the user on the MySQL server.
Solutions
4 solutions available1. Verify User Credentials and Host easy
Ensure the username, password, and hostname used to connect are correct and match an existing user entry in MySQL.
1
Double-check the username and password you are using to connect to the MySQL server. Typos are a common cause of 'Access Denied' errors.
2
Identify the hostname or IP address from which you are attempting to connect. The error message `'%s'@'%s'` will show the hostname MySQL is seeing. Ensure this matches the host specified in your MySQL user account.
3
Connect to your MySQL server using a known administrative account (e.g., 'root') and query the `mysql.user` table to verify the user exists and their host specification.
SELECT user, host FROM mysql.user WHERE user = 'your_username';
-- Replace 'your_username' with the username causing the error.
2. Update Authentication Plugin for Older Clients medium
If you're using an older MySQL client or connector that doesn't support the default `caching_sha2_password` plugin, you can revert to `mysql_native_password` for compatibility.
1
Connect to your MySQL server as an administrator (e.g., root).
2
Alter the user to use the `mysql_native_password` authentication plugin. Replace 'your_username' and 'your_host' with the actual username and host from the error message.
ALTER USER 'your_username'@'your_host' IDENTIFIED WITH mysql_native_password BY 'your_password';
-- Replace 'your_username', 'your_host', and 'your_password' accordingly.
3
Flush privileges to ensure the changes take effect immediately.
FLUSH PRIVILEGES;
3. Grant Appropriate Privileges to the User medium
The user might exist but lack the necessary permissions to perform the requested action or connect from the specified host.
1
Connect to your MySQL server as an administrator (e.g., root).
2
Grant the necessary privileges to the user. This example grants all privileges on all databases and tables from a specific host. Adjust privileges and host as needed.
GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'your_host' WITH GRANT OPTION;
-- Replace 'your_username' and 'your_host'. For specific databases/tables, use 'database_name.*' or 'database_name.table_name'.
3
Flush privileges to apply the changes.
FLUSH PRIVILEGES;
4. Create or Recreate the User with Correct Authentication medium
If the user is misconfigured or doesn't exist for the intended host and authentication method, create or recreate it properly.
1
Connect to your MySQL server as an administrator (e.g., root).
2
If the user already exists, you might want to drop it first. Be cautious with this step if the user has important data or configurations.
DROP USER 'your_username'@'your_host';
-- Replace 'your_username' and 'your_host'.
3
Create the user with the desired authentication plugin. `caching_sha2_password` is the default for newer MySQL versions. Use `mysql_native_password` if compatibility is an issue.
CREATE USER 'your_username'@'your_host' IDENTIFIED WITH caching_sha2_password BY 'your_password';
-- Or for older clients:
-- CREATE USER 'your_username'@'your_host' IDENTIFIED WITH mysql_native_password BY 'your_password';
-- Replace 'your_username', 'your_host', and 'your_password'.
4
Grant the necessary privileges to the newly created user.
GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'your_host';
-- Adjust privileges and scope as needed.
5
Flush privileges.
FLUSH PRIVILEGES;