<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="creating-accounts">
      </a>
      8.2.8 Adding Accounts, Assigning Privileges, and Dropping Accounts
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045249592368">
  </a>
  <a class="indexterm" name="idm46045249591328">
  </a>
  <a class="indexterm" name="idm46045249589840">
  </a>
  <a class="indexterm" name="idm46045249588768">
  </a>
  <a class="indexterm" name="idm46045249587280">
  </a>
  <a class="indexterm" name="idm46045249586208">
  </a>
  <a class="indexterm" name="idm46045249584720">
  </a>
  <a class="indexterm" name="idm46045249583648">
  </a>
  <a class="indexterm" name="idm46045249582160">
  </a>
  <a class="indexterm" name="idm46045249580672">
  </a>
  <a class="indexterm" name="idm46045249579184">
  </a>
  <a class="indexterm" name="idm46045249577696">
  </a>
  <a class="indexterm" name="idm46045249576208">
  </a>
  <a class="indexterm" name="idm46045249574720">
  </a>
  <a class="indexterm" name="idm46045249573232">
  </a>
  <p>
   To manage MySQL accounts, use the SQL statements intended for that
      purpose:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
       <code class="literal">
        CREATE USER
       </code>
      </a>
      and
      <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
       <code class="literal">
        DROP USER
       </code>
      </a>
      create and remove
          accounts.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
       <code class="literal">
        GRANT
       </code>
      </a>
      and
      <a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
       <code class="literal">
        REVOKE
       </code>
      </a>
      assign privileges to and
          revoke privileges from accounts.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="show-grants.html" title="15.7.7.22 SHOW GRANTS Statement">
       <code class="literal">
        SHOW GRANTS
       </code>
      </a>
      displays account
          privilege assignments.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Account-management statements cause the server to make appropriate
      modifications to the underlying grant tables, which are discussed
      in
   <a class="xref" href="grant-tables.html" title="8.2.3 Grant Tables">
    Section 8.2.3, “Grant Tables”
   </a>
   .
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Direct modification of grant tables using statements such as
    <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
     <code class="literal">
      INSERT
     </code>
    </a>
    ,
    <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
     <code class="literal">
      UPDATE
     </code>
    </a>
    , or
    <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
     <code class="literal">
      DELETE
     </code>
    </a>
    is discouraged and done at
        your own risk. The server is free to ignore rows that become
        malformed as a result of such modifications.
   </p>
   <p>
    For any operation that modifies a grant table, the server checks
        whether the table has the expected structure and produces an
        error if not. To update the tables to the expected structure,
        perform the MySQL upgrade procedure. See
    <a class="xref" href="upgrading.html" title="Chapter 3 Upgrading MySQL">
     Chapter 3,
     <i>
      Upgrading MySQL
     </i>
    </a>
    .
   </p>
  </div>
  <p>
   Another option for creating accounts is to use the GUI tool
      MySQL Workbench. Also, several third-party programs offer capabilities
      for MySQL account administration.
   <code class="literal">
    phpMyAdmin
   </code>
   is
      one such program.
  </p>
  <p>
   This section discusses the following topics:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="creating-accounts.html#creating-accounts-granting-privileges" title="Creating Accounts and Granting Privileges">
       Creating Accounts and Granting Privileges
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="creating-accounts.html#checking-account-privileges" title="Checking Account Privileges and Properties">
       Checking Account Privileges and Properties
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="creating-accounts.html#revoking-account-privileges" title="Revoking Account Privileges">
       Revoking Account Privileges
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="creating-accounts.html#dropping-accounts" title="Dropping Accounts">
       Dropping Accounts
      </a>
     </p>
    </li>
   </ul>
  </div>
  <p>
   For additional information about the statements discussed here,
      see
   <a class="xref" href="account-management-statements.html" title="15.7.1 Account Management Statements">
    Section 15.7.1, “Account Management Statements”
   </a>
   .
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="creating-accounts-granting-privileges">
       </a>
       Creating Accounts and Granting Privileges
      </h4>
     </div>
    </div>
   </div>
   <p>
    The following examples show how to use the
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    client program to set up new accounts.
        These examples assume that the MySQL
    <code class="literal">
     root
    </code>
    account has the
    <a class="link" href="privileges-provided.html#priv_create-user">
     <code class="literal">
      CREATE USER
     </code>
    </a>
    privilege and all privileges that it grants to other accounts.
   </p>
   <p>
    At the command line, connect to the server as the MySQL
    <code class="literal">
     root
    </code>
    user, supplying the appropriate password
        at the password prompt:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa70642668"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> <span class="token property">-u</span> root <span class="token property">-p</span>
