<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="drop-user">
      </a>
      15.7.1.5 DROP USER Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045174045120">
  </a>
  <a class="indexterm" name="idm46045174044048">
  </a>
  <a class="indexterm" name="idm46045174042560">
  </a>
  <a class="indexterm" name="idm46045174041072">
  </a>
  <a class="indexterm" name="idm46045174039584">
  </a>
  <a class="indexterm" name="idm46045174038096">
  </a>
  <a class="indexterm" name="idm46045174036608">
  </a>
  <a class="indexterm" name="idm46045174035120">
  </a>
  <a class="indexterm" name="idm46045174033632">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa12426837"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">USER</span> <span class="token punctuation">[</span><span class="token keyword">IF</span> <span class="token keyword">EXISTS</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">user</em></span> <span class="token punctuation">[</span><span class="token punctuation">,</span> <span class="token keyword"><em class="replaceable">user</em></span><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
  </div>
  <p>
   The
   <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
    <code class="literal">
     DROP USER
    </code>
   </a>
   statement removes
        one or more MySQL accounts and their privileges. It removes
        privilege rows for the account from all grant tables.
  </p>
  <p>
   Roles named in the
   <a class="link" href="server-system-variables.html#sysvar_mandatory_roles">
    <code class="literal">
     mandatory_roles
    </code>
   </a>
   system variable
        value cannot be dropped.
  </p>
  <p>
   To use
   <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
    <code class="literal">
     DROP USER
    </code>
   </a>
   , you must have
        the global
   <a class="link" href="privileges-provided.html#priv_create-user">
    <code class="literal">
     CREATE USER
    </code>
   </a>
   privilege,
        or the
   <a class="link" href="privileges-provided.html#priv_delete">
    <code class="literal">
     DELETE
    </code>
   </a>
   privilege for the
   <code class="literal">
    mysql
   </code>
   system schema. When the
   <a class="link" href="server-system-variables.html#sysvar_read_only">
    <code class="literal">
     read_only
    </code>
   </a>
   system variable is
        enabled,
   <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
    <code class="literal">
     DROP USER
    </code>
   </a>
   additionally
        requires the
   <a class="link" href="privileges-provided.html#priv_connection-admin">
    <code class="literal">
     CONNECTION_ADMIN
    </code>
   </a>
   privilege (or the deprecated
   <a class="link" href="privileges-provided.html#priv_super">
    <code class="literal">
     SUPER
    </code>
   </a>
   privilege).
  </p>
  <p>
   <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
    <code class="literal">
     DROP USER
    </code>
   </a>
   fails with an error if
        any account to be dropped is named as the
   <code class="literal">
    DEFINER
   </code>
   attribute for any stored object.
        (That is, the statement fails if dropping an account would cause
        a stored object to become orphaned.) To perform the operation
        anyway, you must have the
   <a class="link" href="privileges-provided.html#priv_set-any-definer">
    <code class="literal">
     SET_ANY_DEFINER
    </code>
   </a>
   or
   <a class="link" href="privileges-provided.html#priv_allow-nonexistent-definer">
    <code class="literal">
     ALLOW_NONEXISTENT_DEFINER
    </code>
   </a>
   privilege; in this case, the statement succeeds with a warning
        rather than failing with an error. For additional information,
        including how to identify which objects name a given account as
        the
   <code class="literal">
    DEFINER
   </code>
   attribute, see
   <a class="xref" href="stored-objects-security.html#stored-objects-security-orphan-objects" title="Orphan Stored Objects">
    Orphan Stored Objects
   </a>
   .
  </p>
  <p>
   <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
    <code class="literal">
     DROP USER
    </code>
   </a>
   either succeeds for all
        named users or rolls back and has no effect if any error occurs.
        By default, an error occurs if you try to drop a user that does
        not exist. If the
   <code class="literal">
    IF EXISTS
   </code>
   clause is given,
        the statement produces a warning for each named user that does
        not exist, rather than an error.
  </p>
  <p>
   The statement is written to the binary log if it succeeds, but
        not if it fails; in that case, rollback occurs and no changes
        are made. A statement written to the binary log includes all
        named users. If the
   <code class="literal">
    IF EXISTS
   </code>
   clause is
        given, this includes even users that do not exist and were not
        dropped.
  </p>
  <p>
   Each account name uses the format described in
   <a class="xref" href="account-names.html" title="8.2.4 Specifying Account Names">
    Section 8.2.4, “Specifying Account Names”
   </a>
   . For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa72428483"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The host name part of the account name, if omitted, defaults to
   <code class="literal">
    '%'
   </code>
   .
  </p>
  <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Important
   </div>
   <p>
    <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
     <code class="literal">
      DROP USER
     </code>
    </a>
    does not
          automatically close any open user sessions. Rather, in the
          event that a user with an open session is dropped, the
          statement does not take effect until that user's session is
          closed. Once the session is closed, the user is dropped, and
          that user's next attempt to log in fails.
    <span class="emphasis">
     <em>
      This
          is by design
     </em>
    </span>
    .
   </p>
  </div>
  <p>
   <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
    <code class="literal">
     DROP USER
    </code>
   </a>
   does not automatically
        drop or invalidate databases or objects within them that the old
        user created. This includes stored programs or views for which
        the
   <code class="literal">
    DEFINER
   </code>
   attribute names the dropped user.
        Attempts to access such objects may produce an error if they
        execute in definer security context. (For information about
        security context, see
   <a class="xref" href="stored-objects-security.html" title="27.6 Stored Object Access Control">
    Section 27.6, “Stored Object Access Control”
   </a>
   .)
  </p>
 </div>
 <br/>
</div>
