keepcalculator

06 Numbers and Powers

Fix MySQL Workbench Access Denied Errors

Card No. 06·45639 · Updated · Standard formula, shown below

MySQL Workbench’s “Access denied for user” error stops you from connecting to your database, usually because of wrong credentials, host mismatches, or missing privileges. This guide walks through the most common causes and provides step-by-step fixes, from resetting your password to adjusting user permissions.

What You’ll Need

  • Access to the MySQL server (either locally or via SSH).
  • Administrative privileges on the server (e.g., root access) to run certain commands.
  • MySQL client or command-line tool installed (mysql or mysqlsh).
  • MySQL Workbench installed (any recent version).

Step-by-Step

  1. Identify the exact error message. In Workbench, the error appears in a dialog box. Note the full text—it often includes the username and host, like Access denied for user 'root'@'localhost'. This tells you which user and host are being rejected.
  2. Check your username and password. In the connection setup (Home window → Manage Connections), verify the username and password fields. If you’re unsure about the password, try connecting via the command line: mysql -u username -p and enter the password. If that works, the credentials are correct; if not, proceed to reset the password.
  3. Reset the root password (if forgotten).
    1. Stop the MySQL service. On Linux: sudo systemctl stop mysql (or mysqld). On Windows: use Services (services.msc) to stop MySQL.
    2. Start MySQL in safe mode, skipping grant tables: sudo mysqld_safe --skip-grant-tables & (Linux) or add --skip-grant-tables to the MySQL configuration file (my.ini) on Windows.
    3. Connect without a password: mysql -u root
    4. Flush privileges and set a new password: FLUSH PRIVILEGES; then ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword'; (replace with your own).
    5. Exit and restart MySQL normally. Remove the --skip-grant-tables option if you added it to the config.
  4. Verify the host part of the user. MySQL users are defined as ‘user’@’host’. If your Workbench connects from ‘localhost’ but the user is only allowed from ‘192.168.1.%’, you’ll get an error. Check the user table: SELECT user, host FROM mysql.user; If the host doesn’t match, create a new user or update the host.
  5. Grant the necessary privileges. Even with correct credentials, if the user lacks privileges for the database, you may see an “Access denied” message. Grant privileges with: GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'host'; then FLUSH PRIVILEGES;.
  6. Check the connection method in Workbench. For remote connections, ensure the “Connection Method” is set to “Standard TCP/IP over SSH” if you’re using an SSH tunnel. Misconfigured SSH or wrong port (default 3306) can cause errors. Try connecting with a simple TCP/IP method if the server allows it.
  7. Test with the command-line client. If Workbench fails but the command line works, the issue is likely in Workbench’s saved credentials. Delete the connection and recreate it, re-entering the password.

Common Mistakes

  • Using the wrong case for username or database name—MySQL is case-sensitive on Linux.
  • Forgetting that the host part matters: ‘root’@’localhost’ is different from ‘root’@’%’.
  • Leaving the password field empty when a password is set, or vice versa.
  • Not running FLUSH PRIVILEGES after changing grant tables.
  • Using an outdated MySQL client that doesn’t support the server’s authentication plugin (e.g., caching_sha2_password).

Tips

  • Use a strong password and store it in a password manager.
  • When creating a user for remote access, use a specific IP range instead of ‘%’ for security.
  • Keep MySQL and Workbench updated to avoid compatibility issues.
  • If you’re using a managed cloud database (like AWS RDS), the root user is often restricted—create a new user with appropriate privileges.

Troubleshooting

If the steps above don’t resolve the issue:

  • Check the MySQL error log. It often contains detailed authentication failures. On Linux, look at /var/log/mysql/error.log. On Windows, check the MySQL data directory.
  • Verify that the MySQL server is actually running. Try sudo systemctl status mysql or check the service in Task Manager.
  • Test the connection from the command line on the same machine as the server. If it fails there, the issue is with server-side configuration, not Workbench.
  • Check for firewall or network issues. For remote connections, ensure port 3306 is open and accessible.
  • Try a different authentication plugin. If the user uses caching_sha2_password and your client is old, switch to mysql_native_password with: ALTER USER 'user'@'host' IDENTIFIED WITH mysql_native_password BY 'password';
  • If you’re using SSH tunneling, test the SSH connection separately. Ensure the SSH key or password is correct and that the MySQL port is accessible from the SSH host.

Frequently Asked Questions

Q: I’m sure my password is correct, but I still get access denied. Why?
A: The host part of the user is likely mismatched. Check the user table to see which host is allowed, and either change the host or create a new user with the correct host.

Q: How do I allow remote connections to MySQL?
A: Create a user with a host of ‘%’ or a specific IP, and ensure the MySQL server is configured to listen on the appropriate interface (bind-address). Also, open the firewall port.

Q: Can I reset the root password without stopping the server?
A: In most cases, you need to stop the server to use –skip-grant-tables. However, if you have another user with administrative privileges, you can use that user to reset root’s password.

Q: What does “Access denied for user ‘root’@’localhost’ (using password: YES)” mean?
A: It means the password provided is incorrect for the user ‘root’ at ‘localhost’. Double-check the password or reset it.

Q: Why does Workbench work for one database but not another?
A: The user may have privileges for one database but not the other. Grant the necessary privileges for the specific database.

Q: Is it safe to use –skip-grant-tables?
A: It’s a temporary measure for recovery. Only do it when you have physical access to the server, and always restart MySQL normally afterward.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →