Client Error Codes > 1045
Categories
Client Error Codes, Error Codes
Definition
Error 1045 is returned when a user is denied permission to connect to the MySQL server.
Sample
[localhost]$ mysql
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)
Resolution
- If the message ends with ‘(using password: NO)’, no password was specified while connecting. Add -p to the call to the mysql client:
mysql -p
- If the username in the error message is not the one you need to use to connect to MySQL, specify the desired username with the -u flag:
mysql -u mike -p
When -u is omitted, the mysql client uses the logged-in username on the OS (root in the example above).
- Authentication is based on a combination of user and the host being connected from (’root’ connecting from ‘localhost’ in the example above). Check that the connecting host listed is the one you have permission to connect from.
- If you are connecting from the correct host using the correct username, it means that you are providing the wrong password or the user does not exist. See the Adding Users link in the following section.
Further Reference
Causes of Access Denied Errors (MySQL Reference Manual)
Connecting to the MySQL Server (MySQL Reference Manual)
Adding New User Accounts to MySQL (MySQL Reference Manual)