Blog › MySQL · Published 2026-11-26

MySQL error 1045 access denied: read the message, fix the cause

MySQL error 1045 (Access denied for user 'x'@'y') looks like a password problem, but the message itself carries three clues that point to the real cause. This guide reads the message the way the official MySQL reference manual does.

Read the message first

Per the MySQL manual, the error tells you: who you are trying to log in as, the client host you are connecting from, and whether a password was used. using password: NO means you tried to log in without a password at all. Normally the user table on the server should have one row that exactly matches the host name and user name in the error message.

Checklist, in order

  1. Are you passing a password? If the message says using password: NO and the account has one, you forgot -p or your config file is not being read.
  2. Wrong password? With using password: YES and a matching account, the password is the first suspect.
  3. Does a matching account exist? Check what the server knows:
    SELECT User, Host FROM mysql.user;
    The result should include a row whose Host and User match your client host and MySQL user name.
  4. Connecting from another machine? An error like Host ... is not allowed to connect to this MySQL server means no user table row has a Host value matching your client host. Fix it by creating an account for the client-host plus user-name combination you actually use.
  5. Localhost quirks: localhost is special; using --host=127.0.0.1 forces a TCP/IP connection to the local server, and the host name must then appear in a user table row even though you are on the same machine.

Fixes that follow from the diagnosis

Common mistakes

Running MySQL behind nginx? See fixing nginx 502 Bad Gateway for the layer in front. If you would rather hand database and server care to us, see hosting and maintenance.

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles