<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="rename-user">
      </a>
      15.7.1.7 RENAME USER Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045173199328">
  </a>
  <a class="indexterm" name="idm46045173198256">
  </a>
  <a class="indexterm" name="idm46045173196768">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89561826"><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">RENAME</span> <span class="token keyword">USER</span> <em class="replaceable">old_user</em> <span class="token keyword">TO</span> <em class="replaceable">new_user</em>
    <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">old_user</em> <span class="token keyword">TO</span> <em class="replaceable">new_user</em><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="rename-user.html" title="15.7.1.7 RENAME USER Statement">
    <code class="literal">
     RENAME USER
    </code>
   </a>
   statement renames
        existing MySQL accounts. An error occurs for old accounts that
        do not exist or new accounts that already exist.
  </p>
  <p>
   To use
   <a class="link" href="rename-user.html" title="15.7.1.7 RENAME USER Statement">
    <code class="literal">
     RENAME 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_update">
    <code class="literal">
     UPDATE
    </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="rename-user.html" title="15.7.1.7 RENAME USER Statement">
    <code class="literal">
     RENAME 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="rename-user.html" title="15.7.1.7 RENAME USER Statement">
    <code class="literal">
     RENAME USER
    </code>
   </a>
   fails with an error
        if any account to be renamed is named as the
   <code class="literal">
    DEFINER
   </code>
   attribute for any stored object.
        (That is, the statement fails if renaming 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>
   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="sa85920903"><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">RENAME</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">TO</span> <span class="token string">'jeff'</span>@<span class="token string">'127.0.0.1'</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>
  <p>
   <a class="link" href="rename-user.html" title="15.7.1.7 RENAME USER Statement">
    <code class="literal">
     RENAME USER
    </code>
   </a>
   causes the privileges
        held by the old user to be those held by the new user. However,
   <a class="link" href="rename-user.html" title="15.7.1.7 RENAME USER Statement">
    <code class="literal">
     RENAME 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 old 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>
  <p>
   The privilege changes take effect as indicated in
   <a class="xref" href="privilege-changes.html" title="8.2.13 When Privilege Changes Take Effect">
    Section 8.2.13, “When Privilege Changes Take Effect”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
