# How do I fix an "Access Denied" error when connecting to MySQL? An `Access Denied` error occurs when: - You input the incorrect username, password, or database name in the connection string. - The user does not have the proper privileges to connect to the database. Furthermore, access denied errors can look different depending on the root cause. For instance, this error means that you’re using the wrong password: ``` ERROR 1045 (28000): Access denied for user 'sammy'@'203.0.113.0' (using password: YES) ``` This access denied error means the connection string didn’t contain the `-p` flag but a password is required: ``` ERROR 1045 (28000): Access denied for user 'sammy'@'203.0.113.0'' (using password: NO) ``` This access denied error means the user does not have privileges on the database specified in the connection string: ``` ERROR 1044 (42000): Access denied for user 'sammy'@'%' to database 'defaultdb' ``` If you are getting this error: - Ensure you have the correct username, password, and database name in your connection string. - Ensure the user has the correct privileges on the database you want to connect to. - To change user privileges, see [Privileges Provided by MySQL](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html). ## Related Topics [How do I fix the mysqldump "Couldn't execute FLUSH TABLES Access denied" error?](https://docs.digitalocean.com/support/how-do-i-fix-the-mysqldump-couldnt-execute-flush-tables-access-denied-error/index.html.md): Update backup user permissions, remove the –single-transaction flag, or downgrade mysqldump. [Why does MySQL shut down when importing data with the source command?](https://docs.digitalocean.com/support/why-does-mysql-shut-down-when-importing-data-with-the-source-command/index.html.md): Use MySQL’s import command instead of source for handling large data imports. [How do I fix the "1227" error?](https://docs.digitalocean.com/support/how-do-i-fix-the-1227-error/index.html.md): Remove or replace the DEFINER in the dump file.