Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

CREATE USER fails with error 1396

ErrorCREATE USER is refused for an account whose user and host already exist (error 1396)

Short answer

Error 1396 on CREATE USER means an account with that exact user and host already exists, often left from an earlier attempt. List the accounts, then drop the old one with DROP USER, or use CREATE USER IF NOT EXISTS when reuse is fine.

  • Applies to MySQL 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every account with that user name, host included. The host part decides which account is meant.

    SELECT user, host FROM mysql.user WHERE user = 'jack';
  2. 2Match what you see, then jump to its fix

    1. 1The query above returns a row for the same user and hostThe account already existsFix
    2. 2A previous attempt or an earlier install created the account and you want it goneAn old account must be replacedFix
    3. 3DROP USER 'jack' reports that the operation failed, yet an account for jack existsDROP USER used a name without a hostFix

What does the error look like?

  • CREATE USER is refused for an account whose user and host already exist (error 1396)

Cause 1 of 3

The account already exists

1Check

Compare the user and host in the error with the rows returned.

SELECT user, host FROM mysql.user WHERE user = 'jack';

2Fix

Reuse it with IF NOT EXISTS (this only warns), or change its password. Do not recreate it.

CREATE USER IF NOT EXISTS 'jack'@'localhost' IDENTIFIED BY 'a-new-strong-password';

3Verify

The statement ends with a warning, not an error.

SHOW WARNINGS;

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 3

An old account must be replaced

1Check

Confirm the exact user and host, because 'jack'@'%' and 'jack'@'localhost' are two accounts.

SELECT user, host FROM mysql.user WHERE user = 'jack';

2Fix

Drop that account with the full name, then create it again. DROP USER removes its privilege rows from all grant tables.

DROP USER 'jack'@'localhost';
CREATE USER 'jack'@'localhost' IDENTIFIED BY 'a-new-strong-password';

3Verify

The new account is listed.

SELECT user, host FROM mysql.user WHERE user = 'jack';

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 3

DROP USER used a name without a host

1Check

A name without a host means the host '%'. If the account is 'jack'@'localhost', the short name points at a different account.

SELECT user, host FROM mysql.user WHERE user = 'jack';

2Fix

Write the host exactly as listed. IF EXISTS turns a missing account into a warning.

DROP USER IF EXISTS 'jack'@'localhost';

3Verify

No row remains for that user and host.

SELECT user, host FROM mysql.user WHERE user = 'jack';

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Use CREATE USER IF NOT EXISTS in setup scripts so reruns do not fail.
  • Always write both user and host in account statements.
  • Use DROP USER, not DELETE on the grant tables.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.