Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › authentication

How to Fix MySQL Error 1045: Access Denied for User ‘root’

By Freedom251 Team · · 10 min read

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MySQL error 1045 is an authentication failure, not a generic server outage. Start with mysql -u root -p and enter the password interactively. If the message says using password: NO, no password was sent; using password: YES means a password was sent but rejected. If the result changes between localhost and 127.0.0.1, you are testing different transports and possibly different root account rows. The steps below identify which condition applies before you change credentials or grants.

What error 1045 actually means

A typical message is ERROR 1045 (28000): Access denied for user 'root'@'localhost'. The server received a connection attempt, identified the requested account as root from localhost, and rejected authentication. SQLSTATE 28000 denotes an authorization or authentication failure. It does not by itself indicate that the MySQL service is stopped; a stopped service normally produces a connection error before authentication is attempted.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MySQL authenticates the pair of values in the account name: User and Host. A row for root@localhost is a different account from root@127.0.0.1 or root@db.example. The password and authentication plugin belong to the matched row, so using the right password against the wrong host row still produces 1045.

Read the password suffix literally

Message ending What the client sent First check
using password: NO No password was supplied to the client. Retry with -p and enter the password when prompted. Also check whether the account is intentionally passwordless after an insecure initialization.
using password: YES A password value was sent, but the server did not accept it. Check the password, the selected host/transport, and whether an option file supplied an old password.

The suffix describes the request that reached the server, not whether you personally typed a password during that command. A client option file can inject one without an interactive prompt.

Choose the right branch before changing anything

Your situation Most likely explanation Safe first action
You ran mysql -u root and see NO. The client sent no credential. Run mysql -u root -p.
You see YES although you did not enter a password. An option file or environment-level client setting supplied one. Run mysql --no-defaults -u root -p.
localhost fails but 127.0.0.1 works. The two commands selected different transports and possibly different account rows or plugins. Decide whether the account is intended for a Unix socket or TCP, then inspect the matching row.
127.0.0.1 fails but localhost works. The TCP account row, TCP authentication plugin, or TCP listener does not match. Use the working socket connection to inspect User, Host, and plugin.
Both transports fail and the password is unknown. The credential must be reset using the procedure for the installed server version and operating system. Use MySQL’s current password-reset procedure, then assign the password with ALTER USER.
The data directory was initialized with --initialize-insecure. The root account may deliberately have no password. Connect only through a protected local path and set a password immediately.
The failure started after an upgrade. The configured authentication plugin may no longer be supported or enabled. Check the server version and account plugin before changing the account.

Step 1: retry with an interactive password

Use this exact form:

mysql -u root -p

When the client displays Enter password:, type the password and press Enter. Nothing is echoed. Keeping the password out of the command line prevents it from appearing in shell history and process listings in the way a command such as mysql -u root -pSecretPassword can.

Do not add a space and a password after -p. With no value attached, -p requests an interactive prompt. If the login succeeds, the original command simply omitted the credential. If it still returns 1045 with using password: YES, continue rather than repeatedly guessing: the next checks distinguish a stale client setting from a wrong account or password.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 2: bypass stale option-file credentials

MySQL clients read option files that can provide a user name, host, port, socket, or password. An old password in one of those files can make a command fail even when you believe you supplied no password. Suppress those defaults for one test:

mysql --no-defaults -u root -p

This invocation still lets you enter a password interactively, but it does not load the normal option-file settings for that run. Compare its result with the ordinary command:

  1. Run mysql -u root -p and note the complete error, including NO or YES.
  2. Run mysql --no-defaults -u root -p and enter the same intended password.
  3. If the second command works, inspect the client option files used by your operating system and remove or correct the obsolete credential, host, socket, or port. Keep credentials out of shared files unless their permissions and purpose are understood.
  4. If both commands fail identically, the problem is more likely the password, account host row, transport, or server-side plugin.

--no-defaults is a diagnostic bypass, not a permanent configuration fix. It can also remove a required socket or port setting, so a changed connection target is possible; compare the host and transport explicitly in the next step.

Step 3: test the socket and TCP paths separately

On a local installation, localhost normally makes MySQL programs use a Unix socket. The MySQL Reference Manual states that a TCP/IP connection requires connection parameters that force TCP. Use these two explicit tests:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mysql -u root -p
mysql -h 127.0.0.1 -u root -p

The first command normally uses the local socket; the second requests TCP/IP to the loopback address. You can also make the host choice explicit with -h localhost, but that still normally resolves to socket behavior on common Unix installations. A successful socket login does not prove that a TCP login should work, and vice versa.

When localhost works but 127.0.0.1 fails

The root account may exist only as root@localhost, or its socket authentication plugin may accept local socket credentials while rejecting a TCP client. Use the working socket session to inspect the account rows and plugin. Do not “fix” this by adding a root account for every host unless remote access is genuinely required.

When 127.0.0.1 works but localhost fails

The TCP request is matching a different row, while the socket row is absent, has another password, or uses an authentication method your client cannot complete. Verify the socket path and the root@localhost row rather than assuming the password is wrong.

When both fail

Run the no-defaults test first. If the password is known and both transports still return 1045, inspect the account rows from another administrative account or proceed to the version-appropriate reset procedure.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file, unless there are connection parameters specified to ensure that the client makes a TCP/IP connection.” — MySQL Reference Manual

Step 4: inspect the matching account row

You need an administrative session to query the grant tables. If another administrator can log in, run:

SELECT User, Host, plugin FROM mysql.user WHERE User = 'root';