Enter password<span class="token punctuation">:</span> <span class="token punctuation"></span><em class="replaceable"><span class="token punctuation">(</span>enter root password here<span class="token punctuation">)</span></em><span class="token punctuation"></span></code></pre>
   </div>
   <p>
    After connecting to the server, you can add new accounts. The
        following example uses
    <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
     <code class="literal">
      CREATE USER
     </code>
    </a>
    and
    <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
     <code class="literal">
      GRANT
     </code>
    </a>
    statements
        to set up four accounts (where you see
    <code class="literal">
     '
     <em class="replaceable">
      <code>
       password
      </code>
     </em>
     '
    </code>
    ,
        substitute an appropriate password):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70440063"><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">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'finley'</span>@<span class="token string">'localhost'</span>
  <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">ALL</span>
  <span class="token keyword">ON</span> <span class="token operator">*</span><span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">TO</span> <span class="token string">'finley'</span>@<span class="token string">'localhost'</span>
  <span class="token keyword">WITH</span> <span class="token keyword">GRANT</span> <span class="token keyword">OPTION</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'finley'</span>@<span class="token string">'%.example.com'</span>
  <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">ALL</span>
  <span class="token keyword">ON</span> <span class="token operator">*</span><span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">TO</span> <span class="token string">'finley'</span>@<span class="token string">'%.example.com'</span>
  <span class="token keyword">WITH</span> <span class="token keyword">GRANT</span> <span class="token keyword">OPTION</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span>
  <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">RELOAD</span><span class="token punctuation">,</span><span class="token keyword">PROCESS</span>
  <span class="token keyword">ON</span> <span class="token operator">*</span><span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">TO</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'dummy'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    The accounts created by those statements have the following
        properties:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Two accounts have a user name of
       <code class="literal">
        finley
       </code>
       .
            Both are superuser accounts with full global privileges to
            do anything. The
       <code class="literal">
        'finley'@'localhost'
       </code>
       account can be used only when connecting from the local
            host. The
       <code class="literal">
        'finley'@'%.example.com'
       </code>
       account uses the
       <code class="literal">
        '%'
       </code>
       wildcard in the host
            part, so it can be used to connect from any host in the
       <code class="literal">
        example.com
       </code>
       domain.
      </p>
      <p>
       The
       <code class="literal">
        'finley'@'localhost'
       </code>
       account is
            necessary if there is an anonymous-user account for
       <code class="literal">
        localhost
       </code>
       . Without the
       <code class="literal">
        'finley'@'localhost'
       </code>
       account, that
            anonymous-user account takes precedence when
       <code class="literal">
        finley
       </code>
       connects from the local host and
       <code class="literal">
        finley
       </code>
       is treated as an anonymous user.
            The reason for this is that the anonymous-user account has a
            more specific
       <code class="literal">
        Host
       </code>
       column value than the
       <code class="literal">
        'finley'@'%'
       </code>
       account and thus comes
            earlier in the
       <code class="literal">
        user
       </code>
       table sort order.
            (For information about
       <code class="literal">
        user
       </code>
       table
            sorting, see
       <a class="xref" href="connection-access.html" title="8.2.6 Access Control, Stage 1: Connection Verification">
        Section 8.2.6, “Access Control, Stage 1: Connection Verification”
       </a>
       .)
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <code class="literal">
        'admin'@'localhost'
       </code>
       account can be
            used only by
       <code class="literal">
        admin
       </code>
       to connect from the
            local host. It is granted the global
       <a class="link" href="privileges-provided.html#priv_reload">
        <code class="literal">
         RELOAD
        </code>
       </a>
       and
       <a class="link" href="privileges-provided.html#priv_process">
        <code class="literal">
         PROCESS
        </code>
       </a>
       administrative
            privileges. These privileges enable the
       <code class="literal">
        admin
       </code>
       user to execute the
       <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
        <span class="command">
         <strong>
          mysqladmin reload
         </strong>
        </span>
       </a>
       ,
       <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
        <span class="command">
         <strong>
          mysqladmin
            refresh
         </strong>
        </span>
       </a>
       , and
       <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
        <span class="command">
         <strong>
          mysqladmin
            flush-
          <em class="replaceable">
           <code>
            xxx
           </code>
          </em>
         </strong>
        </span>
       </a>
       commands, as
            well as
       <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
        <span class="command">
         <strong>
          mysqladmin processlist
         </strong>
        </span>
       </a>
       . No
            privileges are granted for accessing any databases. You
            could add such privileges using
       <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
        <code class="literal">
         GRANT
        </code>
       </a>
       statements.
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <code class="literal">
        'dummy'@'localhost'
       </code>
       account has no
            password (which is insecure and not recommended). This
            account can be used only to connect from the local host. No
            privileges are granted. It is assumed that you grant
            specific privileges to the account using
       <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
        <code class="literal">
         GRANT
        </code>
       </a>
       statements.
      </p>
     </li>
    </ul>
   </div>
   <p>
    The previous example grants privileges at the global level. The
        next example creates three accounts and grants them access at
        lower levels; that is, to specific databases or objects within
        databases. Each account has a user name of
    <code class="literal">
     custom
    </code>
    , but the host name parts differ:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68391677"><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">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'custom'</span>@<span class="token string">'localhost'</span>
  <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">ALL</span>
  <span class="token keyword">ON</span> bankaccount<span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">TO</span> <span class="token string">'custom'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'custom'</span>@<span class="token string">'host47.example.com'</span>
  <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">SELECT</span><span class="token punctuation">,</span><span class="token keyword">INSERT</span><span class="token punctuation">,</span><span class="token keyword">UPDATE</span><span class="token punctuation">,</span><span class="token keyword">DELETE</span><span class="token punctuation">,</span><span class="token keyword">CREATE</span><span class="token punctuation">,</span><span class="token keyword">DROP</span>
  <span class="token keyword">ON</span> expenses<span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">TO</span> <span class="token string">'custom'</span>@<span class="token string">'host47.example.com'</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'custom'</span>@<span class="token string">'%.example.com'</span>
  <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">SELECT</span><span class="token punctuation">,</span><span class="token keyword">INSERT</span><span class="token punctuation">,</span><span class="token keyword">UPDATE</span><span class="token punctuation">,</span><span class="token keyword">DELETE</span><span class="token punctuation">,</span><span class="token keyword">CREATE</span><span class="token punctuation">,</span><span class="token keyword">DROP</span>
  <span class="token keyword">ON</span> customer<span class="token punctuation">.</span>addresses
  <span class="token keyword">TO</span> <span class="token string">'custom'</span>@<span class="token string">'%.example.com'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    The three accounts can be used as follows:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The
       <code class="literal">
        'custom'@'localhost'
       </code>
       account has all
            database-level privileges to access the
       <code class="literal">
        bankaccount
       </code>
       database. The account can be
            used to connect to the server only from the local host.
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <code class="literal">
        'custom'@'host47.example.com'
       </code>
       account
            has specific database-level privileges to access the
       <code class="literal">
        expenses
       </code>
       database. The account can be
            used to connect to the server only from the host
       <code class="literal">
        host47.example.com
       </code>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <code class="literal">
        'custom'@'%.example.com'
       </code>
       account has
            specific table-level privileges to access the
       <code class="literal">
        addresses
       </code>
       table in the
       <code class="literal">
        customer
       </code>
       database, from any host in the
       <code class="literal">
        example.com
       </code>
       domain. The account can be
            used to connect to the server from all machines in the
            domain due to use of the
       <code class="literal">
        %
       </code>
       wildcard
            character in the host part of the account name.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="checking-account-privileges">
       </a>
       Checking Account Privileges and Properties
      </h4>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045249487088">
   </a>
   <a class="indexterm" name="idm46045249485600">
   </a>
   <p>
    To see the privileges for an account, use
    <a class="link" href="show-grants.html" title="15.7.7.22 SHOW GRANTS Statement">
     <code class="literal">
      SHOW GRANTS
     </code>
    </a>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38466710"><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 prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">GRANTS</span> <span class="token keyword">FOR</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Grants for admin@localhost                          <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> GRANT RELOAD, PROCESS ON *.* TO `admin`@`localhost` <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    To see nonprivilege properties for an account, use
    <a class="link" href="show-create-user.html" title="15.7.7.13 SHOW CREATE USER Statement">
     <code class="literal">
      SHOW CREATE USER
     </code>
    </a>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40235242"><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 prompt">mysql&gt;</span> <span class="token keyword">SET</span> print_identified_with_as_hex <span class="token operator">=</span> <span class="token keyword">ON</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
