<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="group-replication-functions-for-new-primary">
      </a>
      14.18.1.1 Function which Configures Group Replication Primary
     </h4>
    </div>
   </div>
  </div>
  <p>
   The following function enables you to set a member of a
          single-primary replication group to take over as the primary.
          The current primary becomes a read-only secondary, and the
          specified group member becomes the read-write primary. The
          function can be used on any member of a replication group
          running in single-primary mode. This function replaces the
          usual primary election process; see
   <a class="xref" href="group-replication-change-primary.html" title="20.5.1.1 Changing the Primary">
    Section 20.5.1.1, “Changing the Primary”
   </a>
   , for more
          information.
  </p>
  <p>
   If a standard source to replica replication channel is running
          on the existing primary member in addition to the Group
          Replication channels, you must stop that replication channel
          before you can change the primary member. You can identify the
          current primary using the
   <code class="literal">
    MEMBER_ROLE
   </code>
   column in the Performance Schema
   <a class="link" href="performance-schema-replication-group-members-table.html" title="29.12.11.16 The replication_group_members Table">
    <code class="literal">
     replication_group_members
    </code>
   </a>
   table.
  </p>
  <p>
   Any uncommitted transactions that the group is waiting on must
          be committed, rolled back, or terminated before the operation
          can complete. You can specify a timeout for transactions that
          are running when you use the function. For the timeout to
          work, all members of the group must be MySQL version 8.0.29 or
          newer.
  </p>
  <p>
   When the timeout expires, for any transactions that did not
          yet reach their commit phase, the client session is
          disconnected so that the transaction does not proceed.
          Transactions that reached their commit phase are allowed to
          complete. When you set a timeout, it also prevents new
          transactions starting on the primary from that point on.
          Explicitly defined transactions (with a
   <code class="literal">
    START
          TRANSACTION
   </code>
   or
   <code class="literal">
    BEGIN
   </code>
   statement)
          are subject to the timeout, disconnection, and incoming
          transaction blocking even if they do not modify any data. To
          allow inspection of the primary while the function is
          operating, single statements that do not modify data, as
          listed in
   <a class="xref" href="group-replication-configuring-consistency-guarantees.html#group-replication-nonblocking" title="Permitted Queries Under Consistency Rules">
    Permitted Queries Under Consistency Rules
   </a>
   , are
          permitted to proceed.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a name="function_group-replication-set-as-primary">
      </a>
      <a class="link" href="group-replication-functions-for-new-primary.html#function_group-replication-set-as-primary">
       <code class="literal">
        group_replication_set_as_primary()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045193977344">
     </a>
     <a class="indexterm" name="idm46045193976304">
     </a>
     <p>
      Appoints a specific member of the group as the new
              primary, overriding any election process.
     </p>
     <p>
      Syntax:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-clike"><div class="docs-select-all right" id="sa51465159"><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-clike">STRING <span class="token function">group_replication_set_as_primary</span><span class="token punctuation">(</span><em class="replaceable">member_uuid</em><span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">timeout</em><span class="token punctuation">]</span><span class="token punctuation">)</span></code></pre>
     </div>
     <p>
      Arguments:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <em class="replaceable">
          <code>
           member_uuid
          </code>
         </em>
         : A string
                  containing the UUID of the member of the group that
                  you want to become the new primary.
        </p>
       </li>
       <li class="listitem">
        <p>
         <em class="replaceable">
          <code>
           timeout
          </code>
         </em>
         : An integer
                  specifying a timeout in seconds for transactions that
                  are running on the existing primary when you use the
                  function. You can set a timeout from 0 seconds
                  (immediately) up to 3600 seconds (60 minutes). When
                  you set a timeout, new transactions cannot start on
                  the primary from that point on. There is no default
                  setting for the timeout, so if you do not set it,
                  there is no upper limit to the wait time, and new
                  transactions can start during that time.
        </p>
       </li>
      </ul>
     </div>
     <p>
      Return value:
     </p>
     <p>
      A string containing the result of the operation, for
              example whether it was successful or not.
     </p>
     <p>
      Example:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa35238076"><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">SELECT</span> group_replication_set_as_primary<span class="token punctuation">(</span>‘<span class="token number">00371d66</span><span class="token operator">-</span><span class="token number">3c45</span><span class="token operator">-</span><span class="token number">11ea</span><span class="token operator">-</span><span class="token number">804b</span><span class="token operator">-</span><span class="token number">080027337932</span>’<span class="token punctuation">,</span> <span class="token number">300</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      This function waits for all ongoing transactions and DML
              operations to finish before electing the new primary. In
              MySQL 8.4, it also waits for the completion
              of any ongoing DDL statements such as
      <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
       <code class="literal">
        ALTER TABLE
       </code>
      </a>
      . Operations
              that are considered DDL statements for this purpose are
              listed here:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <a class="link" href="alter-database.html" title="15.1.2 ALTER DATABASE Statement">
          <code class="literal">
           ALTER DATABASE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-function.html" title="15.1.4 ALTER FUNCTION Statement">
          <code class="literal">
           ALTER FUNCTION
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-instance.html" title="15.1.5 ALTER INSTANCE Statement">
          <code class="literal">
           ALTER INSTANCE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-procedure.html" title="15.1.7 ALTER PROCEDURE Statement">
          <code class="literal">
           ALTER PROCEDURE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-server.html" title="15.1.8 ALTER SERVER Statement">
          <code class="literal">
           ALTER SERVER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <code class="literal">
          ALTER TABLE
         </code>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-tablespace.html" title="15.1.10 ALTER TABLESPACE Statement">
          <code class="literal">
           ALTER TABLESPACE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
          <code class="literal">
           ALTER USER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-view.html" title="15.1.11 ALTER VIEW Statement">
          <code class="literal">
           ALTER VIEW
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
          <code class="literal">
           ANALYZE TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="cache-index.html" title="15.7.8.2 CACHE INDEX Statement">
          <code class="literal">
           CACHE INDEX
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
          <code class="literal">
           CHECK TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
          <code class="literal">
           CREATE DATABASE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-function.html" title="15.1.14 CREATE FUNCTION Statement">
          <code class="literal">
           CREATE FUNCTION
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-index.html" title="15.1.15 CREATE INDEX Statement">
          <code class="literal">
           CREATE INDEX
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-role.html" title="15.7.1.2 CREATE ROLE Statement">
          <code class="literal">
           CREATE ROLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-procedure.html" title="15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements">
          <code class="literal">
           CREATE PROCEDURE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-server.html" title="15.1.18 CREATE SERVER Statement">
          <code class="literal">
           CREATE SERVER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-spatial-reference-system.html" title="15.1.19 CREATE SPATIAL REFERENCE SYSTEM Statement">
          <code class="literal">
           CREATE SPATIAL REFERENCE
                  SYSTEM
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
          <code class="literal">
           CREATE TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-tablespace.html" title="15.1.21 CREATE TABLESPACE Statement">
          <code class="literal">
           CREATE TABLESPACE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-trigger.html" title="15.1.22 CREATE TRIGGER Statement">
          <code class="literal">
           CREATE TRIGGER
          </code>
         </a>
        </p>
       </li>
       <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>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
          <code class="literal">
           CREATE VIEW
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-database.html" title="15.1.24 DROP DATABASE Statement">
          <code class="literal">
           DROP DATABASE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-function.html" title="15.1.26 DROP FUNCTION Statement">
          <code class="literal">
           DROP FUNCTION
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-index.html" title="15.1.27 DROP INDEX Statement">
          <code class="literal">
           DROP INDEX
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-procedure.html" title="15.1.29 DROP PROCEDURE and DROP FUNCTION Statements">
          <code class="literal">
           DROP PROCEDURE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-role.html" title="15.7.1.4 DROP ROLE Statement">
          <code class="literal">
           DROP ROLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-server.html" title="15.1.30 DROP SERVER Statement">
          <code class="literal">
           DROP SERVER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-spatial-reference-system.html" title="15.1.31 DROP SPATIAL REFERENCE SYSTEM Statement">
          <code class="literal">
           DROP SPATIAL REFERENCE
                  SYSTEM
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
          <code class="literal">
           DROP TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-tablespace.html" title="15.1.33 DROP TABLESPACE Statement">
          <code class="literal">
           DROP TABLESPACE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-trigger.html" title="15.1.34 DROP TRIGGER Statement">
          <code class="literal">
           DROP TRIGGER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
          <code class="literal">
           DROP USER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="drop-view.html" title="15.1.35 DROP VIEW Statement">
          <code class="literal">
           DROP VIEW
          </code>
         </a>
        </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>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="load-index.html" title="15.7.8.5 LOAD INDEX INTO CACHE Statement">
          <code class="literal">
           LOAD INDEX
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
          <code class="literal">
           OPTIMIZE TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="rename-table.html" title="15.1.36 RENAME TABLE Statement">
          <code class="literal">
           RENAME TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
          <code class="literal">
           REPAIR TABLE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
          <code class="literal">
           REVOKE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
          <code class="literal">
           TRUNCATE TABLE
          </code>
         </a>
        </p>
       </li>
      </ul>
     </div>
     <p>
      This also includes any open cursors (see
      <a class="xref" href="cursors.html" title="15.6.6 Cursors">
       Section 15.6.6, “Cursors”
      </a>
      ).
     </p>
     <p>
      For more information, see
      <a class="xref" href="group-replication-change-primary.html" title="20.5.1.1 Changing the Primary">
       Section 20.5.1.1, “Changing the Primary”
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