The result shows which host values exist for root and which authentication plugin each row uses. Compare those values with the command you are running:

  • A command using the socket normally needs a row whose Host matches localhost.
  • A command using -h 127.0.0.1 needs a row that MySQL’s host-matching rules select for that address.
  • A hostname, container name, or remote address can select yet another row.
  • The plugin column explains why a password that works for one row is rejected by another.

MySQL grant-table matching uses both User and Host; it is not enough to see a root user somewhere in the table. If you administer a system with multiple root rows, record which row is used by each connection method before changing a password.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why granting root to % is a poor shortcut

A host value of % is a wildcard that permits connections from any host. The MySQL security documentation warns that such a grant leaves the account insecure. It can expose a highly privileged account to every reachable network, and it can mask the real host-matching problem. Prefer the narrow host row required by the deployment, and use a separate least-privilege administrative account for routine work.

Step 5: reset a forgotten root password safely

If the password is genuinely lost, repeated login attempts cannot recover it. The exact recovery commands depend on the MySQL server version, operating system, service manager, and whether the installation uses a socket or TCP. Use the current MySQL password-reset procedure for that installed version instead of copying an old command from an unrelated release.

The safe recovery sequence has these stages:

  1. Identify the installation. Confirm which server instance and data directory you are repairing, and note the installed MySQL version and operating system. A client binary’s version is not always the server’s version.
  2. Restrict access. Stop the normal server and follow the official procedure to start a temporary recovery mode, such as an initialization file or the version-appropriate grant-bypass method. Perform this on a controlled local machine; do not expose a recovery instance to a network.
  3. Connect through the intended local path. The temporary mode may require a socket connection and may not accept the same host or port as the normal service.
  4. Change the exact account row. After administrative access is available, assign a new credential with the account’s real host value, for example:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'a-long-unique-password';

Replace localhost only when inspection shows that the required root row has another host. Altering root@localhost does not change root@127.0.0.1.

  1. End recovery mode. Shut down the temporary instance, remove any temporary initialization file containing the password, and restart MySQL normally using the service’s documented method.
  2. Verify both security and connectivity. Test the intended socket or TCP command with -p, then confirm that the server is no longer running with grant checks bypassed.

Do not leave a recovery option, plaintext password file, or grant-bypass process in place. If the official instructions for your release use a different syntax, follow those instructions; password-reset procedures are version-specific for a reason.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 6: handle an insecure initialization

MySQL documents that initializing with mysqld --initialize-insecure can permit a passwordless root login and describes that state as a security risk. In that situation, a command with no -p may be the expected way to enter locally:

mysql -u root

Once connected, set a password immediately with ALTER USER for the actual root host row. Then close the session and verify that mysql -u root is rejected while mysql -u root -p succeeds. Do not interpret a passwordless local login as evidence that the server is correctly secured; it is an initialization condition that must be corrected.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Step 7: check authentication-plugin and version compatibility

The account’s authentication plugin must be supported by both the server and the client. Query the plugin column as shown above, then check the server release before changing it.

MySQL 8.4

MySQL 8.4 disables mysql_native_password by default. An account configured to use that legacy plugin can therefore fail after an upgrade even when its old password is correct. Prefer a current client and the authentication plugin supported by the server rather than enabling a legacy plugin globally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MySQL 9.0

MySQL 9.0 removes mysql_native_password. A migration that worked on an older server can consequently produce an authentication failure after the upgrade. Update clients and account definitions to a supported plugin before attempting another password reset.

Changing an authentication plugin is not interchangeable with changing a password. It can affect client-library compatibility, replication tooling, and applications. Make the change for the specific account and test every client that uses it; do not make a legacy plugin the default merely to silence error 1045.

Common failed fixes and what they teach you

Adding -p but still getting YES

This confirms that a credential reached the server, not that it was the credential you intended. Run the --no-defaults command, then inspect host selection and the account plugin.

Changing only the password for one host row

If the application connects over TCP while you changed root@localhost, nothing about the TCP row changes. Match the ALTER USER target to the connection’s selected Host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Replacing the host with %

This may make a test connection appear to work, but it broadens access to every host and creates a serious exposure for a privileged account. Solve the matching problem with the narrowest required host instead.

Copying a reset command from another MySQL release

Recovery flags, service commands, and plugin behavior differ by version and platform. An obsolete command can fail, leave the server in an unsafe mode, or change the wrong instance. Identify the server version and use the corresponding official procedure.

Assuming the error is caused by a stopped service

Error 1045 means the server got far enough to reject authentication. If the service were unreachable, you would normally see a connection or socket error instead. Check service status only after distinguishing connectivity from authentication.

A repeatable diagnostic checklist

  1. Copy the entire error, including the account host and the using password suffix.
  2. Run mysql -u root -p and enter the password interactively.
  3. Run mysql --no-defaults -u root -p to eliminate stale option-file values.
  4. Compare socket access with mysql -h 127.0.0.1 -u root -p.
  5. From a working administrative session, query User, Host, and plugin for every root row.
  6. Do not add Host='%' as a shortcut.
  7. If the password is lost, use the reset procedure for the installed version and then run ALTER USER on the correct host row.
  8. If the data directory was initialized insecurely, set a password before allowing normal use.
  9. After upgrades, verify plugin support: mysql_native_password is disabled by default in MySQL 8.4 and removed in MySQL 9.0.
  10. Retest the exact transport used by the application, not merely a different local command that happens to work.

Bottom line

Error 1045 becomes manageable when you treat it as a precise account-and-transport mismatch. Start with an interactive password, remove hidden option-file credentials, distinguish the Unix socket from TCP, inspect the exact User/Host row, and only then reset credentials or address plugin compatibility. Keep host grants narrow and finish by returning the server to normal, authenticated operation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

authenticationDatabase TroubleshootingError 1045Linux administrationMySQLRoot Password

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.