CREATE USER for admin@localhost<span class="token punctuation">:</span> CREATE USER `admin`@`localhost`
IDENTIFIED WITH 'caching_sha2_password'
AS 0x24412430303524301D0E17054E2241362B1419313C3E44326F294133734B30792F436E77764270373039612E32445250786D43594F45354532324B6169794F47457852796E32
REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK
PASSWORD HISTORY DEFAULT
PASSWORD REUSE INTERVAL DEFAULT
PASSWORD REQUIRE CURRENT DEFAULT</span></code></pre>
   </div>
   <p>
    Enabling the
    <a class="link" href="server-system-variables.html#sysvar_print_identified_with_as_hex">
     <code class="literal">
      print_identified_with_as_hex
     </code>
    </a>
    system variable causes
    <a class="link" href="show-create-user.html" title="15.7.7.13 SHOW CREATE USER Statement">
     <code class="literal">
      SHOW CREATE
        USER
     </code>
    </a>
    to display hash values that contain unprintable
        characters as hexadecimal strings rather than as regular string
        literals.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="revoking-account-privileges">
       </a>
       Revoking Account Privileges
      </h4>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045249471600">
   </a>
   <a class="indexterm" name="idm46045249470112">
   </a>
   <p>
    To revoke account privileges, use the
    <a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
     <code class="literal">
      REVOKE
     </code>
    </a>
    statement. Privileges can
        be revoked at different levels, just as they can be granted at
        different levels.
   </p>
   <p>
    Revoke global privileges:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40987640"><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">REVOKE</span> <span class="token keyword">ALL</span>
  <span class="token keyword">ON</span> <span class="token operator">*</span><span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">FROM</span> <span class="token string">'finley'</span>@<span class="token string">'%.example.com'</span><span class="token punctuation">;</span>

