mysqldude
Error codes › 1396

MySQL & MariaDB error 1396: Operation CREATE USER / DROP USER failed

Error messageOperation … failed for …
Example from our test runs: Operation CREATE USER failed for 'app1'@'%' (5.6.51)

The account statement hit an account that does or doesn't exist. Accounts are user@host pairs, so 'app'@'%' and 'app'@'localhost' are different accounts.

MySQLMariaDB
SymbolER_CANNOT_USERER_CANNOT_USER
SQLSTATEHY000HY000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

The message names the operation and the account, e.g. Operation CREATE USER failed for 'app'@'%'. CREATE USER fails because the account already exists; DROP USER, RENAME USER and ALTER USER fail because it doesn’t.

Why it happens

  • A setup script runs twice and creates the same account again.
  • The host part doesn’t match. DROP USER 'app' means 'app'@'%', which isn’t the same account as 'app'@'localhost' or 'app'@'10.0.%'.
  • Someone removed rows from mysql.user with DELETE instead of DROP USER, so other grant tables or the in-memory cache still know the account. CREATE USER then fails until FLUSH PRIVILEGES. Never edit the grant tables directly.

How to fix it

  • List the accounts: SELECT user, host FROM mysql.user WHERE user = 'app'; and use the exact user@host pair.
  • Make scripts repeatable with CREATE USER IF NOT EXISTS and DROP USER IF EXISTS (MySQL 5.7+, MariaDB). MySQL 5.6 doesn’t support IF [NOT] EXISTS here.
  • If grant tables were edited by hand, FLUSH PRIVILEGES; and then DROP USER the account properly before creating it again.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database:

    CREATE DATABASE demo;
    USE demo;
  2. Run:

    CREATE USER 'app1'@'%' IDENTIFIED BY 'Test#1234';
    CREATE USER 'app1'@'%' IDENTIFIED BY 'Test#1234';

You get: Operation CREATE USER failed for 'app1'@'%'(11.8.9)

Verified fixes

  1. Check which user@host pairs exist before creating or dropping

    CREATE USER 'app1'@'%' IDENTIFIED BY 'Test#1234';
    SELECT user, host FROM mysql.user WHERE user = 'app1';
  2. CREATE USER IF NOT EXISTS / DROP USER IF EXISTS (MySQL 5.7+, MariaDB)

    CREATE USER IF NOT EXISTS 'app1'@'%' IDENTIFIED BY 'Test#1234';
    CREATE USER IF NOT EXISTS 'app1'@'%' IDENTIFIED BY 'Test#1234';
    DROP USER IF EXISTS 'app1'@'localhost';
    SELECT COUNT(*) FROM mysql.user WHERE user = 'app1';

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Create an account that already exists
repro
✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396
Drop an account that doesn't exist (the host part must match exactly)
version check
✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396✓ 1396
Check which user@host pairs exist before creating or dropping
fix
✓✓✓✓✓✓✓✓✓
CREATE USER IF NOT EXISTS / DROP USER IF EXISTS (MySQL 5.7+, MariaDB)
fix
✗ 1064✓✓✓✓✓✓✓✓
Create an account that already exists repro
MySQL 5.6✓ 13965.7✓ 13968.0✓ 13968.4✓ 13969✓ 1396
MariaDB 10.6✓ 139610.11✓ 139611.4✓ 139611.8✓ 1396
Drop an account that doesn't exist (the host part must match exactly) version check
MySQL 5.6✓ 13965.7✓ 13968.0✓ 13968.4✓ 13969✓ 1396
MariaDB 10.6✓ 139610.11✓ 139611.4✓ 139611.8✓ 1396
Check which user@host pairs exist before creating or dropping fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
CREATE USER IF NOT EXISTS / DROP USER IF EXISTS (MySQL 5.7+, MariaDB) fix
MySQL 5.6✗ 10645.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (1)
  • CREATE USER IF NOT EXISTS / DROP USER IF EXISTS (MySQL 5.7+, MariaDB) (MySQL 5.6): error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS 'app1'@'%' IDENTIFIED BY 'Test#

Related errors

  • 1045 ER_ACCESS_DENIED_ERRORexplained
  • 1133 ER_PASSWORD_NO_MATCH
  • 1227 ER_SPECIFIC_ACCESS_DENIED_ERRORexplained