<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="set-default-role">
      </a>
      15.7.1.9 SET DEFAULT ROLE Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045173040928">
  </a>
  <a class="indexterm" name="idm46045173039872">
  </a>
  <a class="indexterm" name="idm46045173038384">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43289336"><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">SET</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">ROLE</span>
    {<span class="token keyword">NONE</span> <span class="token operator">|</span> <span class="token keyword">ALL</span> <span class="token operator">|</span> <span class="token keyword"><em class="replaceable">role</em></span> <span class="token punctuation">[</span><span class="token punctuation">,</span> <span class="token keyword"><em class="replaceable">role</em></span> <span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>}
    <span class="token keyword">TO</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>
   For each
   <em class="replaceable">
    <code>
     user
    </code>
   </em>
   named immediately after
        the
   <code class="literal">
    TO
   </code>
   keyword, this statement defines which
        roles become active when the user connects to the server and
        authenticates, or when the user executes the
   <a class="link" href="set-role.html" title="15.7.1.11 SET ROLE Statement">
    <code class="literal">
     SET ROLE
        DEFAULT
    </code>
   </a>
   statement during a session.
  </p>
  <p>
   <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
    <code class="literal">
     SET DEFAULT ROLE
    </code>
   </a>
   is alternative
        syntax for
   <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
    <code class="literal">
     ALTER
        USER ... DEFAULT ROLE
    </code>
   </a>
   (see
   <a class="xref" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
    Section 15.7.1.1, “ALTER USER Statement”
   </a>
   ). However,
   <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
    <code class="literal">
     ALTER USER
    </code>
   </a>
   can set the default
        for only a single user, whereas
   <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
    <code class="literal">
     SET DEFAULT
        ROLE
    </code>
   </a>
   can set the default for multiple users. On the
        other hand, you can specify
   <code class="literal">
    CURRENT_USER
   </code>
   as
        the user name for the
   <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
    <code class="literal">
     ALTER USER
    </code>
   </a>
   statement, whereas you cannot for
   <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
    <code class="literal">
     SET
        DEFAULT ROLE
    </code>
   </a>
   .
  </p>
  <p>
   <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
    <code class="literal">
     SET DEFAULT ROLE
    </code>
   </a>
   requires these
        privileges:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Setting the default roles for another user requires 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.default_roles
      </code>
      system table.
     </p>
    </li>
    <li class="listitem">
     <p>
      Setting the default roles for yourself requires no special
            privileges, as long as the roles you want as the default
            have been granted to you.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Each role name uses the format described in
   <a class="xref" href="role-names.html" title="8.2.5 Specifying Role Names">
    Section 8.2.5, “Specifying Role Names”
   </a>
   . For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa68039086"><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">SET</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">ROLE</span> <span class="token string">'admin'</span><span class="token punctuation">,</span> <span class="token string">'developer'</span> <span class="token keyword">TO</span> <span class="token string">'joe'</span>@<span class="token string">'10.0.0.1'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The host name part of the role name, if omitted, defaults to
   <code class="literal">
    '%'
   </code>
   .
  </p>
  <p>
   The clause following the
   <code class="literal">
    DEFAULT ROLE
   </code>
   keywords permits these values:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       NONE
      </code>
      : Set the default to
      <code class="literal">
       NONE
      </code>
      (no roles).
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       ALL
      </code>
      : Set the default to all roles granted
            to the account.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       <em class="replaceable">
        <code>
         role
        </code>
       </em>
       [,
       <em class="replaceable">
        <code>
         role
        </code>
       </em>
       ] ...
      </code>
      : Set the
            default to the named roles, which must exist and be granted
            to the account at the time
      <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
       <code class="literal">
        SET DEFAULT
            ROLE
       </code>
      </a>
      is executed.
     </p>
    </li>
   </ul>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
     <code class="literal">
      SET DEFAULT ROLE
     </code>
    </a>
    and
    <a class="link" href="set-role.html" title="15.7.1.11 SET ROLE Statement">
     <code class="literal">
      SET ROLE
          DEFAULT
     </code>
    </a>
    are different statements:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <a class="link" href="set-default-role.html" title="15.7.1.9 SET DEFAULT ROLE Statement">
        <code class="literal">
         SET DEFAULT ROLE
        </code>
       </a>
       defines
              which account roles to activate by default within account
              sessions.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="link" href="set-role.html" title="15.7.1.11 SET ROLE Statement">
        <code class="literal">
         SET ROLE
              DEFAULT
        </code>
       </a>
       sets the active roles within the current
              session to the current account default roles.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <p>
   For role usage examples, see
   <a class="xref" href="roles.html" title="8.2.10 Using Roles">
    Section 8.2.10, “Using Roles”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