<span class="token keyword">REVOKE</span> <span class="token keyword">RELOAD</span>
  <span class="token keyword">ON</span> <span class="token operator">*</span><span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">FROM</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    Revoke database-level privileges:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11946417"><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">REVOKE</span> <span class="token keyword">CREATE</span><span class="token punctuation">,</span><span class="token keyword">DROP</span>
  <span class="token keyword">ON</span> expenses<span class="token punctuation">.</span><span class="token operator">*</span>
  <span class="token keyword">FROM</span> <span class="token string">'custom'</span>@<span class="token string">'host47.example.com'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    Revoke table-level privileges:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35950151"><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">REVOKE</span> <span class="token keyword">INSERT</span><span class="token punctuation">,</span><span class="token keyword">UPDATE</span><span class="token punctuation">,</span><span class="token keyword">DELETE</span>
  <span class="token keyword">ON</span> customer<span class="token punctuation">.</span>addresses
  <span class="token keyword">FROM</span> <span class="token string">'custom'</span>@<span class="token string">'%.example.com'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    To check the effect of privilege revocation, use
    <a class="link" href="show-grants.html" title="15.7.7.22 SHOW GRANTS Statement">
     <code class="literal">
      SHOW GRANTS
     </code>
    </a>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42263761"><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 prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">GRANTS</span> <span class="token keyword">FOR</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Grants for admin@localhost                  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> GRANT PROCESS ON *.* TO `admin`@`localhost` <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="dropping-accounts">
       </a>
       Dropping Accounts
      </h4>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045249457664">
   </a>
   <a class="indexterm" name="idm46045249456176">
   </a>
   <a class="indexterm" name="idm46045249454688">
   </a>
   <a class="indexterm" name="idm46045249453200">
   </a>
   <p>
    To remove an account, use the
    <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
     <code class="literal">
      DROP
        USER
     </code>
    </a>
    statement. For example, to drop some of the
        accounts created previously:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17512299"><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">'finley'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token keyword">DROP</span> <span class="token keyword">USER</span> <span class="token string">'finley'</span>@<span class="token string">'%.example.com'</span><span class="token punctuation">;</span>
<span class="token keyword">DROP</span> <span class="token keyword">USER</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token keyword">DROP</span> <span class="token keyword">USER</span> <span class="token string">'dummy'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
   </div>
  </div>
 </div>
 <br/>
</div>
