<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="create-role">
      </a>
      15.7.1.2 CREATE ROLE Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045174601760">
  </a>
  <a class="indexterm" name="idm46045174600688">
  </a>
  <a class="indexterm" name="idm46045174599200">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa14920297"><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">ROLE</span> <span class="token punctuation">[</span><span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</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 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></code></pre>
  </div>
  <p>
   <a class="link" href="create-role.html" title="15.7.1.2 CREATE ROLE Statement">
    <code class="literal">
     CREATE ROLE
    </code>
   </a>
   creates one or more
        roles, which are named collections of privileges. To use this
        statement, you must have the global
   <a class="link" href="privileges-provided.html#priv_create-role">
    <code class="literal">
     CREATE
        ROLE
    </code>
   </a>
   or
   <a class="link" href="privileges-provided.html#priv_create-user">
    <code class="literal">
     CREATE USER
    </code>
   </a>
   privilege. 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="create-role.html" title="15.7.1.2 CREATE ROLE Statement">
    <code class="literal">
     CREATE
        ROLE
    </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 role when created is locked, has no password, and is assigned
        the default authentication plugin. (These role attributes can be
        changed later with the
   <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
    <code class="literal">
     ALTER USER
    </code>
   </a>
   statement, by users who have the global
   <a class="link" href="privileges-provided.html#priv_create-user">
    <code class="literal">
     CREATE USER
    </code>
   </a>
   privilege.)
  </p>
  <p>
   <a class="link" href="create-role.html" title="15.7.1.2 CREATE ROLE Statement">
    <code class="literal">
     CREATE ROLE
    </code>
   </a>
   either succeeds for
        all named roles or rolls back and has no effect if any error
        occurs. By default, an error occurs if you try to create a role
        that already exists. If the
   <code class="literal">
    IF NOT EXISTS
   </code>
   clause is given, the statement produces a warning for each named
        role that already exists, 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 roles. If the
   <code class="literal">
    IF NOT EXISTS
   </code>
   clause is
        given, this includes even roles that already exist and were not
        created.
  </p>
  <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 language-sql"><div class="docs-select-all right" id="sa66257591"><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">ROLE</span> <span class="token string">'admin'</span><span class="token punctuation">,</span> <span class="token string">'developer'</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">ROLE</span> <span class="token string">'webapp'</span>@<span class="token string">'localhost'</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>
   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>
