url
stringlengths
45
122
content
stringlengths
380
3.07M
https://dev.mysql.com/doc/refman/8.4/en/sql-statements.html
<div id="docs-body"> <div class="chapter"> <div class="titlepage"> <div> <div> <h1 class="title"> <a name="sql-statements"> </a> Chapter 15 SQL Statements </h1> </div> </div> </div> <div class="toc"> <p> <b> Table of Contents </b> </p> <dl class="toc"> <dt> <span class="section"> <a href="sql-data-definition-statements.html"> 15.1 Data Definition Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="atomic-ddl.html"> 15.1.1 Atomic Data Definition Statement Support </a> </span> </dt> <dt> <span class="section"> <a href="alter-database.html"> 15.1.2 ALTER DATABASE Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-event.html"> 15.1.3 ALTER EVENT Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-function.html"> 15.1.4 ALTER FUNCTION Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-instance.html"> 15.1.5 ALTER INSTANCE Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-logfile-group.html"> 15.1.6 ALTER LOGFILE GROUP Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-procedure.html"> 15.1.7 ALTER PROCEDURE Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-server.html"> 15.1.8 ALTER SERVER Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-table.html"> 15.1.9 ALTER TABLE Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-tablespace.html"> 15.1.10 ALTER TABLESPACE Statement </a> </span> </dt> <dt> <span class="section"> <a href="alter-view.html"> 15.1.11 ALTER VIEW Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-database.html"> 15.1.12 CREATE DATABASE Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-event.html"> 15.1.13 CREATE EVENT Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-function.html"> 15.1.14 CREATE FUNCTION Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-index.html"> 15.1.15 CREATE INDEX Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-logfile-group.html"> 15.1.16 CREATE LOGFILE GROUP Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-procedure.html"> 15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements </a> </span> </dt> <dt> <span class="section"> <a href="create-server.html"> 15.1.18 CREATE SERVER Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-spatial-reference-system.html"> 15.1.19 CREATE SPATIAL REFERENCE SYSTEM Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-table.html"> 15.1.20 CREATE TABLE Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-tablespace.html"> 15.1.21 CREATE TABLESPACE Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-trigger.html"> 15.1.22 CREATE TRIGGER Statement </a> </span> </dt> <dt> <span class="section"> <a href="create-view.html"> 15.1.23 CREATE VIEW Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-database.html"> 15.1.24 DROP DATABASE Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-event.html"> 15.1.25 DROP EVENT Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-function.html"> 15.1.26 DROP FUNCTION Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-index.html"> 15.1.27 DROP INDEX Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-logfile-group.html"> 15.1.28 DROP LOGFILE GROUP Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-procedure.html"> 15.1.29 DROP PROCEDURE and DROP FUNCTION Statements </a> </span> </dt> <dt> <span class="section"> <a href="drop-server.html"> 15.1.30 DROP SERVER Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-spatial-reference-system.html"> 15.1.31 DROP SPATIAL REFERENCE SYSTEM Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-table.html"> 15.1.32 DROP TABLE Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-tablespace.html"> 15.1.33 DROP TABLESPACE Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-trigger.html"> 15.1.34 DROP TRIGGER Statement </a> </span> </dt> <dt> <span class="section"> <a href="drop-view.html"> 15.1.35 DROP VIEW Statement </a> </span> </dt> <dt> <span class="section"> <a href="rename-table.html"> 15.1.36 RENAME TABLE Statement </a> </span> </dt> <dt> <span class="section"> <a href="truncate-table.html"> 15.1.37 TRUNCATE TABLE Statement </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-data-manipulation-statements.html"> 15.2 Data Manipulation Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="call.html"> 15.2.1 CALL Statement </a> </span> </dt> <dt> <span class="section"> <a href="delete.html"> 15.2.2 DELETE Statement </a> </span> </dt> <dt> <span class="section"> <a href="do.html"> 15.2.3 DO Statement </a> </span> </dt> <dt> <span class="section"> <a href="except.html"> 15.2.4 EXCEPT Clause </a> </span> </dt> <dt> <span class="section"> <a href="handler.html"> 15.2.5 HANDLER Statement </a> </span> </dt> <dt> <span class="section"> <a href="import-table.html"> 15.2.6 IMPORT TABLE Statement </a> </span> </dt> <dt> <span class="section"> <a href="insert.html"> 15.2.7 INSERT Statement </a> </span> </dt> <dt> <span class="section"> <a href="intersect.html"> 15.2.8 INTERSECT Clause </a> </span> </dt> <dt> <span class="section"> <a href="load-data.html"> 15.2.9 LOAD DATA Statement </a> </span> </dt> <dt> <span class="section"> <a href="load-xml.html"> 15.2.10 LOAD XML Statement </a> </span> </dt> <dt> <span class="section"> <a href="parenthesized-query-expressions.html"> 15.2.11 Parenthesized Query Expressions </a> </span> </dt> <dt> <span class="section"> <a href="replace.html"> 15.2.12 REPLACE Statement </a> </span> </dt> <dt> <span class="section"> <a href="select.html"> 15.2.13 SELECT Statement </a> </span> </dt> <dt> <span class="section"> <a href="set-operations.html"> 15.2.14 Set Operations with UNION, INTERSECT, and EXCEPT </a> </span> </dt> <dt> <span class="section"> <a href="subqueries.html"> 15.2.15 Subqueries </a> </span> </dt> <dt> <span class="section"> <a href="table.html"> 15.2.16 TABLE Statement </a> </span> </dt> <dt> <span class="section"> <a href="update.html"> 15.2.17 UPDATE Statement </a> </span> </dt> <dt> <span class="section"> <a href="union.html"> 15.2.18 UNION Clause </a> </span> </dt> <dt> <span class="section"> <a href="values.html"> 15.2.19 VALUES Statement </a> </span> </dt> <dt> <span class="section"> <a href="with.html"> 15.2.20 WITH (Common Table Expressions) </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-transactional-statements.html"> 15.3 Transactional and Locking Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="commit.html"> 15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements </a> </span> </dt> <dt> <span class="section"> <a href="cannot-roll-back.html"> 15.3.2 Statements That Cannot Be Rolled Back </a> </span> </dt> <dt> <span class="section"> <a href="implicit-commit.html"> 15.3.3 Statements That Cause an Implicit Commit </a> </span> </dt> <dt> <span class="section"> <a href="savepoint.html"> 15.3.4 SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements </a> </span> </dt> <dt> <span class="section"> <a href="lock-instance-for-backup.html"> 15.3.5 LOCK INSTANCE FOR BACKUP and UNLOCK INSTANCE Statements </a> </span> </dt> <dt> <span class="section"> <a href="lock-tables.html"> 15.3.6 LOCK TABLES and UNLOCK TABLES Statements </a> </span> </dt> <dt> <span class="section"> <a href="set-transaction.html"> 15.3.7 SET TRANSACTION Statement </a> </span> </dt> <dt> <span class="section"> <a href="xa.html"> 15.3.8 XA Transactions </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-replication-statements.html"> 15.4 Replication Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="replication-statements-source.html"> 15.4.1 SQL Statements for Controlling Source Servers </a> </span> </dt> <dt> <span class="section"> <a href="replication-statements-replica.html"> 15.4.2 SQL Statements for Controlling Replica Servers </a> </span> </dt> <dt> <span class="section"> <a href="replication-statements-group.html"> 15.4.3 SQL Statements for Controlling Group Replication </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-prepared-statements.html"> 15.5 Prepared Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="prepare.html"> 15.5.1 PREPARE Statement </a> </span> </dt> <dt> <span class="section"> <a href="execute.html"> 15.5.2 EXECUTE Statement </a> </span> </dt> <dt> <span class="section"> <a href="deallocate-prepare.html"> 15.5.3 DEALLOCATE PREPARE Statement </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-compound-statements.html"> 15.6 Compound Statement Syntax </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="begin-end.html"> 15.6.1 BEGIN ... END Compound Statement </a> </span> </dt> <dt> <span class="section"> <a href="statement-labels.html"> 15.6.2 Statement Labels </a> </span> </dt> <dt> <span class="section"> <a href="declare.html"> 15.6.3 DECLARE Statement </a> </span> </dt> <dt> <span class="section"> <a href="stored-program-variables.html"> 15.6.4 Variables in Stored Programs </a> </span> </dt> <dt> <span class="section"> <a href="flow-control-statements.html"> 15.6.5 Flow Control Statements </a> </span> </dt> <dt> <span class="section"> <a href="cursors.html"> 15.6.6 Cursors </a> </span> </dt> <dt> <span class="section"> <a href="condition-handling.html"> 15.6.7 Condition Handling </a> </span> </dt> <dt> <span class="section"> <a href="condition-handling-restrictions.html"> 15.6.8 Restrictions on Condition Handling </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-server-administration-statements.html"> 15.7 Database Administration Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="account-management-statements.html"> 15.7.1 Account Management Statements </a> </span> </dt> <dt> <span class="section"> <a href="resource-group-statements.html"> 15.7.2 Resource Group Management Statements </a> </span> </dt> <dt> <span class="section"> <a href="table-maintenance-statements.html"> 15.7.3 Table Maintenance Statements </a> </span> </dt> <dt> <span class="section"> <a href="component-statements.html"> 15.7.4 Component, Plugin, and Loadable Function Statements </a> </span> </dt> <dt> <span class="section"> <a href="clone.html"> 15.7.5 CLONE Statement </a> </span> </dt> <dt> <span class="section"> <a href="set-statement.html"> 15.7.6 SET Statements </a> </span> </dt> <dt> <span class="section"> <a href="show.html"> 15.7.7 SHOW Statements </a> </span> </dt> <dt> <span class="section"> <a href="other-administrative-statements.html"> 15.7.8 Other Administrative Statements </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="sql-utility-statements.html"> 15.8 Utility Statements </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="describe.html"> 15.8.1 DESCRIBE Statement </a> </span> </dt> <dt> <span class="section"> <a href="explain.html"> 15.8.2 EXPLAIN Statement </a> </span> </dt> <dt> <span class="section"> <a href="help.html"> 15.8.3 HELP Statement </a> </span> </dt> <dt> <span class="section"> <a href="use.html"> 15.8.4 USE Statement </a> </span> </dt> </dl> </dd> </dl> </div> <p> This chapter describes the syntax for the <a class="link" href="glossary.html#glos_sql" title="SQL"> SQL </a> statements supported by MySQL. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-features-mysqldb.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-features-mysqldb"> </a> 19.5.1.22 Replication of the mysql System Schema </h4> </div> </div> </div> <a class="indexterm" name="idm46045135275776"> </a> <a class="indexterm" name="idm46045135274272"> </a> <a class="indexterm" name="idm46045135272784"> </a> <a class="indexterm" name="idm46045135271296"> </a> <p> Data modification statements made to tables in the <code class="literal"> mysql </code> schema are replicated according to the value of <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> ; if this value is <code class="literal"> MIXED </code> , these statements are replicated using row-based format. However, statements that would normally update this information indirectly—such <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement"> <code class="literal"> GRANT </code> </a> , <a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement"> <code class="literal"> REVOKE </code> </a> , and statements manipulating triggers, stored routines, and views—are replicated to replicas using statement-based replication. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/password-management.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="password-management"> </a> 8.2.15 Password Management </h3> </div> </div> </div> <a class="indexterm" name="idm46045248689824"> </a> <p> MySQL supports these password-management capabilities: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Password expiration, to require passwords to be changed periodically. </p> </li> <li class="listitem"> <p> Password reuse restrictions, to prevent old passwords from being chosen again. </p> </li> <li class="listitem"> <p> Password verification, to require that password changes also specify the current password to be replaced. </p> </li> <li class="listitem"> <p> Dual passwords, to enable clients to connect using either a primary or secondary password. </p> </li> <li class="listitem"> <p> Password strength assessment, to require strong passwords. </p> </li> <li class="listitem"> <p> Random password generation, as an alternative to requiring explicit administrator-specified literal passwords. </p> </li> <li class="listitem"> <p> Password failure tracking, to enable temporary account locking after too many consecutive incorrect-password login failures. </p> </li> </ul> </div> <p> The following sections describe these capabilities, except password strength assessment, which is implemented using the <code class="literal"> validate_password </code> component and is described in <a class="xref" href="validate-password.html" title="8.4.3 The Password Validation Component"> Section 8.4.3, “The Password Validation Component” </a> . </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="password-management.html#internal-versus-external-credentials" title="Internal Versus External Credentials Storage"> Internal Versus External Credentials Storage </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="password-management.html#password-expiration-policy" title="Password Expiration Policy"> Password Expiration Policy </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="password-management.html#password-reuse-policy" title="Password Reuse Policy"> Password Reuse Policy </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="password-management.html#password-reverification-policy" title="Password Verification-Required Policy"> Password Verification-Required Policy </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="password-management.html#dual-passwords" title="Dual Password Support"> Dual Password Support </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="password-management.html#random-password-generation" title="Random Password Generation"> Random Password Generation </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="password-management.html#failed-login-tracking" title="Failed-Login Tracking and Temporary Account Locking"> Failed-Login Tracking and Temporary Account Locking </a> </p> </li> </ul> </div> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> MySQL implements password-management capabilities using tables in the <code class="literal"> mysql </code> system database. If you upgrade MySQL from an earlier version, your system tables might not be up to date. In that case, the server writes messages similar to these to the error log during the startup process (the exact numbers may vary): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa66066346"><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-none">[ERROR] Column count of mysql.user is wrong. Expected 49, found 47. The table is probably corrupted [Warning] ACL table mysql.password_history missing. Some operations may fail.</code></pre> </div> <p> To correct the issue, perform the MySQL upgrade procedure. See <a class="xref" href="upgrading.html" title="Chapter 3 Upgrading MySQL"> Chapter 3, <i> Upgrading MySQL </i> </a> . Until this is done, <span class="emphasis"> <em> password changes are not possible. </em> </span> </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="internal-versus-external-credentials"> </a> Internal Versus External Credentials Storage </h4> </div> </div> </div> <p> Some authentication plugins store account credentials internally to MySQL, in the <code class="literal"> mysql.user </code> system table: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> caching_sha2_password </code> </p> </li> <li class="listitem"> <p> <code class="literal"> mysql_native_password </code> (deprecated) </p> </li> <li class="listitem"> <p> <code class="literal"> sha256_password </code> (deprecated) </p> </li> </ul> </div> <p> Most discussion in this section applies to such authentication plugins because most password-management capabilities described here are based on internal credentials storage handled by MySQL itself. Other authentication plugins store account credentials externally to MySQL. For accounts that use plugins that perform authentication against an external credentials system, password management must be handled externally against that system as well. </p> <p> The exception is that the options for failed-login tracking and temporary account locking apply to all accounts, not just accounts that use internal credentials storage, because MySQL is able to assess the status of login attempts for any account no matter whether it uses internal or external credentials storage. </p> <p> For information about individual authentication plugins, see <a class="xref" href="authentication-plugins.html" title="8.4.1 Authentication Plugins"> Section 8.4.1, “Authentication Plugins” </a> . </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="password-expiration-policy"> </a> Password Expiration Policy </h4> </div> </div> </div> <p> MySQL enables database administrators to expire account passwords manually, and to establish a policy for automatic password expiration. Expiration policy can be established globally, and individual accounts can be set to either defer to the global policy or override the global policy with specific per-account behavior. </p> <p> To expire an account password manually, use the <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa36137687"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span><span class="token punctuation">;</span></code></pre> </div> <p> This operation marks the password expired in the corresponding row in the <code class="literal"> mysql.user </code> system table. </p> <p> Password expiration according to policy is automatic and is based on password age, which for a given account is assessed from the date and time of its most recent password change. The <code class="literal"> mysql.user </code> system table indicates for each account when its password was last changed, and the server automatically treats the password as expired at client connection time if its age is greater than its permitted lifetime. This works with no explicit manual password expiration. </p> <p> To establish automatic password-expiration policy globally, use the <a class="link" href="server-system-variables.html#sysvar_default_password_lifetime"> <code class="literal"> default_password_lifetime </code> </a> system variable. Its default value is 0, which disables automatic password expiration. If the value of <a class="link" href="server-system-variables.html#sysvar_default_password_lifetime"> <code class="literal"> default_password_lifetime </code> </a> is a positive integer <em class="replaceable"> <code> N </code> </em> , it indicates the permitted password lifetime, such that passwords must be changed every <em class="replaceable"> <code> N </code> </em> days. </p> <p> Examples: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> To establish a global policy that passwords have a lifetime of approximately six months, start the server with these lines in a server <code class="filename"> my.cnf </code> file: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa58424907"><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-ini"><span class="token selector">[mysqld]</span> <span class="token constant">default_password_lifetime</span><span class="token attr-value"><span class="token punctuation">=</span>180</span></code></pre> </div> </li> <li class="listitem"> <p> To establish a global policy such that passwords never expire, set <a class="link" href="server-system-variables.html#sysvar_default_password_lifetime"> <code class="literal"> default_password_lifetime </code> </a> to 0: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa18266153"><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-ini"><span class="token selector">[mysqld]</span> <span class="token constant">default_password_lifetime</span><span class="token attr-value"><span class="token punctuation">=</span>0</span></code></pre> </div> </li> <li class="listitem"> <p> <a class="link" href="server-system-variables.html#sysvar_default_password_lifetime"> <code class="literal"> default_password_lifetime </code> </a> can also be set and persisted at runtime: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21654613"><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">PERSIST</span> default_password_lifetime <span class="token operator">=</span> <span class="token number">180</span><span class="token punctuation">;</span> <span class="token keyword">SET</span> <span class="token keyword">PERSIST</span> default_password_lifetime <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span></code></pre> </div> <p> <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> <code class="literal"> SET PERSIST </code> </a> sets a value for the running MySQL instance. It also saves the value to carry over to subsequent server restarts; see <a class="xref" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> Section 15.7.6.1, “SET Syntax for Variable Assignment” </a> . To change the value for the running MySQL instance without having it carry over to subsequent restarts, use the <code class="literal"> GLOBAL </code> keyword rather than <code class="literal"> PERSIST </code> . </p> </li> </ul> </div> <p> The global password-expiration policy applies to all accounts that have not been set to override it. To establish policy for individual accounts, use the <code class="literal"> PASSWORD EXPIRE </code> option of the <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="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statements. See <a class="xref" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> Section 15.7.1.3, “CREATE USER Statement” </a> , and <a class="xref" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> Section 15.7.1.1, “ALTER USER Statement” </a> . </p> <p> Example account-specific statements: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Require the password to be changed every 90 days: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45495337"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">INTERVAL</span> <span class="token number">90</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">INTERVAL</span> <span class="token number">90</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span></code></pre> </div> <p> This expiration option overrides the global policy for all accounts named by the statement. </p> </li> <li class="listitem"> <p> Disable password expiration: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66608953"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">NEVER</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">NEVER</span><span class="token punctuation">;</span></code></pre> </div> <p> This expiration option overrides the global policy for all accounts named by the statement. </p> </li> <li class="listitem"> <p> Defer to the global expiration policy for all accounts named by the statement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33743257"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> When a client successfully connects, the server determines whether the account password has expired: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The server checks whether the password has been manually expired. </p> </li> <li class="listitem"> <p> Otherwise, the server checks whether the password age is greater than its permitted lifetime according to the automatic password expiration policy. If so, the server considers the password expired. </p> </li> </ul> </div> <p> If the password is expired (whether manually or automatically), the server either disconnects the client or restricts the operations permitted to it (see <a class="xref" href="expired-password-handling.html" title="8.2.16 Server Handling of Expired Passwords"> Section 8.2.16, “Server Handling of Expired Passwords” </a> ). Operations performed by a restricted client result in an error until the user establishes a new account password: </p> <a class="indexterm" name="idm46045248615248"> </a> <a class="indexterm" name="idm46045248614208"> </a> <a class="indexterm" name="idm46045248612720"> </a> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa87304117"><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">SELECT</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token output">ERROR 1820 (HY000)<span class="token punctuation">:</span> You must reset your password using ALTER USER statement before executing this statement. </span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</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 output">Query OK, 0 rows affected (0.01 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">1</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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token output">1 row in set (0.00 sec)</span></code></pre> </div> <p> After the client resets the password, the server restores normal access for the session, as well as for subsequent connections that use the account. It is also possible for an administrative user to reset the account password, but any existing restricted sessions for that account remain restricted. A client using the account must disconnect and reconnect before statements can be executed successfully. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Although it is possible to <span class="quote"> “ <span class="quote"> reset </span> ” </span> an expired password by setting it to its current value, it is preferable, as a matter of good policy, to choose a different password. DBAs can enforce non-reuse by establishing an appropriate password-reuse policy. See <a class="xref" href="password-management.html#password-reuse-policy" title="Password Reuse Policy"> Password Reuse Policy </a> . </p> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="password-reuse-policy"> </a> Password Reuse Policy </h4> </div> </div> </div> <p> MySQL enables restrictions to be placed on reuse of previous passwords. Reuse restrictions can be established based on number of password changes, time elapsed, or both. Reuse policy can be established globally, and individual accounts can be set to either defer to the global policy or override the global policy with specific per-account behavior. </p> <p> The password history for an account consists of passwords it has been assigned in the past. MySQL can restrict new passwords from being chosen from this history: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If an account is restricted on the basis of number of password changes, a new password cannot be chosen from a specified number of the most recent passwords. For example, if the minimum number of password changes is set to 3, a new password cannot be the same as any of the most recent 3 passwords. </p> </li> <li class="listitem"> <p> If an account is restricted based on time elapsed, a new password cannot be chosen from passwords in the history that are newer than a specified number of days. For example, if the password reuse interval is set to 60, a new password must not be among those previously chosen within the last 60 days. </p> </li> </ul> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> The empty password does not count in the password history and is subject to reuse at any time. </p> </div> <p> To establish password-reuse policy globally, use the <a class="link" href="server-system-variables.html#sysvar_password_history"> <code class="literal"> password_history </code> </a> and <a class="link" href="server-system-variables.html#sysvar_password_reuse_interval"> <code class="literal"> password_reuse_interval </code> </a> system variables. </p> <p> Examples: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> To prohibit reusing any of the last 6 passwords or passwords newer than 365 days, put these lines in the server <code class="filename"> my.cnf </code> file: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa46198965"><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-ini"><span class="token selector">[mysqld]</span> <span class="token constant">password_history</span><span class="token attr-value"><span class="token punctuation">=</span>6</span> <span class="token constant">password_reuse_interval</span><span class="token attr-value"><span class="token punctuation">=</span>365</span></code></pre> </div> </li> <li class="listitem"> <p> To set and persist the variables at runtime, use statements like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa25580274"><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-ini">SET PERSIST password_history <span class="token attr-value"><span class="token punctuation">=</span> 6;</span> SET PERSIST password_reuse_interval <span class="token attr-value"><span class="token punctuation">=</span> 365;</span></code></pre> </div> <p> <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> <code class="literal"> SET PERSIST </code> </a> sets a value for the running MySQL instance. It also saves the value to carry over to subsequent server restarts; see <a class="xref" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> Section 15.7.6.1, “SET Syntax for Variable Assignment” </a> . To change the value for the running MySQL instance without having it carry over to subsequent restarts, use the <code class="literal"> GLOBAL </code> keyword rather than <code class="literal"> PERSIST </code> . </p> </li> </ul> </div> <p> The global password-reuse policy applies to all accounts that have not been set to override it. To establish policy for individual accounts, use the <code class="literal"> PASSWORD HISTORY </code> and <code class="literal"> PASSWORD REUSE INTERVAL </code> options of the <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="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statements. See <a class="xref" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> Section 15.7.1.3, “CREATE USER Statement” </a> , and <a class="xref" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> Section 15.7.1.1, “ALTER USER Statement” </a> . </p> <p> Example account-specific statements: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Require a minimum of 5 password changes before permitting reuse: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25412577"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token number">5</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token number">5</span><span class="token punctuation">;</span></code></pre> </div> <p> This history-length option overrides the global policy for all accounts named by the statement. </p> </li> <li class="listitem"> <p> Require a minimum of 365 days elapsed before permitting reuse: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa75558374"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token number">365</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token number">365</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span></code></pre> </div> <p> This time-elapsed option overrides the global policy for all accounts named by the statement. </p> </li> <li class="listitem"> <p> To combine both types of reuse restrictions, use <code class="literal"> PASSWORD HISTORY </code> and <code class="literal"> PASSWORD REUSE INTERVAL </code> together: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86972695"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token number">5</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token number">365</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token number">5</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token number">365</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span></code></pre> </div> <p> These options override both global policy reuse restrictions for all accounts named by the statement. </p> </li> <li class="listitem"> <p> Defer to the global policy for both types of reuse restrictions: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa73213764"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="password-reverification-policy"> </a> Password Verification-Required Policy </h4> </div> </div> </div> <p> It is possible to require that attempts to change an account password be verified by specifying the current password to be replaced. This enables DBAs to prevent users from changing a password without proving that they know the current password. Such changes could otherwise occur, for example, if one user walks away from a terminal session temporarily without logging out, and a malicious user uses the session to change the original user's MySQL password. This can have unfortunate consequences: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The original user becomes unable to access MySQL until the account password is reset by an administrator. </p> </li> <li class="listitem"> <p> Until the password reset occurs, the malicious user can access MySQL with the benign user's changed credentials. </p> </li> </ul> </div> <p> Password-verification policy can be established globally, and individual accounts can be set to either defer to the global policy or override the global policy with specific per-account behavior. </p> <p> For each account, its <code class="literal"> mysql.user </code> row indicates whether there is an account-specific setting requiring verification of the current password for password change attempts. The setting is established by the <code class="literal"> PASSWORD REQUIRE </code> option of the <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="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statements: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If the account setting is <code class="literal"> PASSWORD REQUIRE CURRENT </code> , password changes must specify the current password. </p> </li> <li class="listitem"> <p> If the account setting is <code class="literal"> PASSWORD REQUIRE CURRENT OPTIONAL </code> , password changes may but need not specify the current password. </p> </li> <li class="listitem"> <p> If the account setting is <code class="literal"> PASSWORD REQUIRE CURRENT DEFAULT </code> , the <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> system variable determines the verification-required policy for the account: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> If <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> is enabled, password changes must specify the current password. </p> </li> <li class="listitem"> <p> If <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> is disabled, password changes may but need not specify the current password. </p> </li> </ul> </div> </li> </ul> </div> <p> In other words, if the account setting is not <code class="literal"> PASSWORD REQUIRE CURRENT DEFAULT </code> , the account setting takes precedence over the global policy established by the <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> system variable. Otherwise, the account defers to the <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> setting. </p> <p> By default, password verification is optional: <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> is disabled and accounts created with no <code class="literal"> PASSWORD REQUIRE </code> option default to <code class="literal"> PASSWORD REQUIRE CURRENT DEFAULT </code> . </p> <p> The following table shows how per-account settings interact with <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> system variable values to determine account password verification-required policy. </p> <div class="table"> <a name="password-verification-policy-table"> </a> <p class="title"> <b> Table 8.10 Password-Verification Policy </b> </p> <div class="table-contents"> <table summary="Interaction of mysql.user table and password_require_current system variable for password-verification policy."> <colgroup> <col style="width: 40%"/> <col style="width: 30%"/> <col style="width: 30%"/> </colgroup> <thead> <tr> <th scope="col"> Per-Account Setting </th> <th scope="col"> password_require_current System Variable </th> <th scope="col"> Password Changes Require Current Password? </th> </tr> </thead> <tbody> <tr> <th scope="row"> <code class="literal"> PASSWORD REQUIRE CURRENT </code> </th> <td> <code class="literal"> OFF </code> </td> <td> Yes </td> </tr> <tr> <th scope="row"> <code class="literal"> PASSWORD REQUIRE CURRENT </code> </th> <td> <code class="literal"> ON </code> </td> <td> Yes </td> </tr> <tr> <th scope="row"> <code class="literal"> PASSWORD REQUIRE CURRENT OPTIONAL </code> </th> <td> <code class="literal"> OFF </code> </td> <td> No </td> </tr> <tr> <th scope="row"> <code class="literal"> PASSWORD REQUIRE CURRENT OPTIONAL </code> </th> <td> <code class="literal"> ON </code> </td> <td> No </td> </tr> <tr> <th scope="row"> <code class="literal"> PASSWORD REQUIRE CURRENT DEFAULT </code> </th> <td> <code class="literal"> OFF </code> </td> <td> No </td> </tr> <tr> <th scope="row"> <code class="literal"> PASSWORD REQUIRE CURRENT DEFAULT </code> </th> <td> <code class="literal"> ON </code> </td> <td> Yes </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Privileged users can change any account password without specifying the current password, regardless of the verification-required policy. A privileged user is one who has 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 database. </p> </div> <p> To establish password-verification policy globally, use the <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> system variable. Its default value is <code class="literal"> OFF </code> , so it is not required that account password changes specify the current password. </p> <p> Examples: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> To establish a global policy that password changes must specify the current password, start the server with these lines in a server <code class="filename"> my.cnf </code> file: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa77462526"><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-ini"><span class="token selector">[mysqld]</span> <span class="token constant">password_require_current</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span></code></pre> </div> </li> <li class="listitem"> <p> To set and persist <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> at runtime, use a statement such as one of these: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25613991"><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">PERSIST</span> password_require_current <span class="token operator">=</span> <span class="token keyword">ON</span><span class="token punctuation">;</span> <span class="token keyword">SET</span> <span class="token keyword">PERSIST</span> password_require_current <span class="token operator">=</span> <span class="token keyword">OFF</span><span class="token punctuation">;</span></code></pre> </div> <p> <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> <code class="literal"> SET PERSIST </code> </a> sets a value for the running MySQL instance. It also saves the value to carry over to subsequent server restarts; see <a class="xref" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> Section 15.7.6.1, “SET Syntax for Variable Assignment” </a> . To change the value for the running MySQL instance without having it carry over to subsequent restarts, use the <code class="literal"> GLOBAL </code> keyword rather than <code class="literal"> PERSIST </code> . </p> </li> </ul> </div> <p> The global password verification-required policy applies to all accounts that have not been set to override it. To establish policy for individual accounts, use the <code class="literal"> PASSWORD REQUIRE </code> options of the <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="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statements. See <a class="xref" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> Section 15.7.1.3, “CREATE USER Statement” </a> , and <a class="xref" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> Section 15.7.1.1, “ALTER USER Statement” </a> . </p> <p> Example account-specific statements: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Require that password changes specify the current password: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66191533"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span><span class="token punctuation">;</span></code></pre> </div> <p> This verification option overrides the global policy for all accounts named by the statement. </p> </li> <li class="listitem"> <p> Do not require that password changes specify the current password (the current password may but need not be given): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68197266"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token keyword">OPTIONAL</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token keyword">OPTIONAL</span><span class="token punctuation">;</span></code></pre> </div> <p> This verification option overrides the global policy for all accounts named by the statement. </p> </li> <li class="listitem"> <p> Defer to the global password verification-required policy for all accounts named by the statement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa71463880"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> Verification of the current password comes into play when a user changes a password using the <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> or <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> statement. The examples use <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> , which is preferred over <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> , but the principles described here are the same for both statements. </p> <p> In password-change statements, a <code class="literal"> REPLACE </code> clause specifies the current password to be replaced. Examples: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Change the current user's password: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa62807784"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token keyword">REPLACE</span> <span class="token string">'<em class="replaceable">current_auth_string</em>'</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> Change a named user's password: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85829751"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</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">auth_string</em>'</span> <span class="token keyword">REPLACE</span> <span class="token string">'<em class="replaceable">current_auth_string</em>'</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> Change a named user's authentication plugin and password: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46411606"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> caching_sha2_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token keyword">REPLACE</span> <span class="token string">'<em class="replaceable">current_auth_string</em>'</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> The <code class="literal"> REPLACE </code> clause works like this: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> REPLACE </code> must be given if password changes for the account are required to specify the current password, as verification that the user attempting to make the change actually knows the current password. </p> </li> <li class="listitem"> <p> <code class="literal"> REPLACE </code> is optional if password changes for the account may but need not specify the current password. </p> </li> <li class="listitem"> <p> If <code class="literal"> REPLACE </code> is specified, it must specify the correct current password, or an error occurs. This is true even if <code class="literal"> REPLACE </code> is optional. </p> </li> <li class="listitem"> <p> <code class="literal"> REPLACE </code> can be specified only when changing the account password for the current user. (This means that in the examples just shown, the statements that explicitly name the account for <code class="literal"> jeffrey </code> fail unless the current user is <code class="literal"> jeffrey </code> .) This is true even if the change is attempted for another user by a privileged user; however, such a user can change any password without specifying <code class="literal"> REPLACE </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> REPLACE </code> is omitted from the binary log to avoid writing cleartext passwords to it. </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="dual-passwords"> </a> Dual Password Support </h4> </div> </div> </div> <a class="indexterm" name="idm46045248445344"> </a> <a class="indexterm" name="idm46045248443856"> </a> <a class="indexterm" name="idm46045248442784"> </a> <a class="indexterm" name="idm46045248441712"> </a> <p> User accounts are permitted to have dual passwords, designated as primary and secondary passwords. Dual-password capability makes it possible to seamlessly perform credential changes in scenarios like this: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A system has a large number of MySQL servers, possibly involving replication. </p> </li> <li class="listitem"> <p> Multiple applications connect to different MySQL servers. </p> </li> <li class="listitem"> <p> Periodic credential changes must be made to the account or accounts used by the applications to connect to the servers. </p> </li> </ul> </div> <p> Consider how a credential change must be performed in the preceding type of scenario when an account is permitted only a single password. In this case, there must be close cooperation in the timing of when the account password change is made and propagated throughout all servers, and when all applications that use the account are updated to use the new password. This process may involve downtime during which servers or applications are unavailable. </p> <p> With dual passwords, credential changes can be made more easily, in phases, without requiring close cooperation, and without downtime: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> For each affected account, establish a new primary password on the servers, retaining the current password as the secondary password. This enables servers to recognize either the primary or secondary password for each account, while applications can continue to connect to the servers using the same password as previously (which is now the secondary password). </p> </li> <li class="listitem"> <p> After the password change has propagated to all servers, modify applications that use any affected account to connect using the account primary password. </p> </li> <li class="listitem"> <p> After all applications have been migrated from the secondary passwords to the primary passwords, the secondary passwords are no longer needed and can be discarded. After this change has propagated to all servers, only the primary password for each account can be used to connect. The credential change is now complete. </p> </li> </ol> </div> <p> MySQL implements dual-password capability with syntax that saves and discards secondary passwords: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The <code class="literal"> RETAIN CURRENT PASSWORD </code> clause for the <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> and <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> statements saves an account current password as its secondary password when you assign a new primary password. </p> </li> <li class="listitem"> <p> The <code class="literal"> DISCARD OLD PASSWORD </code> clause for <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> discards an account secondary password, leaving only the primary password. </p> </li> </ul> </div> <p> Suppose that, for the previously described credential-change scenario, an account named <code class="literal"> 'appuser1'@'host1.example.com' </code> is used by applications to connect to servers, and that the account password is to be changed from <code class="literal"> ' <em class="replaceable"> <code> password_a </code> </em> ' </code> to <code class="literal"> ' <em class="replaceable"> <code> password_b </code> </em> ' </code> . </p> <p> To perform this change of credentials, use <code class="literal"> ALTER USER </code> as follows: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> On each server that is not a replica, establish <code class="literal"> ' <em class="replaceable"> <code> password_b </code> </em> ' </code> as the new <code class="literal"> appuser1 </code> primary password, retaining the current password as the secondary password: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa95975821"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'appuser1'</span>@<span class="token string">'host1.example.com'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password_b</em>'</span> <span class="token keyword">RETAIN</span> <span class="token keyword">CURRENT</span> <span class="token keyword">PASSWORD</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> Wait for the password change to replicate throughout the system to all replicas. </p> </li> <li class="listitem"> <p> Modify each application that uses the <code class="literal"> appuser1 </code> account so that it connects to the servers using a password of <code class="literal"> ' <em class="replaceable"> <code> password_b </code> </em> ' </code> rather than <code class="literal"> ' <em class="replaceable"> <code> password_a </code> </em> ' </code> . </p> </li> <li class="listitem"> <p> At this point, the secondary password is no longer needed. On each server that is not a replica, discard the secondary password: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa12645861"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'appuser1'</span>@<span class="token string">'host1.example.com'</span> <span class="token keyword">DISCARD</span> <span class="token keyword">OLD</span> <span class="token keyword">PASSWORD</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> After the discard-password change has replicated to all replicas, the credential change is complete. </p> </li> </ol> </div> <p> The <code class="literal"> RETAIN CURRENT PASSWORD </code> and <code class="literal"> DISCARD OLD PASSWORD </code> clauses have the following effects: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> RETAIN CURRENT PASSWORD </code> retains an account current password as its secondary password, replacing any existing secondary password. The new password becomes the primary password, but clients can use the account to connect to the server using either the primary or secondary password. (Exception: If the new password specified by the <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> or <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> statement is empty, the secondary password becomes empty as well, even if <code class="literal"> RETAIN CURRENT PASSWORD </code> is given.) </p> </li> <li class="listitem"> <p> If you specify <code class="literal"> RETAIN CURRENT PASSWORD </code> for an account that has an empty primary password, the statement fails. </p> </li> <li class="listitem"> <p> If an account has a secondary password and you change its primary password without specifying <code class="literal"> RETAIN CURRENT PASSWORD </code> , the secondary password remains unchanged. </p> </li> <li class="listitem"> <p> For <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> , if you change the authentication plugin assigned to the account, the secondary password is discarded. If you change the authentication plugin and also specify <code class="literal"> RETAIN CURRENT PASSWORD </code> , the statement fails. </p> </li> <li class="listitem"> <p> For <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> , <code class="literal"> DISCARD OLD PASSWORD </code> discards the secondary password, if one exists. The account retains only its primary password, and clients can use the account to connect to the server only with the primary password. </p> </li> </ul> </div> <p> Statements that modify secondary passwords require these privileges: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The <a class="link" href="privileges-provided.html#priv_application-password-admin"> <code class="literal"> APPLICATION_PASSWORD_ADMIN </code> </a> privilege is required to use the <code class="literal"> RETAIN CURRENT PASSWORD </code> or <code class="literal"> DISCARD OLD PASSWORD </code> clause for <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> and <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> statements that apply to your own account. The privilege is required to manipulate your own secondary password because most users require only one password. </p> </li> <li class="listitem"> <p> If an account is to be permitted to manipulate secondary passwords for all accounts, it should be granted the <a class="link" href="privileges-provided.html#priv_create-user"> <code class="literal"> CREATE USER </code> </a> privilege rather than <a class="link" href="privileges-provided.html#priv_application-password-admin"> <code class="literal"> APPLICATION_PASSWORD_ADMIN </code> </a> . </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="random-password-generation"> </a> Random Password Generation </h4> </div> </div> </div> <p> The <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> , <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> , and <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> statements have the capability of generating random passwords for user accounts, as an alternative to requiring explicit administrator-specified literal passwords. See the description of each statement for details about the syntax. This section describes the characteristics common to generated random passwords. </p> <p> By default, generated random passwords have a length of 20 characters. This length is controlled by the <a class="link" href="server-system-variables.html#sysvar_generated_random_password_length"> <code class="literal"> generated_random_password_length </code> </a> system variable, which has a range from 5 to 255. </p> <p> For each account for which a statement generates a random password, the statement stores the password in the <code class="literal"> mysql.user </code> system table, hashed appropriately for the account authentication plugin. The statement also returns the cleartext password in a row of a result set to make it available to the user or application executing the statement. The result set columns are named <code class="literal"> user </code> , <code class="literal"> host </code> , <code class="literal"> generated password </code> , and <code class="literal"> auth_factor </code> indicating the user name and host name values that identify the affected row in the <code class="literal"> mysql.user </code> system table, the cleartext generated password, and the authentication factor the displayed password value applies to. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa48582610"><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">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'u1'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span><span class="token punctuation">,</span> <span class="token string">'u2'</span>@<span class="token string">'%.example.com'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span><span class="token punctuation">,</span> <span class="token string">'u3'</span>@<span class="token string">'%.org'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</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 class="token punctuation">-</span><span class="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> user <span class="token punctuation">|</span> host <span class="token punctuation">|</span> generated password <span class="token punctuation">|</span> auth_factor <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 class="token punctuation">-</span><span class="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> u1 <span class="token punctuation">|</span> localhost <span class="token punctuation">|</span> iOeqf&gt;Mh9:;XD&amp;qn(Hl} <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> u2 <span class="token punctuation">|</span> %.example.com <span class="token punctuation">|</span> sXTSAEvw3St<span class="token punctuation">-</span>R<span class="token punctuation">+</span>_<span class="token punctuation">-</span>C3Vb <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> u3 <span class="token punctuation">|</span> %.org <span class="token punctuation">|</span> nEVe%Ctw/U/*Md)Exc7&amp; <span class="token punctuation">|</span> 1 <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 class="token punctuation">-</span><span class="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 prompt">mysql&gt;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'u1'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span><span class="token punctuation">,</span> <span class="token string">'u2'</span>@<span class="token string">'%.example.com'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</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 class="token punctuation">-</span><span class="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> user <span class="token punctuation">|</span> host <span class="token punctuation">|</span> generated password <span class="token punctuation">|</span> auth_factor <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 class="token punctuation">-</span><span class="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> u1 <span class="token punctuation">|</span> localhost <span class="token punctuation">|</span> Seiei:&amp;cw}8]@3OA64vh <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> u2 <span class="token punctuation">|</span> %.example.com <span class="token punctuation">|</span> j@&amp;diTX80l8}(NiHXSae <span class="token punctuation">|</span> 1 <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 class="token punctuation">-</span><span class="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 prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">FOR</span> <span class="token string">'u3'</span>@<span class="token string">'%.org'</span> <span class="token keyword">TO</span> <span class="token keyword">RANDOM</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> <span class="token output"><span class="token punctuation">|</span> user <span class="token punctuation">|</span> host <span class="token punctuation">|</span> generated password <span class="token punctuation">|</span> auth_factor <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> <span class="token output"><span class="token punctuation">|</span> u3 <span class="token punctuation">|</span> %.org <span class="token punctuation">|</span> n&amp;cz2xF;P3!U)<span class="token punctuation">+</span>]Vw52H <span class="token punctuation">|</span> 1 <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></code></pre> </div> <p> A <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> , <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> , or <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> statement that generates a random password for an account is written to the binary log as a <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> or <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statement with an <code class="literal"> IDENTIFIED WITH <em class="replaceable"> <code> auth_plugin </code> </em> AS ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> , clause, where <em class="replaceable"> <code> auth_plugin </code> </em> is the account authentication plugin and <code class="literal"> ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> is the account hashed password value. </p> <p> If the <code class="literal"> validate_password </code> component is installed, the policy that it implements has no effect on generated passwords. (The purpose of password validation is to help humans create better passwords.) </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="failed-login-tracking"> </a> Failed-Login Tracking and Temporary Account Locking </h4> </div> </div> </div> <p> Administrators can configure user accounts such that too many consecutive login failures cause temporary account locking. </p> <p> <span class="quote"> “ <span class="quote"> Login failure </span> ” </span> in this context means failure of the client to provide a correct password during a connection attempt. It does not include failure to connect for reasons such as unknown user or network issues. For accounts that have dual passwords (see <a class="xref" href="password-management.html#dual-passwords" title="Dual Password Support"> Dual Password Support </a> ), either account password counts as correct. </p> <p> The required number of login failures and the lock time are configurable per account, using the <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> and <code class="literal"> PASSWORD_LOCK_TIME </code> options of the <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="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statements. Examples: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa23658352"><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">'u1'</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 keyword">FAILED_LOGIN_ATTEMPTS</span> <span class="token number">3</span> <span class="token keyword">PASSWORD_LOCK_TIME</span> <span class="token number">3</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'u2'</span>@<span class="token string">'localhost'</span> <span class="token keyword">FAILED_LOGIN_ATTEMPTS</span> <span class="token number">4</span> <span class="token keyword">PASSWORD_LOCK_TIME</span> <span class="token keyword">UNBOUNDED</span><span class="token punctuation">;</span></code></pre> </div> <p> When too many consecutive login failures occur, the client receives an error that looks like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa42755714"><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-none">ERROR 3957 (HY000): Access denied for user <em class="replaceable">user</em>. Account is blocked for <em class="replaceable">D</em> day(s) (<em class="replaceable">R</em> day(s) remaining) due to <em class="replaceable">N</em> consecutive failed logins.</code></pre> </div> <p> Use the options as follows: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> FAILED_LOGIN_ATTEMPTS <em class="replaceable"> <code> N </code> </em> </code> </p> <p> This option indicates whether to track account login attempts that specify an incorrect password. The number <em class="replaceable"> <code> N </code> </em> specifies how many consecutive incorrect passwords cause temporary account locking. </p> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD_LOCK_TIME { <em class="replaceable"> <code> N </code> </em> | UNBOUNDED} </code> </p> <p> This option indicates how long to lock the account after too many consecutive login attempts provide an incorrect password. The value is a number <em class="replaceable"> <code> N </code> </em> to specify the number of days the account remains locked, or <code class="literal"> UNBOUNDED </code> to specify that when an account enters the temporarily locked state, the duration of that state is unbounded and does not end until the account is unlocked. The conditions under which unlocking occurs are described later. </p> </li> </ul> </div> <p> Permitted values of <em class="replaceable"> <code> N </code> </em> for each option are in the range from 0 to 32767. A value of 0 disables the option. </p> <p> Failed-login tracking and temporary account locking have these characteristics: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> For failed-login tracking and temporary locking to occur for an account, its <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> and <code class="literal"> PASSWORD_LOCK_TIME </code> options both must be nonzero. </p> </li> <li class="listitem"> <p> For <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> , if <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> or <code class="literal"> PASSWORD_LOCK_TIME </code> is not specified, its implicit default value is 0 for all accounts named by the statement. This means that failed-login tracking and temporary account locking are disabled. </p> </li> <li class="listitem"> <p> For <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> , if <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> or <code class="literal"> PASSWORD_LOCK_TIME </code> is not specified, its value remains unchanged for all accounts named by the statement. </p> </li> <li class="listitem"> <p> For temporary account locking to occur, password failures must be consecutive. Any successful login that occurs prior to reaching the <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> value for failed logins causes failure counting to reset. For example, if <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> is 4 and three consecutive password failures have occurred, one more failure is necessary for locking to begin. But if the next login succeeds, failed-login counting for the account is reset so that four consecutive failures are again required for locking. </p> </li> <li class="listitem"> <p> Once temporary locking begins, successful login cannot occur even with the correct password until either the lock duration has passed or the account is unlocked by one of the account-reset methods listed in the following discussion. </p> </li> </ul> </div> <p> When the server reads the grant tables, it initializes state information for each account regarding whether failed-login tracking is enabled, whether the account is currently temporarily locked and when locking began if so, and the number of failures before temporary locking occurs if the account is not locked. </p> <p> An account's state information can be reset, which means that failed-login counting is reset, and the account is unlocked if currently temporarily locked. Account resets can be global for all accounts or per account: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A global reset of all accounts occurs for any of these conditions: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> A server restart. </p> </li> <li class="listitem"> <p> Execution of <a class="link" href="flush.html#flush-privileges"> <code class="literal"> FLUSH PRIVILEGES </code> </a> . (Starting the server with <a class="link" href="server-options.html#option_mysqld_skip-grant-tables"> <code class="option"> --skip-grant-tables </code> </a> causes the grant tables not to be read, which disables failed-login tracking. In this case, the first execution of <a class="link" href="flush.html#flush-privileges"> <code class="literal"> FLUSH PRIVILEGES </code> </a> causes the server to read the grant tables and enable failed-login tracking, in addition to resetting all accounts.) </p> </li> </ul> </div> </li> <li class="listitem"> <p> A per-account reset occurs for any of these conditions: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Successful login for the account. </p> </li> <li class="listitem"> <p> The lock duration passes. In this case, failed-login counting resets at the time of the next login attempt. </p> </li> <li class="listitem"> <p> Execution of an <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statement for the account that sets either <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> or <code class="literal"> PASSWORD_LOCK_TIME </code> (or both) to any value (including the current option value), or execution of an <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER ... UNLOCK </code> </a> statement for the account. </p> <p> Other <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statements for the account have no effect on its current failed-login count or its locking state. </p> </li> </ul> </div> </li> </ul> </div> <p> Failed-login tracking is tied to the login account that is used to check credentials. If user proxying is in use, tracking occurs for the proxy user, not the proxied user. That is, tracking is tied to the account indicated by <a class="link" href="information-functions.html#function_user"> <code class="literal"> USER() </code> </a> , not the account indicated by <a class="link" href="information-functions.html#function_current-user"> <code class="literal"> CURRENT_USER() </code> </a> . For information about the distinction between proxy and proxied users, see <a class="xref" href="proxy-users.html" title="8.2.19 Proxy Users"> Section 8.2.19, “Proxy Users” </a> . </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/indexes.html
<div id="docs-body"> <div class="appendix"> <div class="titlepage"> <div> <div> <h1 class="title"> <a name="indexes"> </a> Appendix C Indexes </h1> </div> </div> </div> <div class="toc"> <p> <b> Table of Contents </b> </p> <dl class="toc"> <dt> <span class="index"> <a href="ix01.html"> General Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-cfunc.html"> C Function Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-command.html"> Command Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-function.html"> Function Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-is.html"> INFORMATION_SCHEMA Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-jointype.html"> Join Types Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-operator.html"> Operator Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-option.html"> Option Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-priv.html"> Privileges Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-sqlmode.html"> SQL Modes Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-statement.html"> Statement/Syntax Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-statvar.html"> Status Variable Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-sysvar.html"> System Variable Index </a> </span> </dt> <dt> <span class="index"> <a href="dynindex-isolevel.html"> Transaction Isolation Level Index </a> </span> </dt> </dl> </div> <p> </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/channels-startup-options.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="channels-startup-options"> </a> 19.2.2.3 Startup Options and Replication Channels </h4> </div> </div> </div> <a class="indexterm" name="idm46045138112960"> </a> <a class="indexterm" name="idm46045138111472"> </a> <p> This section describes startup options which are impacted by the addition of replication channels. </p> <p> The following startup options now affect <span class="emphasis"> <em> all </em> </span> channels in a replication topology. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> --log-replica-updates </code> </a> </p> <p> All transactions received by the replica (even from multiple sources) are written in the binary log. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#sysvar_relay_log_purge"> <code class="literal"> --relay-log-purge </code> </a> </p> <p> When set, each channel purges its own relay log automatically. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#sysvar_replica_transaction_retries"> <code class="literal"> --replica-transaction-retries </code> </a> </p> <p> The specified number of transaction retries can take place on all applier threads of all channels. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#option_mysqld_skip-replica-start"> <code class="option"> --skip-replica-start </code> </a> </p> <p> No replication threads start on any channels. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#sysvar_replica_skip_errors"> <code class="literal"> --replica-skip-errors </code> </a> </p> <p> Execution continues and errors are skipped for all channels. </p> </li> </ul> </div> <p> The values set for the following startup options apply on each channel; since these are <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> startup options, they are applied on every channel. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="option"> --max-relay-log-size= <em class="replaceable"> <code> size </code> </em> </code> </p> <p> Maximum size of the individual relay log file for each channel; after reaching this limit, the file is rotated. </p> </li> <li class="listitem"> <p> <code class="option"> --relay-log-space-limit= <em class="replaceable"> <code> size </code> </em> </code> </p> <p> Upper limit for the total size of all relay logs combined, for each individual channel. For <em class="replaceable"> <code> N </code> </em> channels, the combined size of these logs is limited to <a class="link" href="replication-options-replica.html#sysvar_relay_log_space_limit"> <code class="literal"> relay_log_space_limit * <em class="replaceable"> <code> N </code> </em> </code> </a> . </p> </li> <li class="listitem"> <p> <code class="option"> --replica-parallel-workers= <em class="replaceable"> <code> value </code> </em> </code> </p> <p> Number of replication applier threads per channel. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#sysvar_replica_checkpoint_group"> <code class="literal"> replica_checkpoint_group </code> </a> </p> <p> Waiting time by an receiver thread for each source. </p> </li> <li class="listitem"> <p> <code class="option"> --relay-log-index=filename </code> </p> <p> Base name for each channel's relay log index file. See <a class="xref" href="channels-naming-conventions.html" title="19.2.2.4 Replication Channel Naming Conventions"> Section 19.2.2.4, “Replication Channel Naming Conventions” </a> . </p> </li> <li class="listitem"> <p> <code class="option"> --relay-log=filename </code> </p> <p> Denotes the base name of each channel's relay log file. See <a class="xref" href="channels-naming-conventions.html" title="19.2.2.4 Replication Channel Naming Conventions"> Section 19.2.2.4, “Replication Channel Naming Conventions” </a> . </p> </li> <li class="listitem"> <p> <code class="option"> --replica-net-timeout= <em class="replaceable"> <code> N </code> </em> </code> </p> <p> This value is set per channel, so that each channel waits for <em class="replaceable"> <code> N </code> </em> seconds to check for a broken connection. </p> </li> <li class="listitem"> <p> <code class="option"> --replica-skip-counter= <em class="replaceable"> <code> N </code> </em> </code> </p> <p> This value is set per channel, so that each channel skips <em class="replaceable"> <code> N </code> </em> events from its source. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/sys-host-summary-by-stages.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="sys-host-summary-by-stages"> </a> 30.4.3.4 The host_summary_by_stages and x$host_summary_by_stages Views </h4> </div> </div> </div> <a class="indexterm" name="idm46045063287408"> </a> <a class="indexterm" name="idm46045063285952"> </a> <a class="indexterm" name="idm46045063284448"> </a> <a class="indexterm" name="idm46045063282944"> </a> <p> These views summarize statement stages, grouped by host. By default, rows are sorted by host and descending total latency. </p> <p> The <a class="link" href="sys-host-summary-by-stages.html" title="30.4.3.4 The host_summary_by_stages and x$host_summary_by_stages Views"> <code class="literal"> host_summary_by_stages </code> </a> and <a class="link" href="sys-host-summary-by-stages.html" title="30.4.3.4 The host_summary_by_stages and x$host_summary_by_stages Views"> <code class="literal"> x$host_summary_by_stages </code> </a> views have these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> host </code> </p> <p> The host from which the client connected. Rows for which the <code class="literal"> HOST </code> column in the underlying Performance Schema table is <code class="literal"> NULL </code> are assumed to be for background threads and are reported with a host name of <code class="literal"> background </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> event_name </code> </p> <p> The stage event name. </p> </li> <li class="listitem"> <p> <code class="literal"> total </code> </p> <p> The total number of occurrences of the stage event for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> total_latency </code> </p> <p> The total wait time of timed occurrences of the stage event for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> avg_latency </code> </p> <p> The average wait time per timed occurrence of the stage event for the host. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster.html
<div id="docs-body"> <div class="chapter"> <div class="titlepage"> <div> <div> <h1 class="title"> <a name="mysql-cluster"> </a> Chapter 25 MySQL NDB Cluster 8.4 </h1> </div> </div> </div> <div class="toc"> <p> <b> Table of Contents </b> </p> <dl class="toc"> <dt> <span class="section"> <a href="mysql-cluster-general-info.html"> 25.1 General Information </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-overview.html"> 25.2 NDB Cluster Overview </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="mysql-cluster-basics.html"> 25.2.1 NDB Cluster Core Concepts </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-nodes-groups.html"> 25.2.2 NDB Cluster Nodes, Node Groups, Fragment Replicas, and Partitions </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-overview-requirements.html"> 25.2.3 NDB Cluster Hardware, Software, and Networking Requirements </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-what-is-new.html"> 25.2.4 What is New in MySQL NDB Cluster 8.4 </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-added-deprecated-removed.html"> 25.2.5 Options, Variables, and Parameters Added, Deprecated or Removed in NDB 8.4 </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-compared.html"> 25.2.6 MySQL Server Using InnoDB Compared with NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations.html"> 25.2.7 Known Limitations of NDB Cluster </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="mysql-cluster-installation.html"> 25.3 NDB Cluster Installation </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="mysql-cluster-install-linux.html"> 25.3.1 Installation of NDB Cluster on Linux </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-install-windows.html"> 25.3.2 Installing NDB Cluster on Windows </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-install-configuration.html"> 25.3.3 Initial Configuration of NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-install-first-start.html"> 25.3.4 Initial Startup of NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-install-example-data.html"> 25.3.5 NDB Cluster Example with Tables and Data </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-install-shutdown-restart.html"> 25.3.6 Safe Shutdown and Restart of NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-upgrade-downgrade.html"> 25.3.7 Upgrading and Downgrading NDB Cluster </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="mysql-cluster-configuration.html"> 25.4 Configuration of NDB Cluster </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="mysql-cluster-quick.html"> 25.4.1 Quick Test Setup of NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-configuration-overview.html"> 25.4.2 Overview of NDB Cluster Configuration Parameters, Options, and Variables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-config-file.html"> 25.4.3 NDB Cluster Configuration Files </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-interconnects.html"> 25.4.4 Using High-Speed Interconnects with NDB Cluster </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="mysql-cluster-programs.html"> 25.5 NDB Cluster Programs </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="mysql-cluster-programs-ndbd.html"> 25.5.1 ndbd — The NDB Cluster Data Node Daemon </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndbinfo-select-all.html"> 25.5.2 ndbinfo_select_all — Select From ndbinfo Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndbmtd.html"> 25.5.3 ndbmtd — The NDB Cluster Data Node Daemon (Multi-Threaded) </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-mgmd.html"> 25.5.4 ndb_mgmd — The NDB Cluster Management Server Daemon </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-mgm.html"> 25.5.5 ndb_mgm — The NDB Cluster Management Client </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-blob-tool.html"> 25.5.6 ndb_blob_tool — Check and Repair BLOB and TEXT columns of NDB Cluster Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-config.html"> 25.5.7 ndb_config — Extract NDB Cluster Configuration Information </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-delete-all.html"> 25.5.8 ndb_delete_all — Delete All Rows from an NDB Table </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-desc.html"> 25.5.9 ndb_desc — Describe NDB Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-drop-index.html"> 25.5.10 ndb_drop_index — Drop Index from an NDB Table </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-drop-table.html"> 25.5.11 ndb_drop_table — Drop an NDB Table </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-error-reporter.html"> 25.5.12 ndb_error_reporter — NDB Error-Reporting Utility </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-import.html"> 25.5.13 ndb_import — Import CSV Data Into NDB </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-index-stat.html"> 25.5.14 ndb_index_stat — NDB Index Statistics Utility </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-move-data.html"> 25.5.15 ndb_move_data — NDB Data Copy Utility </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-perror.html"> 25.5.16 ndb_perror — Obtain NDB Error Message Information </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-print-backup-file.html"> 25.5.17 ndb_print_backup_file — Print NDB Backup File Contents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-print-file.html"> 25.5.18 ndb_print_file — Print NDB Disk Data File Contents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-print-frag-file.html"> 25.5.19 ndb_print_frag_file — Print NDB Fragment List File Contents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-print-schema-file.html"> 25.5.20 ndb_print_schema_file — Print NDB Schema File Contents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-print-sys-file.html"> 25.5.21 ndb_print_sys_file — Print NDB System File Contents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-redo-log-reader.html"> 25.5.22 ndb_redo_log_reader — Check and Print Content of Cluster Redo Log </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-restore.html"> 25.5.23 ndb_restore — Restore an NDB Cluster Backup </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-secretsfile-reader.html"> 25.5.24 ndb_secretsfile_reader — Obtain Key Information from an Encrypted NDB Data File </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-select-all.html"> 25.5.25 ndb_select_all — Print Rows from an NDB Table </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-select-count.html"> 25.5.26 ndb_select_count — Print Row Counts for NDB Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-show-tables.html"> 25.5.27 ndb_show_tables — Display List of NDB Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-sign-keys.html"> 25.5.28 ndb_sign_keys — Create, Sign, and Manage TLS Keys and Certificates for NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-size-pl.html"> 25.5.29 ndb_size.pl — NDBCLUSTER Size Requirement Estimator </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-top.html"> 25.5.30 ndb_top — View CPU usage information for NDB threads </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndb-waiter.html"> 25.5.31 ndb_waiter — Wait for NDB Cluster to Reach a Given Status </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-programs-ndbxfrm.html"> 25.5.32 ndbxfrm — Compress, Decompress, Encrypt, and Decrypt Files Created by NDB Cluster </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="mysql-cluster-management.html"> 25.6 Management of NDB Cluster </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="mysql-cluster-mgm-client-commands.html"> 25.6.1 Commands in the NDB Cluster Management Client </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-logs-ndb-messages.html"> 25.6.2 NDB Cluster Log Messages </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-event-reports.html"> 25.6.3 Event Reports Generated in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-start-phases.html"> 25.6.4 Summary of NDB Cluster Start Phases </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-rolling-restart.html"> 25.6.5 Performing a Rolling Restart of an NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-single-user-mode.html"> 25.6.6 NDB Cluster Single User Mode </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-online-add-node.html"> 25.6.7 Adding NDB Cluster Data Nodes Online </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-backup.html"> 25.6.8 Online Backup of NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-importing-data.html"> 25.6.9 Importing Data Into MySQL Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-mysqld.html"> 25.6.10 MySQL Server Usage for NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-disk-data.html"> 25.6.11 NDB Cluster Disk Data Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-online-operations.html"> 25.6.12 Online Operations with ALTER TABLE in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-privilege-synchronization.html"> 25.6.13 Privilege Synchronization and NDB_STORED_USER </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-tde.html"> 25.6.14 File System Encryption for NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-tls.html"> 25.6.15 TLS Link Encryption for NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-ndb-api-statistics.html"> 25.6.16 NDB API Statistics Counters and Variables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-ndbinfo.html"> 25.6.17 ndbinfo: The NDB Cluster Information Database </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-information-schema-tables.html"> 25.6.18 INFORMATION_SCHEMA Tables for NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-ps-tables.html"> 25.6.19 NDB Cluster and the Performance Schema </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-sql-statements.html"> 25.6.20 Quick Reference: NDB Cluster SQL Statements </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-security.html"> 25.6.21 NDB Cluster Security Issues </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="mysql-cluster-replication.html"> 25.7 NDB Cluster Replication </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="mysql-cluster-replication-abbreviations.html"> 25.7.1 NDB Cluster Replication: Abbreviations and Symbols </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-general.html"> 25.7.2 General Requirements for NDB Cluster Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-issues.html"> 25.7.3 Known Issues in NDB Cluster Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-schema.html"> 25.7.4 NDB Cluster Replication Schema and Tables </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-preparation.html"> 25.7.5 Preparing the NDB Cluster for Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-starting.html"> 25.7.6 Starting NDB Cluster Replication (Single Replication Channel) </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-two-channels.html"> 25.7.7 Using Two Replication Channels for NDB Cluster Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-failover.html"> 25.7.8 Implementing Failover with NDB Cluster Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-backups.html"> 25.7.9 NDB Cluster Backups With NDB Cluster Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-multi-source.html"> 25.7.10 NDB Cluster Replication: Bidirectional and Circular Replication </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-mta.html"> 25.7.11 NDB Cluster Replication Using the Multithreaded Applier </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-replication-conflict-resolution.html"> 25.7.12 NDB Cluster Replication Conflict Resolution </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="mysql-cluster-news.html"> 25.8 NDB Cluster Release Notes </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045124461648"> </a> <a class="indexterm" name="idm46045124460576"> </a> <a class="indexterm" name="idm46045124459088"> </a> <a class="indexterm" name="idm46045124457584"> </a> <p class="ndb-rel-level"> This chapter provides information about MySQL <span class="firstterm"> NDB Cluster </span> , a high-availability, high-redundancy version of MySQL adapted for the distributed computing environment, as well as information specific to NDB Cluster 8.4 (NDB 8.4.0), based on version 8.4 of the NDB storage engine. See <a class="xref" href="mysql-cluster-what-is-new.html" title="25.2.4 What is New in MySQL NDB Cluster 8.4"> Section 25.2.4, “What is New in MySQL NDB Cluster 8.4” </a> , for information about differences in NDB 8.4 as compared to earlier releases. See <a class="ulink" href="/doc/refman/8.0/en/mysql-cluster.html" target="_top"> MySQL NDB Cluster 8.0 </a> for information about NDB Cluster 8.0. Both NDB 8.0 and NDB 8.4 are intended for use in production environments. NDB Cluster 7.6 and 7.5 are previous GA releases still supported in production, although new deployments can and should use either of MySQL NDB Cluster 8.0 or 8.4. </p> <p> <span class="emphasis"> <em> NDB Cluster 7.4 and older release series are no longer supported or maintained </em> </span> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysqlimport.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="mysqlimport"> </a> 6.5.5 mysqlimport — A Data Import Program </h3> </div> </div> </div> <a class="indexterm" name="idm46045311955264"> </a> <a class="indexterm" name="idm46045311954352"> </a> <a class="indexterm" name="idm46045311952992"> </a> <a class="indexterm" name="idm46045311951632"> </a> <a class="indexterm" name="idm46045311950272"> </a> <p> The <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> client provides a command-line interface to the <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> SQL statement. Most options to <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> correspond directly to clauses of <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> syntax. See <a class="xref" href="load-data.html" title="15.2.9 LOAD DATA Statement"> Section 15.2.9, “LOAD DATA Statement” </a> . </p> <p> Invoke <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa98203679"><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">mysqlimport <span class="token punctuation">[</span><em class="replaceable">options</em><span class="token punctuation">]</span> <em class="replaceable">db_name</em> <em class="replaceable">textfile1</em> <span class="token punctuation">[</span><em class="replaceable">textfile2</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> For each text file named on the command line, <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> strips any extension from the file name and uses the result to determine the name of the table into which to import the file's contents. For example, files named <code class="filename"> patient.txt </code> , <code class="filename"> patient.text </code> , and <code class="filename"> patient </code> all would be imported into a table named <code class="literal"> patient </code> . </p> <p> <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> supports the following options, which can be specified on the command line or in the <code class="literal"> [mysqlimport] </code> and <code class="literal"> [client] </code> groups of an option file. For information about option files used by MySQL programs, see <a class="xref" href="option-files.html" title="6.2.2.2 Using Option Files"> Section 6.2.2.2, “Using Option Files” </a> . </p> <div class="table"> <a name="idm46045311929664"> </a> <p class="title"> <b> Table 6.14 mysqlimport Options </b> </p> <div class="table-contents"> <table frame="box" rules="all" summary="Command-line options available for mysqlimport."> <colgroup> <col style="width: 35%"/> <col style="width: 64%"/> </colgroup> <thead> <tr> <th> Option Name </th> <th> Description </th> </tr> </thead> <tbody> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_bind-address"> --bind-address </a> </td> <td> Use specified network interface to connect to MySQL Server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_character-sets-dir"> --character-sets-dir </a> </td> <td> Directory where character sets can be found </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_columns"> --columns </a> </td> <td> This option takes a comma-separated list of column names as its value </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_compress"> --compress </a> </td> <td> Compress all information sent between client and server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_compression-algorithms"> --compression-algorithms </a> </td> <td> Permitted compression algorithms for connections to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_debug"> --debug </a> </td> <td> Write debugging log </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_debug-check"> --debug-check </a> </td> <td> Print debugging information when program exits </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_debug-info"> --debug-info </a> </td> <td> Print debugging information, memory, and CPU statistics when program exits </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_default-auth"> --default-auth </a> </td> <td> Authentication plugin to use </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_default-character-set"> --default-character-set </a> </td> <td> Specify default character set </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-extra-file"> --defaults-extra-file </a> </td> <td> Read named option file in addition to usual option files </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-file"> --defaults-file </a> </td> <td> Read only named option file </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-group-suffix"> --defaults-group-suffix </a> </td> <td> Option group suffix value </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_delete"> --delete </a> </td> <td> Empty the table before importing the text file </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_enable-cleartext-plugin"> --enable-cleartext-plugin </a> </td> <td> Enable cleartext authentication plugin </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> --fields-enclosed-by </a> </td> <td> This option has the same meaning as the corresponding clause for LOAD DATA </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> --fields-escaped-by </a> </td> <td> This option has the same meaning as the corresponding clause for LOAD DATA </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> --fields-optionally-enclosed-by </a> </td> <td> This option has the same meaning as the corresponding clause for LOAD DATA </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> --fields-terminated-by </a> </td> <td> This option has the same meaning as the corresponding clause for LOAD DATA </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_force"> --force </a> </td> <td> Continue even if an SQL error occurs </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_get-server-public-key"> --get-server-public-key </a> </td> <td> Request RSA public key from server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_help"> --help </a> </td> <td> Display help message and exit </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_host"> --host </a> </td> <td> Host on which MySQL server is located </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ignore"> --ignore </a> </td> <td> See the description for the --replace option </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ignore-lines"> --ignore-lines </a> </td> <td> Ignore the first N lines of the data file </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_lines-terminated-by"> --lines-terminated-by </a> </td> <td> This option has the same meaning as the corresponding clause for LOAD DATA </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_local"> --local </a> </td> <td> Read input files locally from the client host </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_lock-tables"> --lock-tables </a> </td> <td> Lock all tables for writing before processing any text files </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_login-path"> --login-path </a> </td> <td> Read login path options from .mylogin.cnf </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_low-priority"> --low-priority </a> </td> <td> Use LOW_PRIORITY when loading the table </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_no-defaults"> --no-defaults </a> </td> <td> Read no option files </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_no-login-paths"> --no-login-paths </a> </td> <td> Do not read login paths from the login path file </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_password"> --password </a> </td> <td> Password to use when connecting to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> --password1 </a> </td> <td> First multifactor authentication password to use when connecting to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_password2"> --password2 </a> </td> <td> Second multifactor authentication password to use when connecting to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_password3"> --password3 </a> </td> <td> Third multifactor authentication password to use when connecting to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_pipe"> --pipe </a> </td> <td> Connect to server using named pipe (Windows only) </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_plugin-dir"> --plugin-dir </a> </td> <td> Directory where plugins are installed </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_port"> --port </a> </td> <td> TCP/IP port number for connection </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_print-defaults"> --print-defaults </a> </td> <td> Print default options </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_protocol"> --protocol </a> </td> <td> Transport protocol to use </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_replace"> --replace </a> </td> <td> The --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_server-public-key-path"> --server-public-key-path </a> </td> <td> Path name to file containing RSA public key </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_shared-memory-base-name"> --shared-memory-base-name </a> </td> <td> Shared-memory name for shared-memory connections (Windows only) </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_silent"> --silent </a> </td> <td> Produce output only when errors occur </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_socket"> --socket </a> </td> <td> Unix socket file or Windows named pipe to use </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-ca </a> </td> <td> File that contains list of trusted SSL Certificate Authorities </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-capath </a> </td> <td> Directory that contains trusted SSL Certificate Authority certificate files </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-cert </a> </td> <td> File that contains X.509 certificate </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-cipher </a> </td> <td> Permissible ciphers for connection encryption </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-crl </a> </td> <td> File that contains certificate revocation lists </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-crlpath </a> </td> <td> Directory that contains certificate revocation-list files </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl-fips-mode"> --ssl-fips-mode </a> </td> <td> Whether to enable FIPS mode on client side </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-key </a> </td> <td> File that contains X.509 key </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-mode </a> </td> <td> Desired security state of connection to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-session-data </a> </td> <td> File that contains SSL session data </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl"> --ssl-session-data-continue-on-failed-reuse </a> </td> <td> Whether to establish connections if session reuse fails </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_tls-ciphersuites"> --tls-ciphersuites </a> </td> <td> Permissible TLSv1.3 ciphersuites for encrypted connections </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_tls-sni-servername"> --tls-sni-servername </a> </td> <td> Server name supplied by the client </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_tls-version"> --tls-version </a> </td> <td> Permissible TLS protocols for encrypted connections </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_use-threads"> --use-threads </a> </td> <td> Number of threads for parallel file-loading </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_user"> --user </a> </td> <td> MySQL user name to use when connecting to server </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_verbose"> --verbose </a> </td> <td> Verbose mode </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_version"> --version </a> </td> <td> Display version information and exit </td> </tr> <tr> <td> <a class="link" href="mysqlimport.html#option_mysqlimport_zstd-compression-level"> --zstd-compression-level </a> </td> <td> Compression level for connections to server that use zstd compression </td> </tr> </tbody> </table> </div> <div class="table-contents"> <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 739px;"> <thead> <tr> <th style="width: 260.906px;"> Option Name </th> <th style="width: 477.094px;"> Description </th> </tr> </thead> </table> </div> </div> <br class="table-break"/> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a name="option_mysqlimport_help"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_help"> <code class="option"> --help </code> </a> , <code class="option"> -? </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for help"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --help </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311738096"> </a> <a class="indexterm" name="idm46045311736608"> </a> <p> Display a help message and exit. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_bind-address"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_bind-address"> <code class="option"> --bind-address= <em class="replaceable"> <code> ip_address </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for bind-address"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --bind-address=ip_address </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311726640"> </a> <a class="indexterm" name="idm46045311725152"> </a> <p> On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQL server. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_character-sets-dir"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_character-sets-dir"> <code class="option"> --character-sets-dir= <em class="replaceable"> <code> dir_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for character-sets-dir"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --character-sets-dir=path </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> [none] </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311710576"> </a> <a class="indexterm" name="idm46045311709072"> </a> <p> The directory where character sets are installed. See <a class="xref" href="charset-configuration.html" title="12.15 Character Set Configuration"> Section 12.15, “Character Set Configuration” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_columns"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_columns"> <code class="option"> --columns= <em class="replaceable"> <code> column_list </code> </em> </code> </a> , <code class="option"> -c <em class="replaceable"> <code> column_list </code> </em> </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for columns"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --columns=column_list </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311697680"> </a> <a class="indexterm" name="idm46045311696192"> </a> <p> This option takes a list of comma-separated column names as its value. The order of the column names indicates how to match data file columns with table columns. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_compress"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_compress"> <code class="option"> --compress </code> </a> , <code class="option"> -C </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for compress"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --compress[={OFF|ON}] </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311679504"> </a> <a class="indexterm" name="idm46045311678016"> </a> <p> Compress all information sent between the client and the server if possible. See <a class="xref" href="connection-compression-control.html" title="6.2.8 Connection Compression Control"> Section 6.2.8, “Connection Compression Control” </a> . </p> <p> This option is deprecated. Expect it to be removed in a future version of MySQL. See <a class="xref" href="connection-compression-control.html#connection-compression-legacy-configuration" title="Configuring Legacy Connection Compression"> Configuring Legacy Connection Compression </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_compression-algorithms"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_compression-algorithms"> <code class="option"> --compression-algorithms= <em class="replaceable"> <code> value </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for compression-algorithms"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --compression-algorithms=value </code> </td> </tr> <tr> <th> Type </th> <td> Set </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> uncompressed </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> zlib </code> </p> <p class="valid-value"> <code class="literal"> zstd </code> </p> <p class="valid-value"> <code class="literal"> uncompressed </code> </p> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311656704"> </a> <a class="indexterm" name="idm46045311655200"> </a> <p> The permitted compression algorithms for connections to the server. The available algorithms are the same as for the <a class="link" href="server-system-variables.html#sysvar_protocol_compression_algorithms"> <code class="literal"> protocol_compression_algorithms </code> </a> system variable. The default value is <code class="literal"> uncompressed </code> . </p> <p> For more information, see <a class="xref" href="connection-compression-control.html" title="6.2.8 Connection Compression Control"> Section 6.2.8, “Connection Compression Control” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_debug"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_debug"> <code class="option"> --debug[= <em class="replaceable"> <code> debug_options </code> </em> ] </code> </a> , <code class="option"> -# [ <em class="replaceable"> <code> debug_options </code> </em> ] </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for debug"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --debug[=debug_options] </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> d:t:o </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311636480"> </a> <a class="indexterm" name="idm46045311634992"> </a> <p> Write a debugging log. A typical <em class="replaceable"> <code> debug_options </code> </em> string is <code class="literal"> d:t:o, <em class="replaceable"> <code> file_name </code> </em> </code> . The default is <code class="literal"> d:t:o </code> . </p> <p> This option is available only if MySQL was built using <a class="link" href="source-configuration-options.html#option_cmake_with_debug"> <code class="option"> WITH_DEBUG </code> </a> . MySQL release binaries provided by Oracle are <span class="emphasis"> <em> not </em> </span> built using this option. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_debug-check"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_debug-check"> <code class="option"> --debug-check </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for debug-check"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --debug-check </code> </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> FALSE </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311616752"> </a> <a class="indexterm" name="idm46045311615264"> </a> <p> Print some debugging information when the program exits. </p> <p> This option is available only if MySQL was built using <a class="link" href="source-configuration-options.html#option_cmake_with_debug"> <code class="option"> WITH_DEBUG </code> </a> . MySQL release binaries provided by Oracle are <span class="emphasis"> <em> not </em> </span> built using this option. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_debug-info"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_debug-info"> <code class="option"> --debug-info </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for debug-info"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --debug-info </code> </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> FALSE </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311599152"> </a> <a class="indexterm" name="idm46045311597664"> </a> <p> Print debugging information and memory and CPU usage statistics when the program exits. </p> <p> This option is available only if MySQL was built using <a class="link" href="source-configuration-options.html#option_cmake_with_debug"> <code class="option"> WITH_DEBUG </code> </a> . MySQL release binaries provided by Oracle are <span class="emphasis"> <em> not </em> </span> built using this option. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_default-character-set"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_default-character-set"> <code class="option"> --default-character-set= <em class="replaceable"> <code> charset_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for default-character-set"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --default-character-set=charset_name </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311583504"> </a> <a class="indexterm" name="idm46045311582000"> </a> <p> Use <em class="replaceable"> <code> charset_name </code> </em> as the default character set. See <a class="xref" href="charset-configuration.html" title="12.15 Character Set Configuration"> Section 12.15, “Character Set Configuration” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_default-auth"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_default-auth"> <code class="option"> --default-auth= <em class="replaceable"> <code> plugin </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for default-auth"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --default-auth=plugin </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311568944"> </a> <a class="indexterm" name="idm46045311567456"> </a> <p> A hint about which client-side authentication plugin to use. See <a class="xref" href="pluggable-authentication.html" title="8.2.17 Pluggable Authentication"> Section 8.2.17, “Pluggable Authentication” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_defaults-extra-file"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-extra-file"> <code class="option"> --defaults-extra-file= <em class="replaceable"> <code> file_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for defaults-extra-file"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --defaults-extra-file=file_name </code> </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311554704"> </a> <a class="indexterm" name="idm46045311553200"> </a> <p> Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, an error occurs. If <em class="replaceable"> <code> file_name </code> </em> is not an absolute path name, it is interpreted relative to the current directory. </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_defaults-file"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-file"> <code class="option"> --defaults-file= <em class="replaceable"> <code> file_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for defaults-file"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --defaults-file=file_name </code> </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311539296"> </a> <a class="indexterm" name="idm46045311537808"> </a> <p> Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. If <em class="replaceable"> <code> file_name </code> </em> is not an absolute path name, it is interpreted relative to the current directory. </p> <p> Exception: Even with <a class="link" href="option-file-options.html#option_general_defaults-file"> <code class="option"> --defaults-file </code> </a> , client programs read <code class="filename"> .mylogin.cnf </code> . </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_defaults-group-suffix"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-group-suffix"> <code class="option"> --defaults-group-suffix= <em class="replaceable"> <code> str </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for defaults-group-suffix"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --defaults-group-suffix=str </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311521712"> </a> <a class="indexterm" name="idm46045311520208"> </a> <p> Read not only the usual option groups, but also groups with the usual names and a suffix of <em class="replaceable"> <code> str </code> </em> . For example, <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> normally reads the <code class="literal"> [client] </code> and <code class="literal"> [mysqlimport] </code> groups. If this option is given as <a class="link" href="mysqlimport.html#option_mysqlimport_defaults-group-suffix"> <code class="option"> --defaults-group-suffix=_other </code> </a> , <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> also reads the <code class="literal"> [client_other] </code> and <code class="literal"> [mysqlimport_other] </code> groups. </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_delete"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_delete"> <code class="option"> --delete </code> </a> , <code class="option"> -D </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for delete"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --delete </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311502016"> </a> <a class="indexterm" name="idm46045311500528"> </a> <p> Empty the table before importing the text file. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_enable-cleartext-plugin"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_enable-cleartext-plugin"> <code class="option"> --enable-cleartext-plugin </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for enable-cleartext-plugin"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --enable-cleartext-plugin </code> </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> FALSE </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311486208"> </a> <a class="indexterm" name="idm46045311484704"> </a> <p> Enable the <code class="literal"> mysql_clear_password </code> cleartext authentication plugin. (See <a class="xref" href="cleartext-pluggable-authentication.html" title="8.4.1.4 Client-Side Cleartext Pluggable Authentication"> Section 8.4.1.4, “Client-Side Cleartext Pluggable Authentication” </a> .) </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_fields"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> <code class="option"> --fields-terminated-by=... </code> </a> , <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> <code class="option"> --fields-enclosed-by=... </code> </a> , <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> <code class="option"> --fields-optionally-enclosed-by=... </code> </a> , <a class="link" href="mysqlimport.html#option_mysqlimport_fields"> <code class="option"> --fields-escaped-by=... </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for fields-terminated-by"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --fields-terminated-by=string </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311468560"> </a> <a class="indexterm" name="idm46045311467056"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for fields-enclosed-by"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --fields-enclosed-by=string </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311457968"> </a> <a class="indexterm" name="idm46045311456464"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for fields-optionally-enclosed-by"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --fields-optionally-enclosed-by=string </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311447360"> </a> <a class="indexterm" name="idm46045311445856"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for fields-escaped-by"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --fields-escaped-by </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311436784"> </a> <a class="indexterm" name="idm46045311435280"> </a> <p> These options have the same meaning as the corresponding clauses for <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> . See <a class="xref" href="load-data.html" title="15.2.9 LOAD DATA Statement"> Section 15.2.9, “LOAD DATA Statement” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_force"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_force"> <code class="option"> --force </code> </a> , <code class="option"> -f </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for force"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --force </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311423216"> </a> <a class="indexterm" name="idm46045311421728"> </a> <p> Ignore errors. For example, if a table for a text file does not exist, continue processing any remaining files. Without <a class="link" href="mysqlimport.html#option_mysqlimport_force"> <code class="option"> --force </code> </a> , <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> exits if a table does not exist. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_get-server-public-key"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_get-server-public-key"> <code class="option"> --get-server-public-key </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for get-server-public-key"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --get-server-public-key </code> </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311407568"> </a> <a class="indexterm" name="idm46045311406064"> </a> <p> Request from the server the public key required for RSA key pair-based password exchange. This option applies to clients that authenticate with the <code class="literal"> caching_sha2_password </code> authentication plugin. For that plugin, the server does not send the public key unless requested. This option is ignored for accounts that do not authenticate with that plugin. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection. </p> <p> If <a class="link" href="mysqlimport.html#option_mysqlimport_server-public-key-path"> <code class="option"> --server-public-key-path= <em class="replaceable"> <code> file_name </code> </em> </code> </a> is given and specifies a valid public key file, it takes precedence over <a class="link" href="mysqlimport.html#option_mysqlimport_get-server-public-key"> <code class="option"> --get-server-public-key </code> </a> . </p> <p> For information about the <code class="literal"> caching_sha2_password </code> plugin, see <a class="xref" href="caching-sha2-pluggable-authentication.html" title="8.4.1.2 Caching SHA-2 Pluggable Authentication"> Section 8.4.1.2, “Caching SHA-2 Pluggable Authentication” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_host"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_host"> <code class="option"> --host= <em class="replaceable"> <code> host_name </code> </em> </code> </a> , <code class="option"> -h <em class="replaceable"> <code> host_name </code> </em> </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for host"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --host=host_name </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> localhost </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311385040"> </a> <a class="indexterm" name="idm46045311383552"> </a> <p> Import data to the MySQL server on the given host. The default host is <code class="literal"> localhost </code> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_ignore"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_ignore"> <code class="option"> --ignore </code> </a> , <code class="option"> -i </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for ignore"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --ignore </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311372688"> </a> <a class="indexterm" name="idm46045311371200"> </a> <p> See the description for the <a class="link" href="mysqlimport.html#option_mysqlimport_replace"> <code class="option"> --replace </code> </a> option. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_ignore-lines"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_ignore-lines"> <code class="option"> --ignore-lines= <em class="replaceable"> <code> N </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for ignore-lines"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --ignore-lines=# </code> </td> </tr> <tr> <th> Type </th> <td> Numeric </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311358304"> </a> <a class="indexterm" name="idm46045311356816"> </a> <p> Ignore the first <em class="replaceable"> <code> N </code> </em> lines of the data file. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_lines-terminated-by"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_lines-terminated-by"> <code class="option"> --lines-terminated-by=... </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for lines-terminated-by"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --lines-terminated-by=string </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311344656"> </a> <a class="indexterm" name="idm46045311343152"> </a> <p> This option has the same meaning as the corresponding clause for <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> . For example, to import Windows files that have lines terminated with carriage return/linefeed pairs, use <a class="link" href="mysqlimport.html#option_mysqlimport_lines-terminated-by"> <code class="option"> --lines-terminated-by="\r\n" </code> </a> . (You might have to double the backslashes, depending on the escaping conventions of your command interpreter.) See <a class="xref" href="load-data.html" title="15.2.9 LOAD DATA Statement"> Section 15.2.9, “LOAD DATA Statement” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_local"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_local"> <code class="option"> --local </code> </a> , <code class="option"> -L </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for local"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --local </code> </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> FALSE </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311325312"> </a> <a class="indexterm" name="idm46045311323824"> </a> <p> By default, files are read by the server on the server host. With this option, <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> reads input files locally on the client host. </p> <p> Successful use of <code class="literal"> LOCAL </code> load operations within <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> also requires that the server permits local loading; see <a class="xref" href="load-data-local-security.html" title="8.1.6 Security Considerations for LOAD DATA LOCAL"> Section 8.1.6, “Security Considerations for LOAD DATA LOCAL” </a> </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_lock-tables"> </a> <a class="link" href="mysqldump.html#option_mysqldump_lock-tables"> <code class="option"> --lock-tables </code> </a> , <code class="option"> -l </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for lock-tables"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --lock-tables </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311309328"> </a> <a class="indexterm" name="idm46045311307840"> </a> <p> Lock <span class="emphasis"> <em> all </em> </span> tables for writing before processing any text files. This ensures that all tables are synchronized on the server. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_login-path"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_login-path"> <code class="option"> --login-path= <em class="replaceable"> <code> name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for login-path"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --login-path=name </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311295344"> </a> <a class="indexterm" name="idm46045311293856"> </a> <p> Read options from the named login path in the <code class="filename"> .mylogin.cnf </code> login path file. A <span class="quote"> “ <span class="quote"> login path </span> ” </span> is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, use the <a class="link" href="mysql-config-editor.html" title="6.6.7 mysql_config_editor — MySQL Configuration Utility"> <span class="command"> <strong> mysql_config_editor </strong> </span> </a> utility. See <a class="xref" href="mysql-config-editor.html" title="6.6.7 mysql_config_editor — MySQL Configuration Utility"> Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility” </a> . </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_no-login-paths"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_no-login-paths"> <code class="option"> --no-login-paths </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for no-login-paths"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --no-login-paths </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311279712"> </a> <a class="indexterm" name="idm46045311278224"> </a> <p> Skips reading options from the login path file. </p> <p> See <a class="link" href="mysqlimport.html#option_mysqlimport_login-path"> <code class="option"> --login-path </code> </a> for related information. </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_low-priority"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_low-priority"> <code class="option"> --low-priority </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for low-priority"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --low-priority </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311265952"> </a> <a class="indexterm" name="idm46045311264464"> </a> <p> Use <code class="literal"> LOW_PRIORITY </code> when loading the table. This affects only storage engines that use only table-level locking (such as <code class="literal"> MyISAM </code> , <code class="literal"> MEMORY </code> , and <code class="literal"> MERGE </code> ). </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_no-defaults"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_no-defaults"> <code class="option"> --no-defaults </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for no-defaults"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --no-defaults </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311251856"> </a> <a class="indexterm" name="idm46045311250368"> </a> <p> Do not read any option files. If program startup fails due to reading unknown options from an option file, <a class="link" href="mysqlimport.html#option_mysqlimport_no-defaults"> <code class="option"> --no-defaults </code> </a> can be used to prevent them from being read. </p> <p> The exception is that the <code class="filename"> .mylogin.cnf </code> file is read in all cases, if it exists. This permits passwords to be specified in a safer way than on the command line even when <a class="link" href="mysqlimport.html#option_mysqlimport_no-defaults"> <code class="option"> --no-defaults </code> </a> is used. To create <code class="filename"> .mylogin.cnf </code> , use the <a class="link" href="mysql-config-editor.html" title="6.6.7 mysql_config_editor — MySQL Configuration Utility"> <span class="command"> <strong> mysql_config_editor </strong> </span> </a> utility. See <a class="xref" href="mysql-config-editor.html" title="6.6.7 mysql_config_editor — MySQL Configuration Utility"> Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility” </a> . </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_password"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_password"> <code class="option"> --password[= <em class="replaceable"> <code> password </code> </em> ] </code> </a> , <code class="option"> -p[ <em class="replaceable"> <code> password </code> </em> ] </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for password"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --password[=password] </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311230128"> </a> <a class="indexterm" name="idm46045311228640"> </a> <p> The password of the MySQL account used for connecting to the server. The password value is optional. If not given, <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> prompts for one. If given, there must be <span class="emphasis"> <em> no space </em> </span> between <a class="link" href="mysqlimport.html#option_mysqlimport_password"> <code class="option"> --password= </code> </a> or <code class="option"> -p </code> and the password following it. If no password option is specified, the default is to send no password. </p> <p> Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use an option file. See <a class="xref" href="password-security-user.html" title="8.1.2.1 End-User Guidelines for Password Security"> Section 8.1.2.1, “End-User Guidelines for Password Security” </a> . </p> <p> To explicitly specify that there is no password and that <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> should not prompt for one, use the <a class="link" href="mysqlimport.html#option_mysqlimport_password"> <code class="option"> --skip-password </code> </a> option. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_password1"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --password1[= <em class="replaceable"> <code> pass_val </code> </em> ] </code> </a> </p> <a class="indexterm" name="idm46045311216704"> </a> <p> The password for multifactor authentication factor 1 of the MySQL account used for connecting to the server. The password value is optional. If not given, <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> prompts for one. If given, there must be <span class="emphasis"> <em> no space </em> </span> between <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --password1= </code> </a> and the password following it. If no password option is specified, the default is to send no password. </p> <p> Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use an option file. See <a class="xref" href="password-security-user.html" title="8.1.2.1 End-User Guidelines for Password Security"> Section 8.1.2.1, “End-User Guidelines for Password Security” </a> . </p> <p> To explicitly specify that there is no password and that <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> should not prompt for one, use the <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --skip-password1 </code> </a> option. </p> <p> <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --password1 </code> </a> and <a class="link" href="mysqlimport.html#option_mysqlimport_password"> <code class="option"> --password </code> </a> are synonymous, as are <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --skip-password1 </code> </a> and <a class="link" href="mysqlimport.html#option_mysqlimport_password"> <code class="option"> --skip-password </code> </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_password2"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_password2"> <code class="option"> --password2[= <em class="replaceable"> <code> pass_val </code> </em> ] </code> </a> </p> <a class="indexterm" name="idm46045311201152"> </a> <p> The password for multifactor authentication factor 2 of the MySQL account used for connecting to the server. The semantics of this option are similar to the semantics for <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --password1 </code> </a> ; see the description of that option for details. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_password3"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_password3"> <code class="option"> --password3[= <em class="replaceable"> <code> pass_val </code> </em> ] </code> </a> </p> <a class="indexterm" name="idm46045311195792"> </a> <p> The password for multifactor authentication factor 3 of the MySQL account used for connecting to the server. The semantics of this option are similar to the semantics for <a class="link" href="mysqlimport.html#option_mysqlimport_password1"> <code class="option"> --password1 </code> </a> ; see the description of that option for details. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_pipe"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_pipe"> <code class="option"> --pipe </code> </a> , <code class="option"> -W </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for pipe"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --pipe </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311182992"> </a> <a class="indexterm" name="idm46045311181504"> </a> <p> On Windows, connect to the server using a named pipe. This option applies only if the server was started with the <a class="link" href="server-system-variables.html#sysvar_named_pipe"> <code class="literal"> named_pipe </code> </a> system variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of the Windows group specified by the <a class="link" href="server-system-variables.html#sysvar_named_pipe_full_access_group"> <code class="literal"> named_pipe_full_access_group </code> </a> system variable. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_plugin-dir"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_plugin-dir"> <code class="option"> --plugin-dir= <em class="replaceable"> <code> dir_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for plugin-dir"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --plugin-dir=dir_name </code> </td> </tr> <tr> <th> Type </th> <td> Directory name </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311166688"> </a> <a class="indexterm" name="idm46045311165200"> </a> <p> The directory in which to look for plugins. Specify this option if the <a class="link" href="mysqlimport.html#option_mysqlimport_default-auth"> <code class="option"> --default-auth </code> </a> option is used to specify an authentication plugin but <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> does not find it. See <a class="xref" href="pluggable-authentication.html" title="8.2.17 Pluggable Authentication"> Section 8.2.17, “Pluggable Authentication” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_port"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_port"> <code class="option"> --port= <em class="replaceable"> <code> port_num </code> </em> </code> </a> , <code class="option"> -P <em class="replaceable"> <code> port_num </code> </em> </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for port"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --port=port_num </code> </td> </tr> <tr> <th> Type </th> <td> Numeric </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 3306 </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311147072"> </a> <a class="indexterm" name="idm46045311145584"> </a> <p> For TCP/IP connections, the port number to use. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_print-defaults"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_print-defaults"> <code class="option"> --print-defaults </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for print-defaults"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --print-defaults </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311135920"> </a> <a class="indexterm" name="idm46045311134432"> </a> <p> Print the program name and all options that it gets from option files. </p> <p> For additional information about this and other option-file options, see <a class="xref" href="option-file-options.html" title="6.2.2.3 Command-Line Options that Affect Option-File Handling"> Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_protocol"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_protocol"> <code class="option"> --protocol={TCP|SOCKET|PIPE|MEMORY} </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for protocol"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --protocol=type </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> [see text] </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> TCP </code> </p> <p class="valid-value"> <code class="literal"> SOCKET </code> </p> <p class="valid-value"> <code class="literal"> PIPE </code> </p> <p class="valid-value"> <code class="literal"> MEMORY </code> </p> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311113360"> </a> <a class="indexterm" name="idm46045311111872"> </a> <p> The transport protocol to use for connecting to the server. It is useful when the other connection parameters normally result in use of a protocol other than the one you want. For details on the permissible values, see <a class="xref" href="transport-protocols.html" title="6.2.7 Connection Transport Protocols"> Section 6.2.7, “Connection Transport Protocols” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_replace"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_replace"> <code class="option"> --replace </code> </a> , <code class="option"> -r </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for replace"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --replace </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311100864"> </a> <a class="indexterm" name="idm46045311099376"> </a> <p> The <a class="link" href="mysqlimport.html#option_mysqlimport_replace"> <code class="option"> --replace </code> </a> and <a class="link" href="mysqlimport.html#option_mysqlimport_ignore"> <code class="option"> --ignore </code> </a> options control handling of input rows that duplicate existing rows on unique key values. If you specify <a class="link" href="mysqlimport.html#option_mysqlimport_replace"> <code class="option"> --replace </code> </a> , new rows replace existing rows that have the same unique key value. If you specify <a class="link" href="mysqlimport.html#option_mysqlimport_ignore"> <code class="option"> --ignore </code> </a> , input rows that duplicate an existing row on a unique key value are skipped. If you do not specify either option, an error occurs when a duplicate key value is found, and the rest of the text file is ignored. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_server-public-key-path"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_server-public-key-path"> <code class="option"> --server-public-key-path= <em class="replaceable"> <code> file_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for server-public-key-path"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --server-public-key-path=file_name </code> </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311082864"> </a> <a class="indexterm" name="idm46045311081360"> </a> <p> The path name to a file in PEM format containing a client-side copy of the public key required by the server for RSA key pair-based password exchange. This option applies to clients that authenticate with the <code class="literal"> sha256_password </code> (deprecated) or <code class="literal"> caching_sha2_password </code> authentication plugin. This option is ignored for accounts that do not authenticate with one of those plugins. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection. </p> <p> If <a class="link" href="mysqlimport.html#option_mysqlimport_server-public-key-path"> <code class="option"> --server-public-key-path= <em class="replaceable"> <code> file_name </code> </em> </code> </a> is given and specifies a valid public key file, it takes precedence over <a class="link" href="mysqlimport.html#option_mysqlimport_get-server-public-key"> <code class="option"> --get-server-public-key </code> </a> . </p> <p> For <code class="literal"> sha256_password </code> (deprecated), this option applies only if MySQL was built using OpenSSL. </p> <p> For information about the <code class="literal"> sha256_password </code> and <code class="literal"> caching_sha2_password </code> plugins, see <a class="xref" href="sha256-pluggable-authentication.html" title="8.4.1.3 SHA-256 Pluggable Authentication"> Section 8.4.1.3, “SHA-256 Pluggable Authentication” </a> , and <a class="xref" href="caching-sha2-pluggable-authentication.html" title="8.4.1.2 Caching SHA-2 Pluggable Authentication"> Section 8.4.1.2, “Caching SHA-2 Pluggable Authentication” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_shared-memory-base-name"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_shared-memory-base-name"> <code class="option"> --shared-memory-base-name= <em class="replaceable"> <code> name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for shared-memory-base-name"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --shared-memory-base-name=name </code> </td> </tr> <tr> <th> Platform Specific </th> <td> Windows </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311059888"> </a> <a class="indexterm" name="idm46045311058384"> </a> <p> On Windows, the shared-memory name to use for connections made using shared memory to a local server. The default value is <code class="literal"> MYSQL </code> . The shared-memory name is case-sensitive. </p> <p> This option applies only if the server was started with the <a class="link" href="server-system-variables.html#sysvar_shared_memory"> <code class="literal"> shared_memory </code> </a> system variable enabled to support shared-memory connections. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_silent"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_silent"> <code class="option"> --silent </code> </a> , <code class="option"> -s </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for silent"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --silent </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311045680"> </a> <a class="indexterm" name="idm46045311044192"> </a> <p> Silent mode. Produce output only when errors occur. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_socket"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_socket"> <code class="option"> --socket= <em class="replaceable"> <code> path </code> </em> </code> </a> , <code class="option"> -S <em class="replaceable"> <code> path </code> </em> </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for socket"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --socket={file_name|pipe_name} </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045311031520"> </a> <a class="indexterm" name="idm46045311030032"> </a> <p> For connections to <code class="literal"> localhost </code> , the Unix socket file to use, or, on Windows, the name of the named pipe to use. </p> <p> On Windows, this option applies only if the server was started with the <a class="link" href="server-system-variables.html#sysvar_named_pipe"> <code class="literal"> named_pipe </code> </a> system variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of the Windows group specified by the <a class="link" href="server-system-variables.html#sysvar_named_pipe_full_access_group"> <code class="literal"> named_pipe_full_access_group </code> </a> system variable. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_ssl"> </a> <code class="option"> --ssl* </code> </p> <a class="indexterm" name="idm46045311022448"> </a> <a class="indexterm" name="idm46045311020960"> </a> <p> Options that begin with <code class="option"> --ssl </code> specify whether to connect to the server using encryption and indicate where to find SSL keys and certificates. See <a class="xref" href="connection-options.html#encrypted-connection-options" title="Command Options for Encrypted Connections"> Command Options for Encrypted Connections </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_ssl-fips-mode"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_ssl-fips-mode"> <code class="option"> --ssl-fips-mode={OFF|ON|STRICT} </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for ssl-fips-mode"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --ssl-fips-mode={OFF|ON|STRICT} </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> Type </th> <td> Enumeration </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> OFF </code> </p> <p class="valid-value"> <code class="literal"> ON </code> </p> <p class="valid-value"> <code class="literal"> STRICT </code> </p> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310998816"> </a> <a class="indexterm" name="idm46045310997328"> </a> <p> Controls whether to enable FIPS mode on the client side. The <a class="link" href="mysqlimport.html#option_mysqlimport_ssl-fips-mode"> <code class="option"> --ssl-fips-mode </code> </a> option differs from other <code class="option"> --ssl- <em class="replaceable"> <code> xxx </code> </em> </code> options in that it is not used to establish encrypted connections, but rather to affect which cryptographic operations to permit. See <a class="xref" href="fips-mode.html" title="8.8 FIPS Support"> Section 8.8, “FIPS Support” </a> . </p> <p> These <a class="link" href="mysqlimport.html#option_mysqlimport_ssl-fips-mode"> <code class="option"> --ssl-fips-mode </code> </a> values are permitted: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <code class="literal"> OFF </code> : Disable FIPS mode. </p> </li> <li class="listitem"> <p> <code class="literal"> ON </code> : Enable FIPS mode. </p> </li> <li class="listitem"> <p> <code class="literal"> STRICT </code> : Enable <span class="quote"> “ <span class="quote"> strict </span> ” </span> FIPS mode. </p> </li> </ul> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If the OpenSSL FIPS Object Module is not available, the only permitted value for <a class="link" href="mysqlimport.html#option_mysqlimport_ssl-fips-mode"> <code class="option"> --ssl-fips-mode </code> </a> is <code class="literal"> OFF </code> . In this case, setting <a class="link" href="mysqlimport.html#option_mysqlimport_ssl-fips-mode"> <code class="option"> --ssl-fips-mode </code> </a> to <code class="literal"> ON </code> or <code class="literal"> STRICT </code> causes the client to produce a warning at startup and to operate in non-FIPS mode. </p> </div> <p> This option is deprecated. Expect it to be removed in a future version of MySQL. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_tls-ciphersuites"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_tls-ciphersuites"> <code class="option"> --tls-ciphersuites= <em class="replaceable"> <code> ciphersuite_list </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for tls-ciphersuites"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --tls-ciphersuites=ciphersuite_list </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310970368"> </a> <a class="indexterm" name="idm46045310968880"> </a> <p> The permissible ciphersuites for encrypted connections that use TLSv1.3. The value is a list of one or more colon-separated ciphersuite names. The ciphersuites that can be named for this option depend on the SSL library used to compile MySQL. For details, see <a class="xref" href="encrypted-connection-protocols-ciphers.html" title="8.3.2 Encrypted Connection TLS Protocols and Ciphers"> Section 8.3.2, “Encrypted Connection TLS Protocols and Ciphers” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_tls-sni-servername"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_tls-sni-servername"> <code class="option"> --tls-sni-servername= <em class="replaceable"> <code> server_name </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for tls-sni-servername"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --tls-sni-servername=server_name </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310955888"> </a> <a class="indexterm" name="idm46045310954384"> </a> <p> When specified, the name is passed to the <code class="literal"> libmysqlclient </code> C API library using the <code class="literal"> MYSQL_OPT_TLS_SNI_SERVERNAME </code> option of <a class="ulink" href="/doc/c-api/8.4/en/mysql-options.html" target="_top"> <code class="literal"> mysql_options() </code> </a> . The server name is not case-sensitive. To show which server name the client specified for the current session, if any, check the <a class="link" href="server-status-variables.html#statvar_Tls_sni_server_name"> <code class="literal"> Tls_sni_server_name </code> </a> status variable. </p> <p> Server Name Indication (SNI) is an extension to the TLS protocol (OpenSSL must be compiled using TLS extensions for this option to function). The MySQL implementation of SNI represents the client-side only. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_tls-version"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_tls-version"> <code class="option"> --tls-version= <em class="replaceable"> <code> protocol_list </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for tls-version"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --tls-version=protocol_list </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <p class="valid-value"> <code class="literal"> TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 </code> (OpenSSL 1.1.1 or higher) </p> <p class="valid-value"> <code class="literal"> TLSv1,TLSv1.1,TLSv1.2 </code> (otherwise) </p> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310933440"> </a> <a class="indexterm" name="idm46045310931952"> </a> <p> The permissible TLS protocols for encrypted connections. The value is a list of one or more comma-separated protocol names. The protocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see <a class="xref" href="encrypted-connection-protocols-ciphers.html" title="8.3.2 Encrypted Connection TLS Protocols and Ciphers"> Section 8.3.2, “Encrypted Connection TLS Protocols and Ciphers” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_user"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_user"> <code class="option"> --user= <em class="replaceable"> <code> user_name </code> </em> </code> </a> , <code class="option"> -u <em class="replaceable"> <code> user_name </code> </em> </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for user"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --user=user_name, </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310918384"> </a> <a class="indexterm" name="idm46045310916896"> </a> <p> The user name of the MySQL account to use for connecting to the server. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_use-threads"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_use-threads"> <code class="option"> --use-threads= <em class="replaceable"> <code> N </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for use-threads"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --use-threads=# </code> </td> </tr> <tr> <th> Type </th> <td> Numeric </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310904880"> </a> <a class="indexterm" name="idm46045310903392"> </a> <p> Load files in parallel using <em class="replaceable"> <code> N </code> </em> threads. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_verbose"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_verbose"> <code class="option"> --verbose </code> </a> , <code class="option"> -v </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for verbose"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --verbose </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310892864"> </a> <a class="indexterm" name="idm46045310891376"> </a> <p> Verbose mode. Print more information about what the program does. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_version"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_version"> <code class="option"> --version </code> </a> , <code class="option"> -V </code> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for version"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --version </code> </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310881280"> </a> <a class="indexterm" name="idm46045310879792"> </a> <p> Display version information and exit. </p> </li> <li class="listitem"> <p> <a name="option_mysqlimport_zstd-compression-level"> </a> <a class="link" href="mysqlimport.html#option_mysqlimport_zstd-compression-level"> <code class="option"> --zstd-compression-level= <em class="replaceable"> <code> level </code> </em> </code> </a> </p> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for zstd-compression-level"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --zstd-compression-level=# </code> </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> </tbody> </table> </div> <a class="indexterm" name="idm46045310867680"> </a> <a class="indexterm" name="idm46045310866176"> </a> <p> The compression level to use for connections to the server that use the <code class="literal"> zstd </code> compression algorithm. The permitted levels are from 1 to 22, with larger values indicating increasing levels of compression. The default <code class="literal"> zstd </code> compression level is 3. The compression level setting has no effect on connections that do not use <code class="literal"> zstd </code> compression. </p> <p> For more information, see <a class="xref" href="connection-compression-control.html" title="6.2.8 Connection Compression Control"> Section 6.2.8, “Connection Compression Control” </a> . </p> </li> </ul> </div> <p> Here is a sample session that demonstrates use of <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program"> <span class="command"> <strong> mysqlimport </strong> </span> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa63524895"><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">-e</span> <span class="token atrule">'CREATE TABLE imptest(id INT, n VARCHAR(30))'</span> test <span class="token prompt">$&gt; </span><span class="token command">ed</span> a 100 Max Sydow 101 Count Dracula <span class="token punctuation">.</span> w imptest<span class="token punctuation">.</span>txt 32 q <span class="token prompt">$&gt; </span><span class="token command">od</span> <span class="token property">-c</span> imptest<span class="token punctuation">.</span>txt 0000000 1 0 0 \t M a x S y d o w \n 1 0 0000020 1 \t C o u n t D r a c u l a \n 0000040 <span class="token prompt">$&gt; </span><span class="token command">mysqlimport</span> <span class="token property">--local</span> test imptest<span class="token punctuation">.</span>txt test<span class="token punctuation">.</span>imptest<span class="token punctuation">:</span> Records<span class="token punctuation">:</span> 2 Deleted<span class="token punctuation">:</span> 0 Skipped<span class="token punctuation">:</span> 0 Warnings<span class="token punctuation">:</span> 0 <span class="token prompt">$&gt; </span><span class="token command">mysql</span> <span class="token property">-e</span> <span class="token atrule">'SELECT * FROM imptest'</span> test <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> <span class="token output"><span class="token punctuation">|</span> id <span class="token punctuation">|</span> n <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> <span class="token output"><span class="token punctuation">|</span> 100 <span class="token punctuation">|</span> Max Sydow <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 101 <span class="token punctuation">|</span> Count Dracula <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></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-statements-group.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="replication-statements-group"> </a> 15.4.3 SQL Statements for Controlling Group Replication </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="start-group-replication.html"> 15.4.3.1 START GROUP_REPLICATION Statement </a> </span> </dt> <dt> <span class="section"> <a href="stop-group-replication.html"> 15.4.3.2 STOP GROUP_REPLICATION Statement </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045176859040"> </a> <a class="indexterm" name="idm46045176857552"> </a> <a class="indexterm" name="idm46045176856064"> </a> <p> This section provides information about the statements used for controlling group replication. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-and-plugins.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="performance-schema-and-plugins"> </a> 29.18 Performance Schema and Plugins </h2> </div> </div> </div> <p> Removing a plugin with <a class="link" href="uninstall-plugin.html" title="15.7.4.6 UNINSTALL PLUGIN Statement"> <code class="literal"> UNINSTALL PLUGIN </code> </a> does not affect information already collected for code in that plugin. Time spent executing the code while the plugin was loaded was still spent even if the plugin is unloaded later. The associated event information, including aggregate information, remains readable in <code class="literal"> performance_schema </code> database tables. For additional information about the effect of plugin installation and removal, see <a class="xref" href="performance-schema-status-monitoring.html" title="29.7 Performance Schema Status Monitoring"> Section 29.7, “Performance Schema Status Monitoring” </a> . </p> <p> A plugin implementor who instruments plugin code should document its instrumentation characteristics to enable those who load the plugin to account for its requirements. For example, a third-party storage engine should include in its documentation how much memory the engine needs for mutex and other instruments. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/event-scheduler.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="event-scheduler"> </a> 27.4 Using the Event Scheduler </h2> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="events-overview.html"> 27.4.1 Event Scheduler Overview </a> </span> </dt> <dt> <span class="section"> <a href="events-configuration.html"> 27.4.2 Event Scheduler Configuration </a> </span> </dt> <dt> <span class="section"> <a href="events-syntax.html"> 27.4.3 Event Syntax </a> </span> </dt> <dt> <span class="section"> <a href="events-metadata.html"> 27.4.4 Event Metadata </a> </span> </dt> <dt> <span class="section"> <a href="events-status-info.html"> 27.4.5 Event Scheduler Status </a> </span> </dt> <dt> <span class="section"> <a href="events-privileges.html"> 27.4.6 The Event Scheduler and MySQL Privileges </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045082265648"> </a> <a class="indexterm" name="idm46045082264608"> </a> <p> The <span class="firstterm"> MySQL Event Scheduler </span> manages the scheduling and execution of events, that is, tasks that run according to a schedule. The following discussion covers the Event Scheduler and is divided into the following sections: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="events-overview.html" title="27.4.1 Event Scheduler Overview"> Section 27.4.1, “Event Scheduler Overview” </a> , provides an introduction to and conceptual overview of MySQL Events. </p> </li> <li class="listitem"> <p> <a class="xref" href="events-syntax.html" title="27.4.3 Event Syntax"> Section 27.4.3, “Event Syntax” </a> , discusses the SQL statements for creating, altering, and dropping MySQL Events. </p> </li> <li class="listitem"> <p> <a class="xref" href="events-metadata.html" title="27.4.4 Event Metadata"> Section 27.4.4, “Event Metadata” </a> , shows how to obtain information about events and how this information is stored by the MySQL Server. </p> </li> <li class="listitem"> <p> <a class="xref" href="events-privileges.html" title="27.4.6 The Event Scheduler and MySQL Privileges"> Section 27.4.6, “The Event Scheduler and MySQL Privileges” </a> , discusses the privileges required to work with events and the ramifications that events have with regard to privileges when executing. </p> </li> </ul> </div> <p> Stored routines require the <code class="literal"> events </code> data dictionary table in the <code class="literal"> mysql </code> system database. This table is created during the MySQL 8.4 installation procedure. If you are upgrading to MySQL 8.4 from an earlier version, be sure to perform the upgrade procedure to make sure that your system database is up to date. See <a class="xref" href="upgrading.html" title="Chapter 3 Upgrading MySQL"> Chapter 3, <i> Upgrading MySQL </i> </a> . </p> <h3> <a name="idm46045082251744"> </a> Additional Resources </h3> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> There are some restrictions on the use of events; see <a class="xref" href="stored-program-restrictions.html" title="27.8 Restrictions on Stored Programs"> Section 27.8, “Restrictions on Stored Programs” </a> . </p> </li> <li class="listitem"> <p> Binary logging for events takes place as described in <a class="xref" href="stored-programs-logging.html" title="27.7 Stored Program Binary Logging"> Section 27.7, “Stored Program Binary Logging” </a> . </p> </li> <li class="listitem"> <p> You may also find the <a class="ulink" href="https://forums.mysql.com/list.php?20" target="_blank"> MySQL User Forums </a> to be helpful. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/information-schema-tp-thread-group-state-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="information-schema-tp-thread-group-state-table"> </a> 28.5.2 The INFORMATION_SCHEMA TP_THREAD_GROUP_STATE Table </h3> </div> </div> </div> <a class="indexterm" name="idm46045076060800"> </a> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> The <code class="literal"> INFORMATION_SCHEMA </code> thread pool tables are deprecated, and subject to removal in a future version of MySQL. You should use the versions available as Performance Schema tables insted. See <a class="xref" href="performance-schema-thread-pool-tables.html" title="29.12.16 Performance Schema Thread Pool Tables"> Section 29.12.16, “Performance Schema Thread Pool Tables” </a> . Applications should transition away from the old tables to the new tables. For example, if an application uses this query: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa16908103"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>TP_THREAD_GROUP_STATE<span class="token punctuation">;</span></code></pre> </div> <p> The application should use this query instead: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa3420930"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>tp_thread_group_state<span class="token punctuation">;</span></code></pre> </div> </div> <p> The <code class="literal"> TP_THREAD_GROUP_STATE </code> table has one row per thread group in the thread pool. Each row provides information about the current state of a group. </p> <p> For descriptions of the columns in the <code class="literal"> INFORMATION_SCHEMA </code> <code class="literal"> TP_THREAD_GROUP_STATE </code> table, see <a class="xref" href="performance-schema-tp-thread-group-state-table.html" title="29.12.16.2 The tp_thread_group_state Table"> Section 29.12.16.2, “The tp_thread_group_state Table” </a> . The Performance Schema <a class="link" href="performance-schema-tp-thread-group-state-table.html" title="29.12.16.2 The tp_thread_group_state Table"> <code class="literal"> tp_thread_group_state </code> </a> table has equivalent columns. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/group-by-modifiers.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="group-by-modifiers"> </a> 14.19.2 GROUP BY Modifiers </h3> </div> </div> </div> <a class="indexterm" name="idm46045192776816"> </a> <a class="indexterm" name="idm46045192775744"> </a> <a class="indexterm" name="idm46045192774672"> </a> <a class="indexterm" name="idm46045192773600"> </a> <a class="indexterm" name="idm46045192772112"> </a> <p> The <code class="literal"> GROUP BY </code> clause permits a <code class="literal"> WITH ROLLUP </code> modifier that causes summary output to include extra rows that represent higher-level (that is, super-aggregate) summary operations. <code class="literal"> ROLLUP </code> thus enables you to answer questions at multiple levels of analysis with a single query. For example, <code class="literal"> ROLLUP </code> can be used to provide support for OLAP (Online Analytical Processing) operations. </p> <p> Suppose that a <code class="literal"> sales </code> table has <code class="literal"> year </code> , <code class="literal"> country </code> , <code class="literal"> product </code> , and <code class="literal"> profit </code> columns for recording sales profitability: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43138516"><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">TABLE</span> sales <span class="token punctuation">(</span> <span class="token datatype">year</span> <span class="token datatype">INT</span><span class="token punctuation">,</span> country <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> product <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span><span class="token punctuation">,</span> profit <span class="token datatype">INT</span> <span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> To summarize table contents per year, use a simple <code class="literal"> GROUP BY </code> like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86382169"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> 3010 <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></code></pre> </div> <p> The output shows the total (aggregate) profit for each year. To also determine the total profit summed over all years, you must add up the individual values yourself or run an additional query. Or you can use <code class="literal"> ROLLUP </code> , which provides both levels of analysis with a single query. Adding a <code class="literal"> WITH ROLLUP </code> modifier to the <code class="literal"> GROUP BY </code> clause causes the query to produce another (super-aggregate) row that shows the grand total over all year values: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa15470369"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span> <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 7535 <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></code></pre> </div> <p> The <code class="literal"> NULL </code> value in the <code class="literal"> year </code> column identifies the grand total super-aggregate line. </p> <p> <code class="literal"> ROLLUP </code> has a more complex effect when there are multiple <code class="literal"> GROUP BY </code> columns. In this case, each time there is a change in value in any but the last grouping column, the query produces an extra super-aggregate summary row. </p> <p> For example, without <code class="literal"> ROLLUP </code> , a summary of the <code class="literal"> sales </code> table based on <code class="literal"> year </code> , <code class="literal"> country </code> , and <code class="literal"> product </code> might look like this, where the output indicates summary values only at the year/country/product level of analysis: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa20019911"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> product <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 100 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 150 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 75 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 50 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 2700 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> TV <span class="token punctuation">|</span> 250 <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></code></pre> </div> <p> With <code class="literal"> ROLLUP </code> added, the query produces several extra rows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa67001293"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> product <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 100 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1600 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 150 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1350 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 75 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1575 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 50 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 2700 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> TV <span class="token punctuation">|</span> 250 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3000 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 7535 <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></code></pre> </div> <p> Now the output includes summary information at four levels of analysis, not just one: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Following each set of product rows for a given year and country, an extra super-aggregate summary row appears showing the total for all products. These rows have the <code class="literal"> product </code> column set to <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> Following each set of rows for a given year, an extra super-aggregate summary row appears showing the total for all countries and products. These rows have the <code class="literal"> country </code> and <code class="literal"> products </code> columns set to <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> Finally, following all other rows, an extra super-aggregate summary row appears showing the grand total for all years, countries, and products. This row has the <code class="literal"> year </code> , <code class="literal"> country </code> , and <code class="literal"> products </code> columns set to <code class="literal"> NULL </code> . </p> </li> </ul> </div> <p> The <code class="literal"> NULL </code> indicators in each super-aggregate row are produced when the row is sent to the client. The server looks at the columns named in the <code class="literal"> GROUP BY </code> clause following the leftmost one that has changed value. For any column in the result set with a name that matches any of those names, its value is set to <code class="literal"> NULL </code> . (If you specify grouping columns by column position, the server identifies which columns to set to <code class="literal"> NULL </code> by position.) </p> <p> Because the <code class="literal"> NULL </code> values in the super-aggregate rows are placed into the result set at such a late stage in query processing, you can test them as <code class="literal"> NULL </code> values only in the select list or <code class="literal"> HAVING </code> clause. You cannot test them as <code class="literal"> NULL </code> values in join conditions or the <code class="literal"> WHERE </code> clause to determine which rows to select. For example, you cannot add <code class="literal"> WHERE product IS NULL </code> to the query to eliminate from the output all but the super-aggregate rows. </p> <p> The <code class="literal"> NULL </code> values do appear as <code class="literal"> NULL </code> on the client side and can be tested as such using any MySQL client programming interface. However, at this point, you cannot distinguish whether a <code class="literal"> NULL </code> represents a regular grouped value or a super-aggregate value. To test the distinction, use the <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> function, described later. </p> <p> For <code class="literal"> GROUP BY ... WITH ROLLUP </code> queries, to test whether <code class="literal"> NULL </code> values in the result represent super-aggregate values, the <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> function is available for use in the select list, <code class="literal"> HAVING </code> clause, and <code class="literal"> ORDER BY </code> clause. For example, <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING(year) </code> </a> returns 1 when <code class="literal"> NULL </code> in the <code class="literal"> year </code> column occurs in a super-aggregate row, and 0 otherwise. Similarly, <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING(country) </code> </a> and <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING(product) </code> </a> return 1 for super-aggregate <code class="literal"> NULL </code> values in the <code class="literal"> country </code> and <code class="literal"> product </code> columns, respectively: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa73998215"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit<span class="token punctuation">,</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span><span class="token datatype">year</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> grp_year<span class="token punctuation">,</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span>country<span class="token punctuation">)</span> <span class="token keyword">AS</span> grp_country<span class="token punctuation">,</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span>product<span class="token punctuation">)</span> <span class="token keyword">AS</span> grp_product <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> product <span class="token punctuation">|</span> profit <span class="token punctuation">|</span> grp_year <span class="token punctuation">|</span> grp_country <span class="token punctuation">|</span> grp_product <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 100 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1600 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 150 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1350 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 75 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1575 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 50 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 2700 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> TV <span class="token punctuation">|</span> 250 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3000 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 7535 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 1 <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> Instead of displaying the <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> results directly, you can use <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> to substitute labels for super-aggregate <code class="literal"> NULL </code> values: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99360513"><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">SELECT</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token function">GROUPING</span><span class="token punctuation">(</span><span class="token datatype">year</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'All years'</span><span class="token punctuation">,</span> <span class="token datatype">year</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token datatype">year</span><span class="token punctuation">,</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token function">GROUPING</span><span class="token punctuation">(</span>country<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'All countries'</span><span class="token punctuation">,</span> country<span class="token punctuation">)</span> <span class="token keyword">AS</span> country<span class="token punctuation">,</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token function">GROUPING</span><span class="token punctuation">(</span>product<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'All products'</span><span class="token punctuation">,</span> product<span class="token punctuation">)</span> <span class="token keyword">AS</span> product<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> product <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 100 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 1600 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 150 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 1350 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 75 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 1575 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> All countries <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 50 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 2700 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> TV <span class="token punctuation">|</span> 250 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 3000 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> All countries <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> All years <span class="token punctuation">|</span> All countries <span class="token punctuation">|</span> All products <span class="token punctuation">|</span> 7535 <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></code></pre> </div> <p> With multiple expression arguments, <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> returns a result representing a bitmask that combines the results for each expression, with the lowest-order bit corresponding to the result for the rightmost expression. For example, <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING(year, country, product) </code> </a> is evaluated like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-clike"><div class="docs-select-all right" id="sa2509228"><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"> result <span class="token keyword">for</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span><em class="replaceable">product</em><span class="token punctuation">)</span> <span class="token operator">+</span> result <span class="token keyword">for</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span><em class="replaceable">country</em><span class="token punctuation">)</span> <span class="token operator">&lt;</span><span class="token operator">&lt;</span> <span class="token number">1</span> <span class="token operator">+</span> result <span class="token keyword">for</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span><em class="replaceable">year</em><span class="token punctuation">)</span> <span class="token operator">&lt;</span><span class="token operator">&lt;</span> <span class="token number">2</span></code></pre> </div> <p> The result of such a <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> is nonzero if any of the expressions represents a super-aggregate <code class="literal"> NULL </code> , so you can return only the super-aggregate rows and filter out the regular grouped rows like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69606547"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</span> <span class="token keyword">HAVING</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span><span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<span class="token punctuation">)</span> <span class="token operator">&lt;&gt;</span> <span class="token number">0</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> product <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1600 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1350 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1575 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3000 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 7535 <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></code></pre> </div> <p> The <code class="literal"> sales </code> table contains no <code class="literal"> NULL </code> values, so all <code class="literal"> NULL </code> values in a <code class="literal"> ROLLUP </code> result represent super-aggregate values. When the data set contains <code class="literal"> NULL </code> values, <code class="literal"> ROLLUP </code> summaries may contain <code class="literal"> NULL </code> values not only in super-aggregate rows, but also in regular grouped rows. <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> enables these to be distinguished. Suppose that table <code class="literal"> t1 </code> contains a simple data set with two grouping factors for a set of quantity values, where <code class="literal"> NULL </code> indicates something like <span class="quote"> “ <span class="quote"> other </span> ” </span> or <span class="quote"> “ <span class="quote"> unknown </span> ” </span> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7113465"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t1<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> <span class="token output"><span class="token punctuation">|</span> name <span class="token punctuation">|</span> size <span class="token punctuation">|</span> quantity <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> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> small <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> large <span class="token punctuation">|</span> 20 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 5 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> small <span class="token punctuation">|</span> 15 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> large <span class="token punctuation">|</span> 5 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3 <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></code></pre> </div> <p> A simple <code class="literal"> ROLLUP </code> operation produces these results, in which it is not so easy to distinguish <code class="literal"> NULL </code> values in super-aggregate rows from <code class="literal"> NULL </code> values in regular grouped rows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86556644"><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">SELECT</span> <span class="token keyword">name</span><span class="token punctuation">,</span> size<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>quantity<span class="token punctuation">)</span> <span class="token keyword">AS</span> quantity <span class="token keyword">FROM</span> t1 <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token keyword">name</span><span class="token punctuation">,</span> size <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> name <span class="token punctuation">|</span> size <span class="token punctuation">|</span> quantity <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> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 5 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> large <span class="token punctuation">|</span> 20 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> small <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 35 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> large <span class="token punctuation">|</span> 5 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> small <span class="token punctuation">|</span> 15 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 23 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 58 <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></code></pre> </div> <p> Using <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> to substitute labels for the super-aggregate <code class="literal"> NULL </code> values makes the result easier to interpret: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89217868"><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">SELECT</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token function">GROUPING</span><span class="token punctuation">(</span><span class="token keyword">name</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'All items'</span><span class="token punctuation">,</span> <span class="token keyword">name</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">name</span><span class="token punctuation">,</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token function">GROUPING</span><span class="token punctuation">(</span>size<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'All sizes'</span><span class="token punctuation">,</span> size<span class="token punctuation">)</span> <span class="token keyword">AS</span> size<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>quantity<span class="token punctuation">)</span> <span class="token keyword">AS</span> quantity <span class="token keyword">FROM</span> t1 <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token keyword">name</span><span class="token punctuation">,</span> size <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> name <span class="token punctuation">|</span> size <span class="token punctuation">|</span> quantity <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> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 5 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> large <span class="token punctuation">|</span> 20 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> small <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> ball <span class="token punctuation">|</span> All sizes <span class="token punctuation">|</span> 35 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> large <span class="token punctuation">|</span> 5 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> small <span class="token punctuation">|</span> 15 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> hoop <span class="token punctuation">|</span> All sizes <span class="token punctuation">|</span> 23 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> All items <span class="token punctuation">|</span> All sizes <span class="token punctuation">|</span> 58 <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></code></pre> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="group-by-modifiers-other-considerations-when-using-rollup"> </a> Other Considerations When using ROLLUP </h4> </div> </div> </div> <p> The following discussion lists some behaviors specific to the MySQL implementation of <code class="literal"> ROLLUP </code> . </p> <p> <code class="literal"> ORDER BY </code> and <code class="literal"> ROLLUP </code> can be used together, which enables the use of <code class="literal"> ORDER BY </code> and <a class="link" href="miscellaneous-functions.html#function_grouping"> <code class="literal"> GROUPING() </code> </a> to achieve a specific sort order of grouped results. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa5297568"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span> <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</span> <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> <span class="token function">GROUPING</span><span class="token punctuation">(</span><span class="token datatype">year</span><span class="token punctuation">)</span> <span class="token keyword">DESC</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 7535 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> 3010 <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></code></pre> </div> <p> In both cases, the super-aggregate summary rows sort with the rows from which they are calculated, and their placement depends on sort order (at the end for ascending sort, at the beginning for descending sort). </p> <p> <code class="literal"> LIMIT </code> can be used to restrict the number of rows returned to the client. <code class="literal"> LIMIT </code> is applied after <code class="literal"> ROLLUP </code> , so the limit applies against the extra rows added by <code class="literal"> ROLLUP </code> . For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68469933"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> product <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</span> <span class="token keyword">LIMIT</span> <span class="token number">5</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> product <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 100 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 1600 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 150 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <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></code></pre> </div> <p> Using <code class="literal"> LIMIT </code> with <code class="literal"> ROLLUP </code> may produce results that are more difficult to interpret, because there is less context for understanding the super-aggregate rows. </p> <p> A MySQL extension permits a column that does not appear in the <code class="literal"> GROUP BY </code> list to be named in the select list. (For information about nonaggregated columns and <code class="literal"> GROUP BY </code> , see <a class="xref" href="group-by-handling.html" title="14.19.3 MySQL Handling of GROUP BY"> Section 14.19.3, “MySQL Handling of GROUP BY” </a> .) In this case, the server is free to choose any value from this nonaggregated column in summary rows, and this includes the extra rows added by <code class="literal"> WITH ROLLUP </code> . For example, in the following query, <code class="literal"> country </code> is a nonaggregated column that does not appear in the <code class="literal"> GROUP BY </code> list and values chosen for this column are nondeterministic: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68023766"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> country<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span> <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> 7535 <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></code></pre> </div> <p> This behavior is permitted when the <a class="link" href="sql-mode.html#sqlmode_only_full_group_by"> <code class="literal"> ONLY_FULL_GROUP_BY </code> </a> SQL mode is not enabled. If that mode is enabled, the server rejects the query as illegal because <code class="literal"> country </code> is not listed in the <code class="literal"> GROUP BY </code> clause. With <a class="link" href="sql-mode.html#sqlmode_only_full_group_by"> <code class="literal"> ONLY_FULL_GROUP_BY </code> </a> enabled, you can still execute the query by using the <a class="link" href="miscellaneous-functions.html#function_any-value"> <code class="literal"> ANY_VALUE() </code> </a> function for nondeterministic-value columns: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22868350"><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">SELECT</span> <span class="token datatype">year</span><span class="token punctuation">,</span> <span class="token function">ANY_VALUE</span><span class="token punctuation">(</span>country<span class="token punctuation">)</span> <span class="token keyword">AS</span> country<span class="token punctuation">,</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> profit <span class="token keyword">FROM</span> sales <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token datatype">year</span> <span class="token keyword">WITH</span> <span class="token keyword">ROLLUP</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> <span class="token output"><span class="token punctuation">|</span> year <span class="token punctuation">|</span> country <span class="token punctuation">|</span> profit <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> <span class="token output"><span class="token punctuation">|</span> 2000 <span class="token punctuation">|</span> India <span class="token punctuation">|</span> 4525 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> 3010 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> 7535 <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></code></pre> </div> <p> A rollup column cannot be used as an argument to <a class="link" href="fulltext-search.html#function_match"> <code class="literal"> MATCH() </code> </a> (and is rejected with an error) except when called in a <code class="literal"> WHERE </code> clause. See <a class="xref" href="fulltext-search.html" title="14.9 Full-Text Search Functions"> Section 14.9, “Full-Text Search Functions” </a> , for more information. </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/error-log-json.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="error-log-json"> </a> 7.4.2.7 Error Logging in JSON Format </h4> </div> </div> </div> <p> This section describes how to configure error logging using the built-in filter, <code class="literal"> log_filter_internal </code> , and the JSON sink, <code class="literal"> log_sink_json </code> , to take effect immediately and for subsequent server startups. For general information about configuring error logging, see <a class="xref" href="error-log-configuration.html" title="7.4.2.1 Error Log Configuration"> Section 7.4.2.1, “Error Log Configuration” </a> . </p> <p> To enable the JSON sink, first load the sink component, then modify the <a class="link" href="server-system-variables.html#sysvar_log_error_services"> <code class="literal"> log_error_services </code> </a> value: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63246492"><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">INSTALL</span> <span class="token keyword">COMPONENT</span> <span class="token string">'file://component_log_sink_json'</span><span class="token punctuation">;</span> <span class="token keyword">SET</span> <span class="token keyword">PERSIST</span> log_error_services <span class="token operator">=</span> <span class="token string">'log_filter_internal; log_sink_json'</span><span class="token punctuation">;</span></code></pre> </div> <p> To set <a class="link" href="server-system-variables.html#sysvar_log_error_services"> <code class="literal"> log_error_services </code> </a> to take effect at server startup, use the instructions at <a class="xref" href="error-log-configuration.html" title="7.4.2.1 Error Log Configuration"> Section 7.4.2.1, “Error Log Configuration” </a> . Those instructions apply to other error-logging system variables as well. </p> <p> It is permitted to name <code class="literal"> log_sink_json </code> multiple times in the <a class="link" href="server-system-variables.html#sysvar_log_error_services"> <code class="literal"> log_error_services </code> </a> value. For example, to write unfiltered events with one instance and filtered events with another instance, you could set <a class="link" href="server-system-variables.html#sysvar_log_error_services"> <code class="literal"> log_error_services </code> </a> like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa97604783"><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">PERSIST</span> log_error_services <span class="token operator">=</span> <span class="token string">'log_sink_json; log_filter_internal; log_sink_json'</span><span class="token punctuation">;</span></code></pre> </div> <p> The JSON sink determines its output destination based on the default error log destination, which is given by the <a class="link" href="server-system-variables.html#sysvar_log_error"> <code class="literal"> log_error </code> </a> system variable. If <a class="link" href="server-system-variables.html#sysvar_log_error"> <code class="literal"> log_error </code> </a> names a file, the JSON sink bases output file naming on that file name, plus a numbered <code class="filename"> . <em class="replaceable"> <code> NN </code> </em> .json </code> suffix, with <em class="replaceable"> <code> NN </code> </em> starting at 00. For example, if <a class="link" href="server-system-variables.html#sysvar_log_error"> <code class="literal"> log_error </code> </a> is <em class="replaceable"> <code> file_name </code> </em> , successive instances of <code class="literal"> log_sink_json </code> named in the <a class="link" href="server-system-variables.html#sysvar_log_error_services"> <code class="literal"> log_error_services </code> </a> value write to <code class="filename"> <em class="replaceable"> <code> file_name </code> </em> .00.json </code> , <code class="filename"> <em class="replaceable"> <code> file_name </code> </em> .01.json </code> , and so forth. </p> <p> If <a class="link" href="server-system-variables.html#sysvar_log_error"> <code class="literal"> log_error </code> </a> is <code class="literal"> stderr </code> , the JSON sink writes to the console. If <code class="literal"> log_sink_json </code> is named multiple times in the <a class="link" href="server-system-variables.html#sysvar_log_error_services"> <code class="literal"> log_error_services </code> </a> value, they all write to the console, which is likely not useful. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-limitations.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="mysql-cluster-limitations"> </a> 25.2.7 Known Limitations of NDB Cluster </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="mysql-cluster-limitations-syntax.html"> 25.2.7.1 Noncompliance with SQL Syntax in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-limits.html"> 25.2.7.2 Limits and Differences of NDB Cluster from Standard MySQL Limits </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-transactions.html"> 25.2.7.3 Limits Relating to Transaction Handling in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-error-handling.html"> 25.2.7.4 NDB Cluster Error Handling </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-database-objects.html"> 25.2.7.5 Limits Associated with Database Objects in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-unsupported.html"> 25.2.7.6 Unsupported or Missing Features in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-performance.html"> 25.2.7.7 Limitations Relating to Performance in NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-exclusive-to-cluster.html"> 25.2.7.8 Issues Exclusive to NDB Cluster </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-disk-data.html"> 25.2.7.9 Limitations Relating to NDB Cluster Disk Data Storage </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-multiple-nodes.html"> 25.2.7.10 Limitations Relating to Multiple NDB Cluster Nodes </a> </span> </dt> <dt> <span class="section"> <a href="mysql-cluster-limitations-resolved.html"> 25.2.7.11 Previous NDB Cluster Issues Resolved in NDB Cluster 8.4 </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045123675120"> </a> <a class="indexterm" name="idm46045123674048"> </a> <p> In the sections that follow, we discuss known limitations in current releases of NDB Cluster as compared with the features available when using the <code class="literal"> MyISAM </code> and <code class="literal"> InnoDB </code> storage engines. If you check the <span class="quote"> “ <span class="quote"> Cluster </span> ” </span> category in the MySQL bugs database at <a class="ulink" href="http://bugs.mysql.com" target="_blank"> http://bugs.mysql.com </a> , you can find known bugs in the following categories under <span class="quote"> “ <span class="quote"> MySQL Server: </span> ” </span> in the MySQL bugs database at <a class="ulink" href="http://bugs.mysql.com" target="_blank"> http://bugs.mysql.com </a> , which we intend to correct in upcoming releases of NDB Cluster: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> NDB Cluster </p> </li> <li class="listitem"> <p> Cluster Direct API (NDBAPI) </p> </li> <li class="listitem"> <p> Cluster Disk Data </p> </li> <li class="listitem"> <p> Cluster Replication </p> </li> <li class="listitem"> <p> ClusterJ </p> </li> </ul> </div> <p> This information is intended to be complete with respect to the conditions just set forth. You can report any discrepancies that you encounter to the MySQL bugs database using the instructions given in <a class="xref" href="bug-reports.html" title="1.6 How to Report Bugs or Problems"> Section 1.6, “How to Report Bugs or Problems” </a> . Any problem which we do not plan to fix in NDB Cluster 8.4, is added to the list. </p> <p> See <a class="xref" href="mysql-cluster-limitations-resolved.html" title="25.2.7.11 Previous NDB Cluster Issues Resolved in NDB Cluster 8.4"> Section 25.2.7.11, “Previous NDB Cluster Issues Resolved in NDB Cluster 8.4” </a> for a list of issues in earlier releases that have been resolved in NDB Cluster 8.4. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Limitations and other issues specific to NDB Cluster Replication are described in <a class="xref" href="mysql-cluster-replication-issues.html" title="25.7.3 Known Issues in NDB Cluster Replication"> Section 25.7.3, “Known Issues in NDB Cluster Replication” </a> . </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/added-deprecated-removed.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="added-deprecated-removed"> </a> 1.5 Server and Status Variables and Options Added, Deprecated, or Removed in MySQL 8.4 since 8.0 </h2> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="added-deprecated-removed.html#optvars-added" title="Options and Variables Introduced in MySQL 8.4"> Options and Variables Introduced in MySQL 8.4 </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="added-deprecated-removed.html#optvars-deprecated" title="Options and Variables Deprecated in MySQL 8.4"> Options and Variables Deprecated in MySQL 8.4 </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="added-deprecated-removed.html#optvars-removed" title="Options and Variables Removed in MySQL 8.4"> Options and Variables Removed in MySQL 8.4 </a> </p> </li> </ul> </div> <p> This section lists server variables, status variables, and options that were added for the first time, have been deprecated, or have been removed in MySQL 8.4 since 8.0. </p> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="optvars-added"> </a> Options and Variables Introduced in MySQL 8.4 </h3> </div> </div> </div> <p> The following system variables, status variables, and server options have been added in MySQL 8.4. </p> <div class="itemizedlist"> <a name="optvars-added-list"> </a> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> <a class="link" href="audit-log-reference.html#statvar_Audit_log_direct_writes"> Audit_log_direct_writes </a> </code> : Number of direct writes to the audit log file. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_Com_xxx"> Com_show_binary_log_status </a> </code> : Count of SHOW BINARY LOG STATUS statements; use instead of Com_show_master_status. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_Deprecated_use_i_s_processlist_count"> Deprecated_use_i_s_processlist_count </a> </code> : Number of times Information Schema processlist table has been accessed. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_Deprecated_use_i_s_processlist_last_timestamp"> Deprecated_use_i_s_processlist_last_timestamp </a> </code> : Time of most recent access to Information Schema processlist table (timestamp). Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_all_consensus_proposals_count"> Gr_all_consensus_proposals_count </a> </code> : Sum of all proposals that were initiated and terminated in this node. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_all_consensus_time_sum"> Gr_all_consensus_time_sum </a> </code> : The sum of elapsed time of all consensus rounds started and finished in this node. Togheter with count_all_consensus_proposals, we can identify if the individual consensus time has a trend of going up, thus signaling a possible problem. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_certification_garbage_collector_count"> Gr_certification_garbage_collector_count </a> </code> : Number of times certification garbage collection did run. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_certification_garbage_collector_time_sum"> Gr_certification_garbage_collector_time_sum </a> </code> : Sum of the time in micro-seconds that certification garbage collection runs took. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_consensus_bytes_received_sum"> Gr_consensus_bytes_received_sum </a> </code> : The sum of all socket-level bytes that were received to from group nodes having as a destination this node. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_consensus_bytes_sent_sum"> Gr_consensus_bytes_sent_sum </a> </code> : Sum of all socket-level bytes that were sent to all group nodes originating on this node. Socket-level bytes mean that we will report more data here than in the sent messages, because they are multiplexed and sent to each member. As an example, if we have a group with 3 members and we send a 100 bytes message, this value will account for 300 bytes, since we send 100 bytes to each node. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_control_messages_sent_bytes_sum"> Gr_control_messages_sent_bytes_sum </a> </code> : Sum of bytes of control messages sent by this member. The size is the on-the-wire size. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_control_messages_sent_count"> Gr_control_messages_sent_count </a> </code> : Number of control messages sent by this member. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_control_messages_sent_roundtrip_time_sum"> Gr_control_messages_sent_roundtrip_time_sum </a> </code> : Sum of the roundtrip time in micro-seconds of control messages sent by this member. The time is measured between the send and the delivery of the message on the sender member. This time will measure the time between the send and the delivery of the message on the majority of the members of the group (that includes the sender). Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_data_messages_sent_bytes_sum"> Gr_data_messages_sent_bytes_sum </a> </code> : Sum of bytes of data messages sent by this member. The size is the on-the-wire size. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_data_messages_sent_count"> Gr_data_messages_sent_count </a> </code> : Number of data messages sent by this member. Counts the number of transaction data messages sent. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_data_messages_sent_roundtrip_time_sum"> Gr_data_messages_sent_roundtrip_time_sum </a> </code> : Sum of the roundtrip time in micro-seconds of data messages sent by this member. The time is measured between the send and the delivery of the message on the sender member. This time will measure the time between the send and the delivery of the message on the majority of the members of the group (that includes the sender). Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_empty_consensus_proposals_count"> Gr_empty_consensus_proposals_count </a> </code> : Sum of all empty proposal rounds that were initiated and terminated in this node. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_extended_consensus_count"> Gr_extended_consensus_count </a> </code> : The number of full 3-Phase PAXOS that this node initiated. If this number grows, it means that at least of the node is having issues answering to Proposals, either by slowliness or network issues. Use togheter with count_member_failure_suspicions to try and do some diagnose. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_last_consensus_end_timestamp"> Gr_last_consensus_end_timestamp </a> </code> : The time in which our last consensus proposal was approved. Reported in a timestamp format. This is an indicator if the group is halted or making slow progress. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_total_messages_sent_count"> Gr_total_messages_sent_count </a> </code> : The number of high-level messages that this node sent to the group. These messages are the ones the we receive via the API to be proposed to the group. XCom has a batching mechanism, that will gather these messages and propose them all togheter. This will acocunt the number of message before being batched. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_transactions_consistency_after_sync_count"> Gr_transactions_consistency_after_sync_count </a> </code> : Number of transactions on secondaries that waited to start, while waiting for transactions from the primary with group_replication_consistency= AFTER and BEFORE_AND_AFTER to be committed. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_transactions_consistency_after_sync_time_sum"> Gr_transactions_consistency_after_sync_time_sum </a> </code> : Sum of the time in micro-seconds that transactions on secondaries waited to start, while waiting for transactions from the primary with group_replication_consistency= AFTER and BEFORE_AND_AFTER to be committed. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_transactions_consistency_after_termination_count"> Gr_transactions_consistency_after_termination_count </a> </code> : Number of transactions executed with group_replication_consistency= AFTER and BEFORE_AND_AFTER. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_transactions_consistency_after_termination_time_sum"> Gr_transactions_consistency_after_termination_time_sum </a> </code> : Sum of the time in micro-seconds spent between the delivery of the transaction executed with group_replication_consistency=AFTER and BEFORE_AND_AFTER, and the acknowledge of the other group members that the transaction is prepared. It does not include the transaction send roundtrip time. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_transactions_consistency_before_begin_count"> Gr_transactions_consistency_before_begin_count </a> </code> : Number of transactions executed with group_replication_consistency= BEFORE and BEFORE_AND_AFTER. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-status-variables.html#statvar_Gr_transactions_consistency_before_begin_time_sum"> Gr_transactions_consistency_before_begin_time_sum </a> </code> : Sum of the time in micro-seconds that the member waited until its group_replication_applier channel was consumed before execute the transaction with group_replication_consistency= BEFORE and BEFORE_AND_AFTER. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="performance-schema-status-variables.html#statvar_Performance_schema_meter_lost"> Performance_schema_meter_lost </a> </code> : Number of meter instruments that failed to be created. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="performance-schema-status-variables.html#statvar_Performance_schema_metric_lost"> Performance_schema_metric_lost </a> </code> : Number of metric instruments that failed to be created. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_Telemetry_metrics_supported"> Telemetry_metrics_supported </a> </code> : Whether server telemetry metrics is supported. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_Tls_sni_server_name"> Tls_sni_server_name </a> </code> : Server name supplied by the client. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="pluggable-authentication-system-variables.html#sysvar_authentication_ldap_sasl_connect_timeout"> authentication_ldap_sasl_connect_timeout </a> </code> : SASL-Based LDAP server connection timeout. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="pluggable-authentication-system-variables.html#sysvar_authentication_ldap_sasl_response_timeout"> authentication_ldap_sasl_response_timeout </a> </code> : Simple LDAP server response timeout. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="pluggable-authentication-system-variables.html#sysvar_authentication_ldap_simple_connect_timeout"> authentication_ldap_simple_connect_timeout </a> </code> : Simple LDAP server connection timeout. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="pluggable-authentication-system-variables.html#sysvar_authentication_ldap_simple_response_timeout"> authentication_ldap_simple_response_timeout </a> </code> : Simple LDAP server response timeout. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="pluggable-authentication-system-variables.html#sysvar_authentication_webauthn_rp_id"> authentication_webauthn_rp_id </a> </code> : Relying party ID for multifactor authentication. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="data-masking-component-variables.html#sysvar_component_masking.dictionaries_flush_interval_seconds"> component_masking.dictionaries_flush_interval_seconds </a> </code> : How long for scheduler to wait until attempting to schedule next execution, in seconds. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="data-masking-component-variables.html#sysvar_component_masking.masking_database"> component_masking.masking_database </a> </code> : Database to use for masking dictionaries. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_preemptive_garbage_collection"> group_replication_preemptive_garbage_collection </a> </code> : Enable preemptive garbage collection in single-primary mode; no effect in multi-primary mode. Added in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_preemptive_garbage_collection_rows_threshold"> group_replication_preemptive_garbage_collection_rows_threshold </a> </code> : Number of rows of certification information required to trigger preemptive garbage collection in single-primary mode when enabled by group_replication_preemptive_garbage_collection. Added in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="keyring-options.html#option_mysqld_keyring-migration-from-component"> keyring-migration-from-component </a> </code> : Keyring migration is from component to plugin. Added in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-options.html#option_mysqld_mysql-native-password"> mysql-native-password </a> </code> : Enable mysql_native_password authentication plugin. Added in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="firewall-reference.html#sysvar_mysql_firewall_database"> mysql_firewall_database </a> </code> : The database from which MySQL Enterprise Firewall sources its tables and stored procedures. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="firewall-reference.html#sysvar_mysql_firewall_reload_interval_seconds"> mysql_firewall_reload_interval_seconds </a> </code> : Reload data at specified intervals. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="performance-schema-system-variables.html#sysvar_performance_schema_max_meter_classes"> performance_schema_max_meter_classes </a> </code> : Maximum number of meter instruments which can be created. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="performance-schema-system-variables.html#sysvar_performance_schema_max_metric_classes"> performance_schema_max_metric_classes </a> </code> : Maximum number of metric instruments which can be created. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-system-variables.html#sysvar_restrict_fk_on_non_standard_key"> restrict_fk_on_non_standard_key </a> </code> : Disallow creation of foreign keys on non-unique or partial keys. Added in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-system-variables.html#sysvar_set_operations_buffer_size"> set_operations_buffer_size </a> </code> : Amount of memory available for hashing of set operations. Added in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_telemetry.live_sessions"> telemetry.live_sessions </a> </code> : Displays the current number of sessions instrumented with telemetry. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.metrics_reader_frequency_1"> telemetry.metrics_reader_frequency_1 </a> </code> : . Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.metrics_reader_frequency_2"> telemetry.metrics_reader_frequency_2 </a> </code> : . Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.metrics_reader_frequency_3"> telemetry.metrics_reader_frequency_3 </a> </code> : . Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_bsp_max_export_batch_size"> telemetry.otel_bsp_max_export_batch_size </a> </code> : Maximum batch size. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_bsp_max_queue_size"> telemetry.otel_bsp_max_queue_size </a> </code> : Maximum queue size. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_bsp_schedule_delay"> telemetry.otel_bsp_schedule_delay </a> </code> : Delay interval between two consecutive exports in milliseconds. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_certificates"> telemetry.otel_exporter_otlp_metrics_certificates </a> </code> : The trusted certificate to use when verifying a server's TLS credentials. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_cipher"> telemetry.otel_exporter_otlp_metrics_cipher </a> </code> : TLS cipher to use for metrics (TLS 1.2). Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_cipher_suite"> telemetry.otel_exporter_otlp_metrics_cipher_suite </a> </code> : TLS cipher to use for metrics (TLS 1.3). Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_client_certificates"> telemetry.otel_exporter_otlp_metrics_client_certificates </a> </code> : Client certificate/chain trust for clients private key in PEM format. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_client_key"> telemetry.otel_exporter_otlp_metrics_client_key </a> </code> : Client's private key in PEM format. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_compression"> telemetry.otel_exporter_otlp_metrics_compression </a> </code> : Compression used by exporter. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_endpoint"> telemetry.otel_exporter_otlp_metrics_endpoint </a> </code> : Metrics endpoint URL. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_headers"> telemetry.otel_exporter_otlp_metrics_headers </a> </code> : Key-value pairs to be used as headers associated with HTTP requests. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_min_tls"> telemetry.otel_exporter_otlp_metrics_max_tls </a> </code> : Maximum TLS version to use for metrics. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_min_tls"> telemetry.otel_exporter_otlp_metrics_min_tls </a> </code> : Minimum TLS version to use for metrics. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_protocol"> telemetry.otel_exporter_otlp_metrics_protocol </a> </code> : Specifies the OTLP transport protocol. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-metrics-configuration.html#sysvar_telemetry.otel_exporter_otlp_metrics_timeout"> telemetry.otel_exporter_otlp_metrics_timeout </a> </code> : Time OLTP exporter waits for each batch export. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_certificates"> telemetry.otel_exporter_otlp_traces_certificates </a> </code> : The trusted certificate to use when verifying a server's TLS credentials.. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_cipher"> telemetry.otel_exporter_otlp_traces_cipher </a> </code> : TLS cipher to use for traces (TLS 1.2). Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_cipher_suite"> telemetry.otel_exporter_otlp_traces_cipher_suite </a> </code> : TLS cipher to use for traces (TLS 1.3). Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_client_certificates"> telemetry.otel_exporter_otlp_traces_client_certificates </a> </code> : Client certificate/chain trust for clients private key in PEM format.. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_client_key"> telemetry.otel_exporter_otlp_traces_client_key </a> </code> : Client's private key in PEM format.. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_compression"> telemetry.otel_exporter_otlp_traces_compression </a> </code> : Compression used by exporter. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_endpoint"> telemetry.otel_exporter_otlp_traces_endpoint </a> </code> : Target URL to which the exporter sends traces. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_headers"> telemetry.otel_exporter_otlp_traces_headers </a> </code> : Key-value pairs to be used as headers associated with HTTP requests. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_max_tls"> telemetry.otel_exporter_otlp_traces_max_tls </a> </code> : Maximum TLS version to use for traces. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_min_tls"> telemetry.otel_exporter_otlp_traces_min_tls </a> </code> : Minimum TLS version to use for traces. Added in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_protocol"> telemetry.otel_exporter_otlp_traces_protocol </a> </code> : OTLP transport protocol. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_exporter_otlp_traces_timeout"> telemetry.otel_exporter_otlp_traces_timeout </a> </code> : Time OLTP exporter waits for each batch export. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_log_level"> telemetry.otel_log_level </a> </code> : Controls which opentelemetry logs are printed in the server logs (Linux only). Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.otel_resource_attributes"> telemetry.otel_resource_attributes </a> </code> : See corresponding OpenTelemetry variable OTEL_RESOURCE_ATTRIBUTES.. Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.query_text_enabled"> telemetry.query_text_enabled </a> </code> : Controls whether the SQL query text is included in the trace (Linux only). Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="telemetry-trace-configuration.html#sysvar_telemetry.trace_enabled"> telemetry.trace_enabled </a> </code> : Controls whether telemetry traces are collected or not (Linux only). Added in MySQL 8.1.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-system-variables.html#sysvar_thread_pool_longrun_trx_limit"> thread_pool_longrun_trx_limit </a> </code> : When all threads using thread_pool_max_transactions_limit have been executing longer than this number of milliseconds, limit for group is suspended. Added in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-system-variables.html#sysvar_tls_certificates_enforced_validation"> tls_certificates_enforced_validation </a> </code> : Whether to validate server and CA certificates. Added in MySQL 8.1.0. </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="optvars-deprecated"> </a> Options and Variables Deprecated in MySQL 8.4 </h3> </div> </div> </div> <p> The following system variables, status variables, and options have been deprecated in MySQL 8.4. </p> <div class="itemizedlist"> <a name="optvars-deprecated-list"> </a> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> Com_show_master_status </code> : Count of SHOW MASTER STATUS statements. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> authentication_fido_rp_id </code> : Relying party ID for FIDO multifactor authentication. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> binlog_transaction_dependency_tracking </code> : Source of dependency information (commit timestamps or transaction write sets) from which to assess which transactions can be executed in parallel by replica's multithreaded applier. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="ulink" href="/doc/refman/8.0/en/server-options.html#option_mysqld_character-set-client-handshake" target="_top"> character-set-client-handshake </a> </code> : Do not ignore client side character set value sent during handshake. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_allow_local_lower_version_join"> group_replication_allow_local_lower_version_join </a> </code> : Allow current server to join group even if it has lower plugin version than group. Deprecated in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_view_change_uuid"> group_replication_view_change_uuid </a> </code> : UUID for view change event GTIDs. Deprecated in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-options.html#option_mysqld_mysql-native-password"> mysql-native-password </a> </code> : Enable mysql_native_password authentication plugin. Deprecated in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> new </code> : Use very new, possibly 'unsafe' functions. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> old </code> : Cause server to revert to certain behaviors present in older versions. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="performance-schema-system-variables.html#sysvar_performance_schema_show_processlist"> performance_schema_show_processlist </a> </code> : Select SHOW PROCESSLIST implementation. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-system-variables.html#sysvar_restrict_fk_on_non_standard_key"> restrict_fk_on_non_standard_key </a> </code> : Disallow creation of foreign keys on non-unique or partial keys. Deprecated in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="ulink" href="/doc/refman/8.0/en/server-options.html#option_mysqld_character-set-client-handshake" target="_top"> skip-character-set-client-handshake </a> </code> : Ignore client side character set value sent during handshake. Deprecated in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-options.html#option_mysqld_skip-new"> skip-new </a> </code> : Do not use new, possibly wrong routines. Deprecated in MySQL 8.2.0. </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="optvars-removed"> </a> Options and Variables Removed in MySQL 8.4 </h3> </div> </div> </div> <p> The following system variables, status variables, and options have been removed in MySQL 8.4. </p> <div class="itemizedlist"> <a name="optvars-removed-list"> </a> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> Com_change_master </code> : Count of CHANGE REPLICATION SOURCE TO and CHANGE MASTER TO statements. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> Com_show_master_status </code> : Count of SHOW MASTER STATUS statements. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> Com_show_slave_hosts </code> : Count of SHOW REPLICAS and SHOW SLAVE HOSTS statements. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> Com_show_slave_status </code> : Count of SHOW REPLICA STATUS and SHOW SLAVE STATUS statements. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> Com_slave_start </code> : Count of START REPLICA and START SLAVE statements. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> Com_slave_stop </code> : Count of STOP REPLICA and STOP SLAVE statements. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> Replica_rows_last_search_algorithm_used </code> : Search algorithm most recently used by this replica to locate rows for row-based replication (index, table, or hash scan). Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> abort-slave-event-count </code> : Option used by mysql-test for debugging and testing of replication. Removed in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> admin-ssl </code> : Enable connection encryption. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> authentication_fido_rp_id </code> : Relying party ID for FIDO multifactor authentication. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> avoid_temporal_upgrade </code> : Whether ALTER TABLE should upgrade pre-5.6.4 temporal columns. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> binlog_transaction_dependency_tracking </code> : Source of dependency information (commit timestamps or transaction write sets) from which to assess which transactions can be executed in parallel by replica's multithreaded applier. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> character-set-client-handshake </code> : Do not ignore client side character set value sent during handshake. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> daemon_memcached_enable_binlog </code> : . Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> daemon_memcached_engine_lib_name </code> : Shared library implementing InnoDB memcached plugin. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> daemon_memcached_engine_lib_path </code> : Directory which contains shared library implementing InnoDB memcached plugin. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> daemon_memcached_option </code> : Space-separated options which are passed to underlying memcached daemon on startup. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> daemon_memcached_r_batch_size </code> : Specifies how many memcached read operations to perform before doing COMMIT to start new transaction. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> daemon_memcached_w_batch_size </code> : Specifies how many memcached write operations to perform before doing COMMIT to start new transaction. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> default_authentication_plugin </code> : Default authentication plugin. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> disconnect-slave-event-count </code> : Option used by mysql-test for debugging and testing of replication. Removed in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> expire_logs_days </code> : Purge binary logs after this many days. Removed in MySQL 8.2.0. </p> </li> <li class="listitem"> <p> <code class="literal"> group_replication_ip_whitelist </code> : List of hosts permitted to connect to group. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> group_replication_primary_member </code> : Primary member UUID when group operates in single-primary mode. Empty string if group is operating in multi-primary mode. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> group_replication_recovery_complete_at </code> : Recovery policies when handling cached transactions after state transfer. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> have_openssl </code> : Whether mysqld supports SSL connections. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> have_ssl </code> : Whether mysqld supports SSL connections. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> innodb </code> : Enable InnoDB (if this version of MySQL supports it). Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> innodb_api_bk_commit_interval </code> : How often to auto-commit idle connections which use InnoDB memcached interface, in seconds. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> innodb_api_disable_rowlock </code> : . Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> innodb_api_enable_binlog </code> : Allows use of InnoDB memcached plugin with MySQL binary log. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> innodb_api_enable_mdl </code> : Locks table used by InnoDB memcached plugin, so that it cannot be dropped or altered by DDL through SQL interface. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> innodb_api_trx_level </code> : Allows control of transaction isolation level on queries processed by memcached interface. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_encrypted_file_data </code> : keyring_encrypted_file plugin data file. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_encrypted_file_password </code> : keyring_encrypted_file plugin password. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_file_data </code> : keyring_file plugin data file. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_ca_certificate </code> : CA certificate file for peer authentication. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_compartment </code> : OCI compartment OCID. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_encryption_endpoint </code> : OCI encryption server endpoint. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_key_file </code> : OCI RSA private key file. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_key_fingerprint </code> : OCI RSA private key file fingerprint. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_management_endpoint </code> : OCI management server endpoint. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_master_key </code> : OCI master key OCID. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_secrets_endpoint </code> : OCI secrets server endpoint. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_tenancy </code> : OCI tenancy OCID. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_user </code> : OCI user OCID. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_vaults_endpoint </code> : OCI vaults server endpoint. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> keyring_oci_virtual_vault </code> : OCI vault OCID. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> language </code> : Client error messages in given language. May be given as full path. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> log_bin_use_v1_row_events </code> : Whether server is using version 1 binary log row events. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> master-info-file </code> : Location and name of file that remembers source and where I/O replication thread is in source's binary log. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> master_info_repository </code> : Whether to write connection metadata repository, containing source information and replication I/O thread location in source's binary log, to file or table. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> new </code> : Use very new, possibly 'unsafe' functions. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> no-dd-upgrade </code> : Prevent automatic upgrade of data dictionary tables at startup. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> old </code> : Cause server to revert to certain behaviors present in older versions. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> old-style-user-limits </code> : Enable old-style user limits (before 5.0.3, user resources were counted per each user+host vs. per account). Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> relay_log_info_file </code> : File name for applier metadata repository in which replica records information about relay logs. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> relay_log_info_repository </code> : Whether to write location of replication SQL thread in relay logs to file or table. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> show_old_temporals </code> : Whether SHOW CREATE TABLE should indicate pre-5.6.4 temporal columns. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> skip-character-set-client-handshake </code> : Ignore client side character set value sent during handshake. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> skip-host-cache </code> : Do not cache host names. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> skip-ssl </code> : Disable connection encryption. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> slave_rows_search_algorithms </code> : Determines search algorithms used for replica update batching. Any 2 or 3 from this list: INDEX_SEARCH, TABLE_SCAN, HASH_SCAN. Removed in MySQL 8.3.0. </p> </li> <li class="listitem"> <p> <code class="literal"> ssl </code> : Enable connection encryption. Removed in MySQL 8.4.0. </p> </li> <li class="listitem"> <p> <code class="literal"> transaction_write_set_extraction </code> : Defines algorithm used to hash writes extracted during transaction. Removed in MySQL 8.3.0. </p> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/selinux-policies.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="selinux-policies"> </a> 8.7.3 MySQL Server SELinux Policies </h3> </div> </div> </div> <a class="indexterm" name="idm46045231621552"> </a> <p> MySQL Server SELinux policy modules are typically installed by default. You can view installed modules using the <span class="command"> <strong> semodule -l </strong> </span> command. MySQL Server SELinux policy modules include: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> mysqld_selinux </code> </p> </li> <li class="listitem"> <p> <code class="literal"> mysqld_safe_selinux </code> </p> </li> </ul> </div> <p> For information about MySQL Server SELinux policy modules, refer to the SELinux manual pages. The manual pages provide information about types and Booleans associated with the MySQL service. Manual pages are named in the <code class="literal"> <em class="replaceable"> <code> service-name </code> </em> _selinux </code> format. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa66526400"><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">man mysqld_selinux</code></pre> </div> <p> If SELinux manual pages are not available, refer to your distribution's SELinux documentation for information about how to generate manual pages using the <code class="literal"> sepolicy manpage </code> utility. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-administration-pausing.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-administration-pausing"> </a> 19.1.7.2 Pausing Replication on the Replica </h4> </div> </div> </div> <p> You can stop and start replication on the replica using the <a class="link" href="stop-replica.html" title="15.4.2.5 STOP REPLICA Statement"> <code class="literal"> STOP REPLICA </code> </a> and <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement"> <code class="literal"> START REPLICA </code> </a> statements. </p> <p> To stop processing of the binary log from the source, use <a class="link" href="stop-replica.html" title="15.4.2.5 STOP REPLICA Statement"> <code class="literal"> STOP REPLICA </code> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa73992186"><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">STOP</span> <span class="token keyword">REPLICA</span><span class="token punctuation">;</span></code></pre> </div> <p> When replication is stopped, the replication I/O (receiver) thread stops reading events from the source binary log and writing them to the relay log, and the SQL thread stops reading events from the relay log and executing them. You can pause the I/O (receiver) or SQL (applier) thread individually by specifying the thread type: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16640149"><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">STOP</span> <span class="token keyword">REPLICA</span> <span class="token keyword">IO_THREAD</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">STOP</span> <span class="token keyword">REPLICA</span> <span class="token keyword">SQL_THREAD</span><span class="token punctuation">;</span></code></pre> </div> <p> To start execution again, use the <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement"> <code class="literal"> START REPLICA </code> </a> statement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa45707296"><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">START</span> <span class="token keyword">REPLICA</span><span class="token punctuation">;</span></code></pre> </div> <p> To start a particular thread, specify the thread type: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa79435392"><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">START</span> <span class="token keyword">REPLICA</span> <span class="token keyword">IO_THREAD</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">START</span> <span class="token keyword">REPLICA</span> <span class="token keyword">SQL_THREAD</span><span class="token punctuation">;</span></code></pre> </div> <p> For a replica that performs updates only by processing events from the source, stopping only the SQL thread can be useful if you want to perform a backup or other task. The I/O (receiver) thread continues to read events from the source but they are not executed. This makes it easier for the replica to catch up when you restart the SQL (applier) thread. </p> <p> Stopping only the receiver thread enables the events in the relay log to be executed by the applier thread up to the point where the relay log ends. This can be useful when you want to pause execution to catch up with events already received from the source, when you want to perform administration on the replica but also ensure that it has processed all updates to a specific point. This method can also be used to pause event receipt on the replica while you conduct administration on the source. Stopping the receiver thread but permitting the applier thread to run helps ensure that there is not a massive backlog of events to be executed when replication is started again. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysqldump-upgrade-testing.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="mysqldump-upgrade-testing"> </a> 9.4.5.5 Using mysqldump to Test for Upgrade Incompatibilities </h4> </div> </div> </div> <p> When contemplating a MySQL upgrade, it is prudent to install the newer version separately from your current production version. Then you can dump the database and database object definitions from the production server and load them into the new server to verify that they are handled properly. (This is also useful for testing downgrades.) </p> <p> On the production server: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa85696290"><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">mysqldump</span> <span class="token property">--all-databases</span> <span class="token property">--no-data</span> <span class="token property">--routines</span> <span class="token property">--events</span> &gt; dump-defs<span class="token punctuation">.</span>sql</code></pre> </div> <p> On the upgraded server: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa67355578"><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> &lt; dump-defs<span class="token punctuation">.</span>sql</code></pre> </div> <p> Because the dump file does not contain table data, it can be processed quickly. This enables you to spot potential incompatibilities without waiting for lengthy data-loading operations. Look for warnings or errors while the dump file is being processed. </p> <p> After you have verified that the definitions are handled properly, dump the data and try to load it into the upgraded server. </p> <p> On the production server: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa53118777"><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">mysqldump</span> <span class="token property">--all-databases</span> <span class="token property">--no-create-info</span> &gt; dump-data<span class="token punctuation">.</span>sql</code></pre> </div> <p> On the upgraded server: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa86573529"><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> &lt; dump-data<span class="token punctuation">.</span>sql</code></pre> </div> <p> Now check the table contents and run some test queries. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/server-administration.html
<div id="docs-body"> <div class="chapter"> <div class="titlepage"> <div> <div> <h1 class="title"> <a name="server-administration"> </a> Chapter 7 MySQL Server Administration </h1> </div> </div> </div> <div class="toc"> <p> <b> Table of Contents </b> </p> <dl class="toc"> <dt> <span class="section"> <a href="mysqld-server.html"> 7.1 The MySQL Server </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="server-configuration.html"> 7.1.1 Configuring the Server </a> </span> </dt> <dt> <span class="section"> <a href="server-configuration-defaults.html"> 7.1.2 Server Configuration Defaults </a> </span> </dt> <dt> <span class="section"> <a href="server-configuration-validation.html"> 7.1.3 Server Configuration Validation </a> </span> </dt> <dt> <span class="section"> <a href="server-option-variable-reference.html"> 7.1.4 Server Option, System Variable, and Status Variable Reference </a> </span> </dt> <dt> <span class="section"> <a href="server-system-variable-reference.html"> 7.1.5 Server System Variable Reference </a> </span> </dt> <dt> <span class="section"> <a href="server-status-variable-reference.html"> 7.1.6 Server Status Variable Reference </a> </span> </dt> <dt> <span class="section"> <a href="server-options.html"> 7.1.7 Server Command Options </a> </span> </dt> <dt> <span class="section"> <a href="server-system-variables.html"> 7.1.8 Server System Variables </a> </span> </dt> <dt> <span class="section"> <a href="using-system-variables.html"> 7.1.9 Using System Variables </a> </span> </dt> <dt> <span class="section"> <a href="server-status-variables.html"> 7.1.10 Server Status Variables </a> </span> </dt> <dt> <span class="section"> <a href="sql-mode.html"> 7.1.11 Server SQL Modes </a> </span> </dt> <dt> <span class="section"> <a href="connection-management.html"> 7.1.12 Connection Management </a> </span> </dt> <dt> <span class="section"> <a href="ipv6-support.html"> 7.1.13 IPv6 Support </a> </span> </dt> <dt> <span class="section"> <a href="network-namespace-support.html"> 7.1.14 Network Namespace Support </a> </span> </dt> <dt> <span class="section"> <a href="time-zone-support.html"> 7.1.15 MySQL Server Time Zone Support </a> </span> </dt> <dt> <span class="section"> <a href="resource-groups.html"> 7.1.16 Resource Groups </a> </span> </dt> <dt> <span class="section"> <a href="server-side-help-support.html"> 7.1.17 Server-Side Help Support </a> </span> </dt> <dt> <span class="section"> <a href="session-state-tracking.html"> 7.1.18 Server Tracking of Client Session State </a> </span> </dt> <dt> <span class="section"> <a href="server-shutdown.html"> 7.1.19 The Server Shutdown Process </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="data-directory.html"> 7.2 The MySQL Data Directory </a> </span> </dt> <dt> <span class="section"> <a href="system-schema.html"> 7.3 The mysql System Schema </a> </span> </dt> <dt> <span class="section"> <a href="server-logs.html"> 7.4 MySQL Server Logs </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="log-destinations.html"> 7.4.1 Selecting General Query Log and Slow Query Log Output Destinations </a> </span> </dt> <dt> <span class="section"> <a href="error-log.html"> 7.4.2 The Error Log </a> </span> </dt> <dt> <span class="section"> <a href="query-log.html"> 7.4.3 The General Query Log </a> </span> </dt> <dt> <span class="section"> <a href="binary-log.html"> 7.4.4 The Binary Log </a> </span> </dt> <dt> <span class="section"> <a href="slow-query-log.html"> 7.4.5 The Slow Query Log </a> </span> </dt> <dt> <span class="section"> <a href="log-file-maintenance.html"> 7.4.6 Server Log Maintenance </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="components.html"> 7.5 MySQL Components </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="component-loading.html"> 7.5.1 Installing and Uninstalling Components </a> </span> </dt> <dt> <span class="section"> <a href="obtaining-component-information.html"> 7.5.2 Obtaining Component Information </a> </span> </dt> <dt> <span class="section"> <a href="error-log-components.html"> 7.5.3 Error Log Components </a> </span> </dt> <dt> <span class="section"> <a href="query-attribute-components.html"> 7.5.4 Query Attribute Components </a> </span> </dt> <dt> <span class="section"> <a href="scheduler-component.html"> 7.5.5 Scheduler Component </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="server-plugins.html"> 7.6 MySQL Server Plugins </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="plugin-loading.html"> 7.6.1 Installing and Uninstalling Plugins </a> </span> </dt> <dt> <span class="section"> <a href="obtaining-plugin-information.html"> 7.6.2 Obtaining Server Plugin Information </a> </span> </dt> <dt> <span class="section"> <a href="thread-pool.html"> 7.6.3 MySQL Enterprise Thread Pool </a> </span> </dt> <dt> <span class="section"> <a href="rewriter-query-rewrite-plugin.html"> 7.6.4 The Rewriter Query Rewrite Plugin </a> </span> </dt> <dt> <span class="section"> <a href="ddl-rewriter.html"> 7.6.5 The ddl_rewriter Plugin </a> </span> </dt> <dt> <span class="section"> <a href="version-tokens.html"> 7.6.6 Version Tokens </a> </span> </dt> <dt> <span class="section"> <a href="clone-plugin.html"> 7.6.7 The Clone Plugin </a> </span> </dt> <dt> <span class="section"> <a href="daemon-keyring-proxy-plugin.html"> 7.6.8 The Keyring Proxy Bridge Plugin </a> </span> </dt> <dt> <span class="section"> <a href="plugin-services.html"> 7.6.9 MySQL Plugin Services </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="server-loadable-functions.html"> 7.7 MySQL Server Loadable Functions </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="function-loading.html"> 7.7.1 Installing and Uninstalling Loadable Functions </a> </span> </dt> <dt> <span class="section"> <a href="obtaining-loadable-function-information.html"> 7.7.2 Obtaining Information About Loadable Functions </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="multiple-servers.html"> 7.8 Running Multiple MySQL Instances on One Machine </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="multiple-data-directories.html"> 7.8.1 Setting Up Multiple Data Directories </a> </span> </dt> <dt> <span class="section"> <a href="multiple-windows-servers.html"> 7.8.2 Running Multiple MySQL Instances on Windows </a> </span> </dt> <dt> <span class="section"> <a href="multiple-unix-servers.html"> 7.8.3 Running Multiple MySQL Instances on Unix </a> </span> </dt> <dt> <span class="section"> <a href="multiple-server-clients.html"> 7.8.4 Using Client Programs in a Multiple-Server Environment </a> </span> </dt> </dl> </dd> <dt> <span class="section"> <a href="debugging-mysql.html"> 7.9 Debugging MySQL </a> </span> </dt> <dd> <dl> <dt> <span class="section"> <a href="debugging-server.html"> 7.9.1 Debugging a MySQL Server </a> </span> </dt> <dt> <span class="section"> <a href="debugging-client.html"> 7.9.2 Debugging a MySQL Client </a> </span> </dt> <dt> <span class="section"> <a href="lock-order-tool.html"> 7.9.3 The LOCK_ORDER Tool </a> </span> </dt> <dt> <span class="section"> <a href="dbug-package.html"> 7.9.4 The DBUG Package </a> </span> </dt> </dl> </dd> </dl> </div> <p> MySQL Server ( <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> ) is the main program that does most of the work in a MySQL installation. This chapter provides an overview of MySQL Server and covers general server administration: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Server configuration </p> </li> <li class="listitem"> <p> The data directory, particularly the <code class="literal"> mysql </code> system schema </p> </li> <li class="listitem"> <p> The server log files </p> </li> <li class="listitem"> <p> Management of multiple servers on a single machine </p> </li> </ul> </div> <p> For additional information on administrative topics, see also: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="security.html" title="Chapter 8 Security"> Chapter 8, <i> Security </i> </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="backup-and-recovery.html" title="Chapter 9 Backup and Recovery"> Chapter 9, <i> Backup and Recovery </i> </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="replication.html" title="Chapter 19 Replication"> Chapter 19, <i> Replication </i> </a> </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/encryption-functions.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="encryption-functions"> </a> 14.13 Encryption and Compression Functions </h2> </div> </div> </div> <a class="indexterm" name="idm46045199614576"> </a> <a class="indexterm" name="idm46045199613536"> </a> <div class="table"> <a name="idm46045199612048"> </a> <p class="title"> <b> Table 14.18 Encryption Functions </b> </p> <div class="table-contents"> <table frame="box" rules="all" summary="A reference that lists encryption functions."> <colgroup> <col style="width: 28%"/> <col style="width: 71%"/> </colgroup> <thead> <tr> <th> Name </th> <th> Description </th> </tr> </thead> <tbody> <tr> <td> <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> </td> <td> Decrypt using AES </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> </td> <td> Encrypt using AES </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_compress"> <code class="literal"> COMPRESS() </code> </a> </td> <td> Return result as a binary string </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> </td> <td> Calculate MD5 checksum </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES() </code> </a> </td> <td> Return a random byte vector </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> , <code class="literal"> SHA() </code> </a> </td> <td> Calculate an SHA-1 160-bit checksum </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_sha2"> <code class="literal"> SHA2() </code> </a> </td> <td> Calculate an SHA-2 checksum </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_statement-digest"> <code class="literal"> STATEMENT_DIGEST() </code> </a> </td> <td> Compute statement digest hash value </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_statement-digest-text"> <code class="literal"> STATEMENT_DIGEST_TEXT() </code> </a> </td> <td> Compute normalized statement digest </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_uncompress"> <code class="literal"> UNCOMPRESS() </code> </a> </td> <td> Uncompress a string compressed </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_uncompressed-length"> <code class="literal"> UNCOMPRESSED_LENGTH() </code> </a> </td> <td> Return the length of a string before compression </td> </tr> <tr> <td> <a class="link" href="encryption-functions.html#function_validate-password-strength"> <code class="literal"> VALIDATE_PASSWORD_STRENGTH() </code> </a> </td> <td> Determine strength of password </td> </tr> </tbody> </table> </div> <div class="table-contents"> <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 739px;"> <thead> <tr> <th style="width: 234.516px;"> Name </th> <th style="width: 503.484px;"> Description </th> </tr> </thead> </table> </div> </div> <br class="table-break"/> <p> Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results, use a column with a <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> VARBINARY </code> </a> or <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> binary string data type. This avoids potential problems with trailing space removal or character set conversion that would change data values, such as may occur if you use a nonbinary string data type ( <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> , <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> , <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> ). </p> <p> Some encryption functions return strings of ASCII characters: <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> , <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA() </code> </a> , <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> </a> , <a class="link" href="encryption-functions.html#function_sha2"> <code class="literal"> SHA2() </code> </a> , <a class="link" href="encryption-functions.html#function_statement-digest"> <code class="literal"> STATEMENT_DIGEST() </code> </a> , <a class="link" href="encryption-functions.html#function_statement-digest-text"> <code class="literal"> STATEMENT_DIGEST_TEXT() </code> </a> . Their return value is a string that has a character set and collation determined by the <a class="link" href="server-system-variables.html#sysvar_character_set_connection"> <code class="literal"> character_set_connection </code> </a> and <a class="link" href="server-system-variables.html#sysvar_collation_connection"> <code class="literal"> collation_connection </code> </a> system variables. This is a nonbinary string unless the character set is <code class="literal"> binary </code> . </p> <p> If an application stores values from a function such as <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> or <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> </a> that returns a string of hex digits, more efficient storage and comparisons can be obtained by converting the hex representation to binary using <a class="link" href="string-functions.html#function_unhex"> <code class="literal"> UNHEX() </code> </a> and storing the result in a <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> BINARY( <em class="replaceable"> <code> N </code> </em> ) </code> </a> column. Each pair of hexadecimal digits requires one byte in binary form, so the value of <em class="replaceable"> <code> N </code> </em> depends on the length of the hex string. <em class="replaceable"> <code> N </code> </em> is 16 for an <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> value and 20 for a <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> </a> value. For <a class="link" href="encryption-functions.html#function_sha2"> <code class="literal"> SHA2() </code> </a> , <em class="replaceable"> <code> N </code> </em> ranges from 28 to 32 depending on the argument specifying the desired bit length of the result. </p> <p> The size penalty for storing the hex string in a <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> column is at least two times, up to eight times if the value is stored in a column that uses the <code class="literal"> utf8mb4 </code> character set (where each character uses 4 bytes). Storing the string also results in slower comparisons because of the larger values and the need to take character set collation rules into account. </p> <p> Suppose that an application stores <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> string values in a <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR(32) </code> </a> column: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25439234"><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">TABLE</span> md5_tbl <span class="token punctuation">(</span>md5_val <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">.</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">INSERT</span> <span class="token keyword">INTO</span> md5_tbl <span class="token punctuation">(</span>md5_val<span class="token punctuation">,</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">VALUES</span><span class="token punctuation">(</span><span class="token function">MD5</span><span class="token punctuation">(</span><span class="token string">'abcdef'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">.</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> To convert hex strings to more compact form, modify the application to use <a class="link" href="string-functions.html#function_unhex"> <code class="literal"> UNHEX() </code> </a> and <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> BINARY(16) </code> </a> instead as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa28295470"><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">TABLE</span> md5_tbl <span class="token punctuation">(</span>md5_val <span class="token datatype">BINARY</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">.</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">INSERT</span> <span class="token keyword">INTO</span> md5_tbl <span class="token punctuation">(</span>md5_val<span class="token punctuation">,</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">VALUES</span><span class="token punctuation">(</span><span class="token function">UNHEX</span><span class="token punctuation">(</span><span class="token function">MD5</span><span class="token punctuation">(</span><span class="token string">'abcdef'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">.</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> Applications should be prepared to handle the very rare case that a hashing function produces the same value for two different input values. One way to make collisions detectable is to make the hash column a primary key. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Exploits for the MD5 and SHA-1 algorithms have become known. You may wish to consider using another one-way encryption function described in this section instead, such as <a class="link" href="encryption-functions.html#function_sha2"> <code class="literal"> SHA2() </code> </a> . </p> </div> <div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Caution </div> <p> Passwords or other sensitive values supplied as arguments to encryption functions are sent as cleartext to the MySQL server unless an SSL connection is used. Also, such values appear in any MySQL logs to which they are written. To avoid these types of exposure, applications can encrypt sensitive values on the client side before sending them to the server. The same considerations apply to encryption keys. To avoid exposing these, applications can use stored procedures to encrypt and decrypt values on the server side. </p> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <a name="function_aes-decrypt"> </a> <p> <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT( <em class="replaceable"> <code> crypt_str </code> </em> , <em class="replaceable"> <code> key_str </code> </em> [, <em class="replaceable"> <code> init_vector </code> </em> ][, <em class="replaceable"> <code> kdf_name </code> </em> ][, <em class="replaceable"> <code> salt </code> </em> ][, <em class="replaceable"> <code> info | iterations </code> </em> ]) </code> </a> </p> <a class="indexterm" name="idm46045199517136"> </a> <p> This function decrypts data using the official AES (Advanced Encryption Standard) algorithm. For more information, see the description of <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> . </p> <p> Statements that use <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> are unsafe for statement-based replication. </p> </li> <li class="listitem"> <a name="function_aes-encrypt"> </a> <p> <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT( <em class="replaceable"> <code> str </code> </em> , <em class="replaceable"> <code> key_str </code> </em> [, <em class="replaceable"> <code> init_vector </code> </em> ][, <em class="replaceable"> <code> kdf_name </code> </em> ][, <em class="replaceable"> <code> salt </code> </em> ][, <em class="replaceable"> <code> info | iterations </code> </em> ]) </code> </a> </p> <a class="indexterm" name="idm46045199504032"> </a> <p> <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> implement encryption and decryption of data using the official AES (Advanced Encryption Standard) algorithm, previously known as <span class="quote"> “ <span class="quote"> Rijndael. </span> ” </span> The AES standard permits various key lengths. By default these functions implement AES with a 128-bit key length. Key lengths of 196 or 256 bits can be used, as described later. The key length is a trade off between performance and security. </p> <p> <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> encrypts the string <em class="replaceable"> <code> str </code> </em> using the key string <em class="replaceable"> <code> key_str </code> </em> , and returns a binary string containing the encrypted output. <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> decrypts the encrypted string <em class="replaceable"> <code> crypt_str </code> </em> using the key string <em class="replaceable"> <code> key_str </code> </em> , and returns the original (binary) string in hexadecimal format. (To obtain the string as plaintext, cast the result to <code class="literal"> CHAR </code> . Alternatively, start 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 with <a class="link" href="mysql-command-options.html#option_mysql_binary-as-hex"> <code class="option"> --skip-binary-as-hex </code> </a> to cause all binary values to be displayed as text.) If either function argument is <code class="literal"> NULL </code> , the function returns <code class="literal"> NULL </code> . If <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> detects invalid data or incorrect padding, it returns <code class="literal"> NULL </code> . However, it is possible for <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> to return a non- <code class="literal"> NULL </code> value (possibly garbage) if the input data or the key is invalid. </p> <p> These functions support the use of a key derivation function (KDF) to create a cryptographically strong secret key from the information passed in <em class="replaceable"> <code> key_str </code> </em> . The derived key is used to encrypt and decrypt the data, and it remains in the MySQL Server instance and is not accessible to users. Using a KDF is highly recommended, as it provides better security than specifying your own premade key or deriving it by a simpler method as you use the function. The functions support HKDF (available from OpenSSL 1.1.0), for which you can specify an optional salt and context-specific information to include in the keying material, and PBKDF2 (available from OpenSSL 1.0.2), for which you can specify an optional salt and set the number of iterations used to produce the key. </p> <p> <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> permit control of the block encryption mode. The <a class="link" href="server-system-variables.html#sysvar_block_encryption_mode"> <code class="literal"> block_encryption_mode </code> </a> system variable controls the mode for block-based encryption algorithms. Its default value is <code class="literal"> aes-128-ecb </code> , which signifies encryption using a key length of 128 bits and ECB mode. For a description of the permitted values of this variable, see <a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables"> Section 7.1.8, “Server System Variables” </a> . The optional <em class="replaceable"> <code> init_vector </code> </em> argument is used to provide an initialization vector for block encryption modes that require it. </p> <p> Statements that use <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> or <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> are unsafe for statement-based replication. </p> <p> If <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> is invoked from within 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, binary strings display using hexadecimal notation, depending on the value of the <a class="link" href="mysql-command-options.html#option_mysql_binary-as-hex"> <code class="option"> --binary-as-hex </code> </a> . For more information about that option, see <a class="xref" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client"> Section 6.5.1, “mysql — The MySQL Command-Line Client” </a> . </p> <p> The arguments for the <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> functions are as follows: </p> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <em class="replaceable"> <code> str </code> </em> </span> </dt> <dd> <p> The string for <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> to encrypt using the key string <em class="replaceable"> <code> key_str </code> </em> , or the key derived from it by the specified KDF. The string can be any length. Padding is automatically added to <em class="replaceable"> <code> str </code> </em> so it is a multiple of a block as required by block-based algorithms such as AES. This padding is automatically removed by the <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> function. </p> </dd> <dt> <span class="term"> <em class="replaceable"> <code> crypt_str </code> </em> </span> </dt> <dd> <p> The encrypted string for <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> to decrypt using the key string <em class="replaceable"> <code> key_str </code> </em> , or the key derived from it by the specified KDF. The string can be any length. The length of <em class="replaceable"> <code> crypt_str </code> </em> can be calculated from the length of the original string using this formula: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-clike"><div class="docs-select-all right" id="sa73279735"><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"><span class="token number">16</span> <span class="token operator">*</span> <span class="token punctuation">(</span><span class="token function">trunc</span><span class="token punctuation">(</span><em class="replaceable">string_length</em> <span class="token operator">/</span> <span class="token number">16</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span></code></pre> </div> </dd> <dt> <span class="term"> <em class="replaceable"> <code> key_str </code> </em> </span> </dt> <dd> <p> The encryption key, or the input keying material that is used as the basis for deriving a key using a key derivation function (KDF). For the same instance of data, use the same value of <em class="replaceable"> <code> key_str </code> </em> for encryption with <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and decryption with <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> . </p> <p> If you are using a KDF, <em class="replaceable"> <code> key_str </code> </em> can be any arbitrary information such as a password or passphrase. In the further arguments for the function, you specify the KDF name, then add further options to increase the security as appropriate for the KDF. </p> <p> When you use a KDF, the function creates a cryptographically strong secret key from the information passed in <em class="replaceable"> <code> key_str </code> </em> and any salt or additional information that you provide in the other arguments. The derived key is used to encrypt and decrypt the data, and it remains in the MySQL Server instance and is not accessible to users. Using a KDF is highly recommended, as it provides better security than specifying your own premade key or deriving it by a simpler method as you use the function. </p> <p> If you are not using a KDF, for a key length of 128 bits, the most secure way to pass a key to the <em class="replaceable"> <code> key_str </code> </em> argument is to create a truly random 128-bit value and pass it as a binary value. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11696982"><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">INSERT</span> <span class="token keyword">INTO</span> t <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token function">AES_ENCRYPT</span><span class="token punctuation">(</span><span class="token string">'text'</span><span class="token punctuation">,</span><span class="token function">UNHEX</span><span class="token punctuation">(</span><span class="token string">'F3229A0B371ED2D9441B830D21A390C3'</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 passphrase can be used to generate an AES key by hashing the passphrase. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34738136"><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">INSERT</span> <span class="token keyword">INTO</span> t <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token function">AES_ENCRYPT</span><span class="token punctuation">(</span><span class="token string">'text'</span><span class="token punctuation">,</span> <span class="token function">UNHEX</span><span class="token punctuation">(</span><span class="token function">SHA2</span><span class="token punctuation">(</span><span class="token string">'My secret passphrase'</span><span class="token punctuation">,</span><span class="token number">512</span><span class="token punctuation">)</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> If you exceed the maximum key length of 128 bits, a warning is returned. If you are not using a KDF, do not pass a password or passphrase directly to <em class="replaceable"> <code> key_str </code> </em> , hash it first. Previous versions of this documentation suggested the former approach, but it is no longer recommended as the examples shown here are more secure. </p> </dd> <dt> <span class="term"> <em class="replaceable"> <code> init_vector </code> </em> </span> </dt> <dd> <p> An initialization vector, for block encryption modes that require it. The <a class="link" href="server-system-variables.html#sysvar_block_encryption_mode"> <code class="literal"> block_encryption_mode </code> </a> system variable controls the mode. For the same instance of data, use the same value of <em class="replaceable"> <code> init_vector </code> </em> for encryption with <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and decryption with <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> . </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If you are using a KDF, you must specify an initialization vector or a null string for this argument, in order to access the later arguments to define the KDF. </p> </div> <p> For modes that require an initialization vector, it must be 16 bytes or longer (bytes in excess of 16 are ignored). An error occurs if <em class="replaceable"> <code> init_vector </code> </em> is missing. For modes that do not require an initialization vector, it is ignored and a warning is generated if <em class="replaceable"> <code> init_vector </code> </em> is specified, unless you are using a KDF. </p> <p> The default value for the <a class="link" href="server-system-variables.html#sysvar_block_encryption_mode"> <code class="literal"> block_encryption_mode </code> </a> system variable is <code class="literal"> aes-128-ecb </code> , or ECB mode, which does not require an initialization vector. The alternative permitted block encryption modes CBC, CFB1, CFB8, CFB128, and OFB all require an initialization vector. </p> <p> A random string of bytes to use for the initialization vector can be produced by calling <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES(16) </code> </a> . </p> </dd> <dt> <span class="term"> <em class="replaceable"> <code> kdf_name </code> </em> </span> </dt> <dd> <p> The name of the key derivation function (KDF) to create a key from the input keying material passed in <em class="replaceable"> <code> key_str </code> </em> , and other arguments as appropriate for the KDF. Optional. </p> <p> For the same instance of data, use the same value of <em class="replaceable"> <code> kdf_name </code> </em> for encryption with <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and decryption with <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> . When you specify <em class="replaceable"> <code> kdf_name </code> </em> , you must specify <em class="replaceable"> <code> init_vector </code> </em> , using either a valid initialization vector, or a null string if the encryption mode does not require an initialization vector. </p> <p> The following values are supported: </p> <div class="variablelist"> <dl class="variablelist"> <dt> <span class="term"> <code class="literal"> hkdf </code> </span> </dt> <dd> <p> HKDF, which is available from OpenSSL 1.1.0. HKDF extracts a pseudorandom key from the keying material then expands it into additional keys. With HKDF, you can specify an optional salt ( <em class="replaceable"> <code> salt </code> </em> ) and context-specific information such as application details ( <em class="replaceable"> <code> info </code> </em> ) to include in the keying material. </p> </dd> <dt> <span class="term"> <code class="literal"> pbkdf2_hmac </code> </span> </dt> <dd> <p> PBKDF2, which is available from OpenSSL 1.0.2. PBKDF2 applies a pseudorandom function to the keying material, and repeats this process a large number of times to produce the key. With PBKDF2, you can specify an optional salt ( <em class="replaceable"> <code> salt </code> </em> ) to include in the keying material, and set the number of iterations used to produce the key ( <em class="replaceable"> <code> iterations </code> </em> ). </p> </dd> </dl> </div> <p> In this example, HKDF is specified as the key derivation function, and a salt and context information are provided. The argument for the initialization vector is included but is the empty string: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa2697150"><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> <span class="token function">AES_ENCRYPT</span><span class="token punctuation">(</span><span class="token string">'mytext'</span><span class="token punctuation">,</span><span class="token string">'mykeystring'</span><span class="token punctuation">,</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'hkdf'</span><span class="token punctuation">,</span> <span class="token string">'salt'</span><span class="token punctuation">,</span> <span class="token string">'info'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> In this example, PBKDF2 is specified as the key derivation function, a salt is provided, and the number of iterations is doubled from the recommended minimum: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa13169593"><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> <span class="token function">AES_ENCRYPT</span><span class="token punctuation">(</span><span class="token string">'mytext'</span><span class="token punctuation">,</span><span class="token string">'mykeystring'</span><span class="token punctuation">,</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'pbkdf2_hmac'</span><span class="token punctuation">,</span><span class="token string">'salt'</span><span class="token punctuation">,</span> <span class="token string">'2000'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> </dd> <dt> <span class="term"> <em class="replaceable"> <code> salt </code> </em> </span> </dt> <dd> <p> A salt to be passed to the key derivation function (KDF). Optional. Both HKDF and PBKDF2 can use salts, and their use is recommended to help prevent attacks based on dictionaries of common passwords or rainbow tables. </p> <p> A salt consists of random data, which for security must be different for each encryption operation. A random string of bytes to use for the salt can be produced by calling <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES() </code> </a> . This example produces a 64-bit salt: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa69780846"><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 variable">@salt</span> <span class="token operator">=</span> <span class="token function">RANDOM_BYTES</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> For the same instance of data, use the same value of <em class="replaceable"> <code> salt </code> </em> for encryption with <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and decryption with <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> . The salt can safely be stored along with the encrypted data. </p> </dd> <dt> <span class="term"> <em class="replaceable"> <code> info </code> </em> </span> </dt> <dd> <p> Context-specific information for HKDF to include in the keying material, such as information about the application. Optional; available when you specify <code class="literal"> hkdf </code> as the KDF name. HKDF adds this information to the keying material specified in <em class="replaceable"> <code> key_str </code> </em> and the salt specified in <em class="replaceable"> <code> salt </code> </em> to produce the key. </p> <p> For the same instance of data, use the same value of <em class="replaceable"> <code> info </code> </em> for encryption with <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and decryption with <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> . </p> </dd> <dt> <span class="term"> <em class="replaceable"> <code> iterations </code> </em> </span> </dt> <dd> <p> The iteration count for PBKDF2 to use when producing the key. Optional; available when you specify <code class="literal"> pbkdf2_hmac </code> as the KDF name. A higher count gives greater resistance to brute-force attacks because it has a greater computational cost for the attacker, but the same is necessarily true for the key derivation process. The default if you do not specify this argument is 1000, which is the minimum recommended by the OpenSSL standard. </p> <p> For the same instance of data, use the same value of <em class="replaceable"> <code> iterations </code> </em> for encryption with <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> and decryption with <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> . </p> </dd> </dl> </div> <p> </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96736067"><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> block_encryption_mode <span class="token operator">=</span> <span class="token string">'aes-256-cbc'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@key_str</span> <span class="token operator">=</span> <span class="token function">SHA2</span><span class="token punctuation">(</span><span class="token string">'My secret passphrase'</span><span class="token punctuation">,</span><span class="token number">512</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@init_vector</span> <span class="token operator">=</span> <span class="token function">RANDOM_BYTES</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@crypt_str</span> <span class="token operator">=</span> <span class="token function">AES_ENCRYPT</span><span class="token punctuation">(</span><span class="token string">'text'</span><span class="token punctuation">,</span><span class="token variable">@key_str</span><span class="token punctuation">,</span><span class="token variable">@init_vector</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CAST</span><span class="token punctuation">(</span><span class="token function">AES_DECRYPT</span><span class="token punctuation">(</span><span class="token variable">@crypt_str</span><span class="token punctuation">,</span><span class="token variable">@key_str</span><span class="token punctuation">,</span><span class="token variable">@init_vector</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token datatype">CHAR</span><span class="token punctuation">)</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> CAST(AES_DECRYPT(@crypt_str,@key_str,@init_vector) AS CHAR) <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> text <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> </li> <li class="listitem"> <a name="function_compress"> </a> <p> <a class="link" href="encryption-functions.html#function_compress"> <code class="literal"> COMPRESS( <em class="replaceable"> <code> string_to_compress </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199375152"> </a> <p> Compresses a string and returns the result as a binary string. This function requires MySQL to have been compiled with a compression library such as <code class="literal"> zlib </code> . Otherwise, the return value is always <code class="literal"> NULL </code> . The return value is also <code class="literal"> NULL </code> if <em class="replaceable"> <code> string_to_compress </code> </em> is <code class="literal"> NULL </code> . The compressed string can be uncompressed with <a class="link" href="encryption-functions.html#function_uncompress"> <code class="literal"> UNCOMPRESS() </code> </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47687868"><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">SELECT</span> <span class="token function">LENGTH</span><span class="token punctuation">(</span><span class="token function">COMPRESS</span><span class="token punctuation">(</span><span class="token function">REPEAT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">21</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LENGTH</span><span class="token punctuation">(</span><span class="token function">COMPRESS</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LENGTH</span><span class="token punctuation">(</span><span class="token function">COMPRESS</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">13</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LENGTH</span><span class="token punctuation">(</span><span class="token function">COMPRESS</span><span class="token punctuation">(</span><span class="token function">REPEAT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">15</span></code></pre> </div> <p> The compressed string contents are stored the following way: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Empty strings are stored as empty strings. </p> </li> <li class="listitem"> <p> Nonempty strings are stored as a 4-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra <code class="literal"> . </code> character is added to avoid problems with endspace trimming should the result be stored in a <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> or <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> column. (However, use of nonbinary string data types such as <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> or <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> to store compressed strings is not recommended anyway because character set conversion may occur. Use a <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> VARBINARY </code> </a> or <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> binary string column instead.) </p> </li> </ul> </div> <p> If <a class="link" href="encryption-functions.html#function_compress"> <code class="literal"> COMPRESS() </code> </a> is invoked from within 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, binary strings display using hexadecimal notation, depending on the value of the <a class="link" href="mysql-command-options.html#option_mysql_binary-as-hex"> <code class="option"> --binary-as-hex </code> </a> . For more information about that option, see <a class="xref" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client"> Section 6.5.1, “mysql — The MySQL Command-Line Client” </a> . </p> </li> <li class="listitem"> <a name="function_md5"> </a> <p> <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5( <em class="replaceable"> <code> str </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199342144"> </a> <p> Calculates an MD5 128-bit checksum for the string. The value is returned as a string of 32 hexadecimal digits, or <code class="literal"> NULL </code> if the argument was <code class="literal"> NULL </code> . The return value can, for example, be used as a hash key. See the notes at the beginning of this section about storing hash values efficiently. </p> <p> The return value is a string in the connection character set. </p> <p> If FIPS mode is enabled, <code class="function"> MD5() </code> returns <code class="literal"> NULL </code> . See <a class="xref" href="fips-mode.html" title="8.8 FIPS Support"> Section 8.8, “FIPS Support” </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa77658121"><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">SELECT</span> <span class="token function">MD5</span><span class="token punctuation">(</span><span class="token string">'testing'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'ae2b1fca515949e5d54fb22b8ed95575'</span></code></pre> </div> <p> This is the <span class="quote"> “ <span class="quote"> RSA Data Security, Inc. MD5 Message-Digest Algorithm. </span> ” </span> </p> <p> See the note regarding the MD5 algorithm at the beginning this section. </p> </li> <li class="listitem"> <a name="function_random-bytes"> </a> <p> <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES( <em class="replaceable"> <code> len </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199325552"> </a> <p> This function returns a binary string of <em class="replaceable"> <code> len </code> </em> random bytes generated using the random number generator of the SSL library. Permitted values of <em class="replaceable"> <code> len </code> </em> range from 1 to 1024. For values outside that range, an error occurs. Returns <code class="literal"> NULL </code> if <em class="replaceable"> <code> len </code> </em> is <code class="literal"> NULL </code> . </p> <p> <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES() </code> </a> can be used to provide the initialization vector for the <a class="link" href="encryption-functions.html#function_aes-decrypt"> <code class="literal"> AES_DECRYPT() </code> </a> and <a class="link" href="encryption-functions.html#function_aes-encrypt"> <code class="literal"> AES_ENCRYPT() </code> </a> functions. For use in that context, <em class="replaceable"> <code> len </code> </em> must be at least 16. Larger values are permitted, but bytes in excess of 16 are ignored. </p> <p> <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES() </code> </a> generates a random value, which makes its result nondeterministic. Consequently, statements that use this function are unsafe for statement-based replication. </p> <p> If <a class="link" href="encryption-functions.html#function_random-bytes"> <code class="literal"> RANDOM_BYTES() </code> </a> is invoked from within 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, binary strings display using hexadecimal notation, depending on the value of the <a class="link" href="mysql-command-options.html#option_mysql_binary-as-hex"> <code class="option"> --binary-as-hex </code> </a> . For more information about that option, see <a class="xref" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client"> Section 6.5.1, “mysql — The MySQL Command-Line Client” </a> . </p> </li> <li class="listitem"> <a name="function_sha1"> </a> <p> <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1( <em class="replaceable"> <code> str </code> </em> ) </code> </a> , <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA( <em class="replaceable"> <code> str </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199301952"> </a> <a class="indexterm" name="idm46045199300880"> </a> <p> Calculates an SHA-1 160-bit checksum for the string, as described in RFC 3174 (Secure Hash Algorithm). The value is returned as a string of 40 hexadecimal digits, or <code class="literal"> NULL </code> if the argument is <code class="literal"> NULL </code> . One of the possible uses for this function is as a hash key. See the notes at the beginning of this section about storing hash values efficiently. <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA() </code> </a> is synonymous with <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> </a> . </p> <p> The return value is a string in the connection character set. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa93101863"><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">SELECT</span> <span class="token function">SHA1</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'a9993e364706816aba3e25717850c26c9cd0d89d'</span></code></pre> </div> <p> <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> </a> can be considered a cryptographically more secure equivalent of <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> . However, see the note regarding the MD5 and SHA-1 algorithms at the beginning this section. </p> </li> <li class="listitem"> <a name="function_sha2"> </a> <p> <a class="link" href="encryption-functions.html#function_sha2"> <code class="literal"> SHA2( <em class="replaceable"> <code> str </code> </em> , <em class="replaceable"> <code> hash_length </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199282464"> </a> <p> Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512). The first argument is the plaintext string to be hashed. The second argument indicates the desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256). If either argument is <code class="literal"> NULL </code> or the hash length is not one of the permitted values, the return value is <code class="literal"> NULL </code> . Otherwise, the function result is a hash value containing the desired number of bits. See the notes at the beginning of this section about storing hash values efficiently. </p> <p> The return value is a string in the connection character set. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa15256203"><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">SELECT</span> <span class="token function">SHA2</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">,</span> <span class="token number">224</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7'</span></code></pre> </div> <p> This function works only if MySQL has been configured with SSL support. See <a class="xref" href="encrypted-connections.html" title="8.3 Using Encrypted Connections"> Section 8.3, “Using Encrypted Connections” </a> . </p> <p> <a class="link" href="encryption-functions.html#function_sha2"> <code class="literal"> SHA2() </code> </a> can be considered cryptographically more secure than <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> or <a class="link" href="encryption-functions.html#function_sha1"> <code class="literal"> SHA1() </code> </a> . </p> </li> <li class="listitem"> <a name="function_statement-digest"> </a> <p> <a class="link" href="encryption-functions.html#function_statement-digest"> <code class="literal"> STATEMENT_DIGEST( <em class="replaceable"> <code> statement </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199264224"> </a> <p> Given an SQL statement as a string, returns the statement digest hash value as a string in the connection character set, or <code class="literal"> NULL </code> if the argument is <code class="literal"> NULL </code> . The related <a class="link" href="encryption-functions.html#function_statement-digest-text"> <code class="literal"> STATEMENT_DIGEST_TEXT() </code> </a> function returns the normalized statement digest. For information about statement digesting, see <a class="xref" href="performance-schema-statement-digests.html" title="29.10 Performance Schema Statement Digests and Sampling"> Section 29.10, “Performance Schema Statement Digests and Sampling” </a> . </p> <p> Both functions use the MySQL parser to parse the statement. If parsing fails, an error occurs. The error message includes the parse error only if the statement is provided as a literal string. </p> <p> The <a class="link" href="server-system-variables.html#sysvar_max_digest_length"> <code class="literal"> max_digest_length </code> </a> system variable determines the maximum number of bytes available to these functions for computing normalized statement digests. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa92891910"><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> <span class="token variable">@stmt</span> <span class="token operator">=</span> <span class="token string">'SELECT * FROM mytable WHERE cola = 10 AND colb = 20'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STATEMENT_DIGEST</span><span class="token punctuation">(</span><span class="token variable">@stmt</span><span class="token punctuation">)</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> STATEMENT_DIGEST(@stmt) <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 3bb95eeade896657c4526e74ff2a2862039d0a0fe8a9e7155b5fe492cbd78387 <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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 prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">STATEMENT_DIGEST_TEXT</span><span class="token punctuation">(</span><span class="token variable">@stmt</span><span class="token punctuation">)</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 class="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> STATEMENT_DIGEST_TEXT(@stmt) <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 class="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> SELECT * FROM `mytable` WHERE `cola` = ? AND `colb` = ? <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 class="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> </li> <li class="listitem"> <a name="function_statement-digest-text"> </a> <p> <a class="link" href="encryption-functions.html#function_statement-digest-text"> <code class="literal"> STATEMENT_DIGEST_TEXT( <em class="replaceable"> <code> statement </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199245984"> </a> <p> Given an SQL statement as a string, returns the normalized statement digest as a string in the connection character set, or <code class="literal"> NULL </code> if the argument is <code class="literal"> NULL </code> . For additional discussion and examples, see the description of the related <a class="link" href="encryption-functions.html#function_statement-digest"> <code class="literal"> STATEMENT_DIGEST() </code> </a> function. </p> </li> <li class="listitem"> <a name="function_uncompress"> </a> <p> <a class="link" href="encryption-functions.html#function_uncompress"> <code class="literal"> UNCOMPRESS( <em class="replaceable"> <code> string_to_uncompress </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199236288"> </a> <p> Uncompresses a string compressed by the <a class="link" href="encryption-functions.html#function_compress"> <code class="literal"> COMPRESS() </code> </a> function. If the argument is not a compressed value, the result is <code class="literal"> NULL </code> ; if <em class="replaceable"> <code> string_to_uncompress </code> </em> is <code class="literal"> NULL </code> , the result is also <code class="literal"> NULL </code> . This function requires MySQL to have been compiled with a compression library such as <code class="literal"> zlib </code> . Otherwise, the return value is always <code class="literal"> NULL </code> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59641139"><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">SELECT</span> <span class="token function">UNCOMPRESS</span><span class="token punctuation">(</span><span class="token function">COMPRESS</span><span class="token punctuation">(</span><span class="token string">'any string'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'any string'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">UNCOMPRESS</span><span class="token punctuation">(</span><span class="token string">'any string'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token boolean">NULL</span></code></pre> </div> </li> <li class="listitem"> <a name="function_uncompressed-length"> </a> <p> <a class="link" href="encryption-functions.html#function_uncompressed-length"> <code class="literal"> UNCOMPRESSED_LENGTH( <em class="replaceable"> <code> compressed_string </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199219760"> </a> <p> Returns the length that the compressed string had before being compressed. Returns <code class="literal"> NULL </code> if <em class="replaceable"> <code> compressed_string </code> </em> is <code class="literal"> NULL </code> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34864714"><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">SELECT</span> <span class="token function">UNCOMPRESSED_LENGTH</span><span class="token punctuation">(</span><span class="token function">COMPRESS</span><span class="token punctuation">(</span><span class="token function">REPEAT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">30</span></code></pre> </div> </li> <li class="listitem"> <a name="function_validate-password-strength"> </a> <p> <a class="link" href="encryption-functions.html#function_validate-password-strength"> <code class="literal"> VALIDATE_PASSWORD_STRENGTH( <em class="replaceable"> <code> str </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045199207680"> </a> <p> Given an argument representing a plaintext password, this function returns an integer to indicate how strong the password is, or <code class="literal"> NULL </code> if the argument is <code class="literal"> NULL </code> . The return value ranges from 0 (weak) to 100 (strong). </p> <p> Password assessment by <a class="link" href="encryption-functions.html#function_validate-password-strength"> <code class="literal"> VALIDATE_PASSWORD_STRENGTH() </code> </a> is done by the <code class="literal"> validate_password </code> component. If that component is not installed, the function always returns 0. For information about installing <code class="literal"> validate_password </code> , see <a class="xref" href="validate-password.html" title="8.4.3 The Password Validation Component"> Section 8.4.3, “The Password Validation Component” </a> . To examine or configure the parameters that affect password testing, check or set the system variables implemented by <code class="literal"> validate_password </code> . See <a class="xref" href="validate-password-options-variables.html" title="8.4.3.2 Password Validation Options and Variables"> Section 8.4.3.2, “Password Validation Options and Variables” </a> . </p> <p> The password is subjected to increasingly strict tests and the return value reflects which tests were satisfied, as shown in the following table. In addition, if the <a class="link" href="validate-password-options-variables.html#sysvar_validate_password.check_user_name"> <code class="literal"> validate_password.check_user_name </code> </a> system variable is enabled and the password matches the user name, <a class="link" href="encryption-functions.html#function_validate-password-strength"> <code class="literal"> VALIDATE_PASSWORD_STRENGTH() </code> </a> returns 0 regardless of how other <code class="literal"> validate_password </code> system variables are set. </p> <div class="informaltable"> <table summary="Password tests of the VALIDATE_PASSWORD_STRENGTH() function and the values returned by each password test."> <colgroup> <col style="width: 60%"/> <col style="width: 20%"/> </colgroup> <thead> <tr> <th> Password Test </th> <th> Return Value </th> </tr> </thead> <tbody> <tr> <td> Length &lt; 4 </td> <td> 0 </td> </tr> <tr> <td> Length ≥ 4 and &lt; <a class="link" href="validate-password-options-variables.html#sysvar_validate_password.length"> <code class="literal"> validate_password.length </code> </a> </td> <td> 25 </td> </tr> <tr> <td> Satisfies policy 1 ( <code class="literal"> LOW </code> ) </td> <td> 50 </td> </tr> <tr> <td> Satisfies policy 2 ( <code class="literal"> MEDIUM </code> ) </td> <td> 75 </td> </tr> <tr> <td> Satisfies policy 3 ( <code class="literal"> STRONG </code> ) </td> <td> 100 </td> </tr> </tbody> </table> </div> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/installation-layouts.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="installation-layouts"> </a> 2.1.5 Installation Layouts </h3> </div> </div> </div> <a class="indexterm" name="idm46045332671856"> </a> <a class="indexterm" name="idm46045332670784"> </a> <a class="indexterm" name="idm46045332669712"> </a> <a class="indexterm" name="idm46045332668224"> </a> <p> The installation layout differs for different installation types (for example, native packages, binary tarballs, and source tarballs), which can lead to confusion when managing different systems or using different installation sources. The individual layouts are given in the corresponding installation type or platform chapter, as described following. Note that the layout of installations from vendors other than Oracle may differ from these layouts. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="ulink" href="/doc/refman/8.0/en/windows-installation-layout.html" target="_top"> MySQL Installation Layout on Microsoft Windows </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="source-installation-layout.html" title="2.8.3 MySQL Layout for Source Installation"> Section 2.8.3, “MySQL Layout for Source Installation” </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="binary-installation.html#binary-installation-layout" title="Table 2.3 MySQL Installation Layout for Generic Unix/Linux Binary Package"> Table 2.3, “MySQL Installation Layout for Generic Unix/Linux Binary Package” </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="linux-installation-rpm.html#mysql-installation-layout-linuxrpm" title="Table 2.11 MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone"> Table 2.11, “MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone” </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="macos-installation-pkg.html#mysql-installation-layout-macos" title="Table 2.6 MySQL Installation Layout on macOS"> Table 2.6, “MySQL Installation Layout on macOS” </a> </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-shell-tutorial-javascript-documents-collections.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="mysql-shell-tutorial-javascript-documents-collections"> </a> 22.3.3 Documents and Collections </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="mysql-shell-tutorial-javascript-collections-operations.html"> 22.3.3.1 Create, List, and Drop Collections </a> </span> </dt> <dt> <span class="section"> <a href="mysql-shell-tutorial-javascript-collections-add.html"> 22.3.3.2 Working with Collections </a> </span> </dt> <dt> <span class="section"> <a href="mysql-shell-tutorial-javascript-documents-find.html"> 22.3.3.3 Find Documents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-shell-tutorial-javascript-documents-modify.html"> 22.3.3.4 Modify Documents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-shell-tutorial-javascript-documents-remove.html"> 22.3.3.5 Remove Documents </a> </span> </dt> <dt> <span class="section"> <a href="mysql-shell-tutorial-javascript-indexes-create.html"> 22.3.3.6 Create and Drop Indexes </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045128015632"> </a> <p> When you are using MySQL as a Document Store, collections are containers within a schema that you can create, list, and drop. Collections contain JSON documents that you can add, find, update, and remove. </p> <p> The examples in this section use the <code class="literal"> countryinfo </code> collection in the <code class="literal"> world_x </code> schema. For instructions on setting up the <code class="literal"> world_x </code> schema, see <a class="xref" href="mysql-shell-tutorial-javascript-download.html" title="22.3.2 Download and Import world_x Database"> Section 22.3.2, “Download and Import world_x Database” </a> . </p> <h4> <a name="mysql-shell-tutorial-javascript-documents"> </a> Documents </h4> <p> In MySQL, documents are represented as JSON objects. Internally, they are stored in an efficient binary format that enables fast lookups and updates. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Simple document format for JavaScript: </p> <pre class="screen">{field1: "value", field2 : 10, "field 3": null} </pre> </li> </ul> </div> <p> An array of documents consists of a set of documents separated by commas and enclosed within <code class="literal"> [ </code> and <code class="literal"> ] </code> characters. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Simple array of documents for JavaScript: </p> <pre class="screen">[{"Name": "Aruba", "Code:": "ABW"}, {"Name": "Angola", "Code:": "AGO"}] </pre> </li> </ul> </div> <p> MySQL supports the following JavaScript value types in JSON documents: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> numbers (integer and floating point) </p> </li> <li class="listitem"> <p> strings </p> </li> <li class="listitem"> <p> boolean (False and True) </p> </li> <li class="listitem"> <p> null </p> </li> <li class="listitem"> <p> arrays of more JSON values </p> </li> <li class="listitem"> <p> nested (or embedded) objects of more JSON values </p> </li> </ul> </div> <h4> <a name="mysql-shell-tutorial-javascript-collections"> </a> Collections </h4> <p> Collections are containers for documents that share a purpose and possibly share one or more indexes. Each collection has a unique name and exists within a single schema. </p> <p> The term schema is equivalent to a database, which means a group of database objects as opposed to a relational schema, used to enforce structure and constraints over data. A schema does not enforce conformity on the documents in a collection. </p> <p> In this quick-start guide: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Basic objects include: </p> <div class="informaltable"> <table summary="Objects to use interactively in MySQL Shell"> <colgroup> <col style="width: 40%"/> <col style="width: 60%"/> </colgroup> <thead> <tr> <th> Object form </th> <th> Description </th> </tr> </thead> <tbody> <tr> <td> <code class="literal"> db </code> </td> <td> <code class="literal"> db </code> is a global variable assigned to the current active schema. When you want to run operations against the schema, for example to retrieve a collection, you use methods available for the <code class="literal"> db </code> variable. </td> </tr> <tr> <td> <code class="literal"> db.getCollections() </code> </td> <td> <a class="link" href="mysql-shell-tutorial-javascript-collections-operations.html#mysql-shell-tutorial-javascript-collections-get" title="List Collections"> db.getCollections() </a> returns a list of collections in the schema. Use the list to get references to collection objects, iterate over them, and so on. </td> </tr> </tbody> </table> </div> </li> <li class="listitem"> <p> Basic operations scoped by collections include: </p> <div class="informaltable"> <table summary="CRUD operations available in X DevAPI"> <colgroup> <col style="width: 40%"/> <col style="width: 60%"/> </colgroup> <thead> <tr> <th> Operation form </th> <th> Description </th> </tr> </thead> <tbody> <tr> <td> <code class="literal"> db. <em class="replaceable"> <code> name </code> </em> .add() </code> </td> <td> The <a class="link" href="mysql-shell-tutorial-javascript-collections-add.html" title="22.3.3.2 Working with Collections"> add() </a> method inserts one document or a list of documents into the named collection. </td> </tr> <tr> <td> <code class="literal"> db. <em class="replaceable"> <code> name </code> </em> .find() </code> </td> <td> The <a class="link" href="mysql-shell-tutorial-javascript-documents-find.html" title="22.3.3.3 Find Documents"> find() </a> method returns some or all documents in the named collection. </td> </tr> <tr> <td> <code class="literal"> db. <em class="replaceable"> <code> name </code> </em> .modify() </code> </td> <td> The <a class="link" href="mysql-shell-tutorial-javascript-documents-modify.html" title="22.3.3.4 Modify Documents"> modify() </a> method updates documents in the named collection. </td> </tr> <tr> <td> <code class="literal"> db. <em class="replaceable"> <code> name </code> </em> .remove() </code> </td> <td> The <a class="link" href="mysql-shell-tutorial-javascript-documents-remove.html" title="22.3.3.5 Remove Documents"> remove() </a> method deletes one document or a list of documents from the named collection. </td> </tr> </tbody> </table> </div> </li> </ul> </div> <h4> <a name="idm46045127957440"> </a> Related Information </h4> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> See <a class="ulink" href="/doc/x-devapi-userguide/en/devapi-users-working-with-collections.html" target="_top"> Working with Collections </a> for a general overview. </p> </li> <li class="listitem"> <p> <a class="ulink" href="/doc/x-devapi-userguide/en/mysql-x-crud-ebnf-definitions.html" target="_top"> CRUD EBNF Definitions </a> provides a complete list of operations. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/thread-pool.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="thread-pool"> </a> 7.6.3 MySQL Enterprise Thread Pool </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="thread-pool-elements.html"> 7.6.3.1 Thread Pool Elements </a> </span> </dt> <dt> <span class="section"> <a href="thread-pool-installation.html"> 7.6.3.2 Thread Pool Installation </a> </span> </dt> <dt> <span class="section"> <a href="thread-pool-operation.html"> 7.6.3.3 Thread Pool Operation </a> </span> </dt> <dt> <span class="section"> <a href="thread-pool-tuning.html"> 7.6.3.4 Thread Pool Tuning </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045256870816"> </a> <a class="indexterm" name="idm46045256869760"> </a> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> MySQL Enterprise Thread Pool is an extension included in MySQL Enterprise Edition, a commercial product. To learn more about commercial products, <a class="ulink" href="https://www.mysql.com/products/" target="_blank"> https://www.mysql.com/products/ </a> . </p> </div> <p> MySQL Enterprise Edition includes MySQL Enterprise Thread Pool, implemented using a server plugin. The default thread-handling model in MySQL Server executes statements using one thread per client connection. As more clients connect to the server and execute statements, overall performance degrades. The thread pool plugin provides an alternative thread-handling model designed to reduce overhead and improve performance. The plugin implements a thread pool that increases server performance by efficiently managing statement execution threads for large numbers of client connections. </p> <p> The thread pool addresses several problems of the model that uses one thread per connection: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Too many thread stacks make CPU caches almost useless in highly parallel execution workloads. The thread pool promotes thread stack reuse to minimize the CPU cache footprint. </p> </li> <li class="listitem"> <p> With too many threads executing in parallel, context switching overhead is high. This also presents a challenge to the operating system scheduler. The thread pool controls the number of active threads to keep the parallelism within the MySQL server at a level that it can handle and that is appropriate for the server host on which MySQL is executing. </p> </li> <li class="listitem"> <p> Too many transactions executing in parallel increases resource contention. In <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine"> <code class="literal"> InnoDB </code> </a> , this increases the time spent holding central mutexes. The thread pool controls when transactions start to ensure that not too many execute in parallel. </p> </li> </ul> </div> <h4> <a name="idm46045256860304"> </a> Additional Resources </h4> <p> <a class="xref" href="faqs-thread-pool.html" title="A.15 MySQL 8.4 FAQ: MySQL Enterprise Thread Pool"> Section A.15, “MySQL 8.4 FAQ: MySQL Enterprise Thread Pool” </a> </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-shell-tutorial-javascript-documents-find.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="mysql-shell-tutorial-javascript-documents-find"> </a> 22.3.3.3 Find Documents </h4> </div> </div> </div> <a class="indexterm" name="idm46045127886560"> </a> <p> You can use the <code class="literal"> find() </code> method to query for and return documents from a collection in a schema. MySQL Shell provides additional methods to use with the <code class="literal"> find() </code> method to filter and sort the returned documents. </p> <p> MySQL provides the following operators to specify search conditions: <code class="literal"> OR </code> ( <code class="literal"> || </code> ), <code class="literal"> AND </code> ( <code class="literal"> &amp;&amp; </code> ), <code class="literal"> XOR </code> , <code class="literal"> IS </code> , <code class="literal"> NOT </code> , <code class="literal"> BETWEEN </code> , <code class="literal"> IN </code> , <code class="literal"> LIKE </code> , <code class="literal"> != </code> , <code class="literal"> &lt;&gt; </code> , <code class="literal"> &gt; </code> , <code class="literal"> &gt;= </code> , <code class="literal"> &lt; </code> , <code class="literal"> &lt;= </code> , <code class="literal"> &amp; </code> , <code class="literal"> | </code> , <code class="literal"> &lt;&lt; </code> , <code class="literal"> &gt;&gt; </code> , <code class="literal"> + </code> , <code class="literal"> - </code> , <code class="literal"> * </code> , <code class="literal"> / </code> , <code class="literal"> ~ </code> , and <code class="literal"> % </code> . </p> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="mysql-shell-tutorial-javascript-documents-find-all"> </a> Find All Documents in a Collection </h5> </div> </div> </div> <a class="indexterm" name="idm46045127863488"> </a> <p> To return all documents in a collection, use the <code class="literal"> find() </code> method without specifying search conditions. For example, the following operation returns all documents in the <code class="literal"> countryinfo </code> collection. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa36442313"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">828</span><span class="token punctuation">,</span> <span class="token property">"Code:"</span><span class="token operator">:</span> <span class="token string">"ABW"</span><span class="token punctuation">,</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"Aruba"</span><span class="token punctuation">,</span> <span class="token property">"IndepYear"</span><span class="token operator">:</span> <span class="token null">null</span><span class="token punctuation">,</span> <span class="token property">"geography"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Continent"</span><span class="token operator">:</span> <span class="token string">"North America"</span><span class="token punctuation">,</span> <span class="token property">"Region"</span><span class="token operator">:</span> <span class="token string">"Caribbean"</span><span class="token punctuation">,</span> <span class="token property">"SurfaceArea"</span><span class="token operator">:</span> <span class="token number">193</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"government"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"GovernmentForm"</span><span class="token operator">:</span> <span class="token string">"Nonmetropolitan Territory of The Netherlands"</span><span class="token punctuation">,</span> <span class="token property">"HeadOfState"</span><span class="token operator">:</span> <span class="token string">"Beatrix"</span> <span class="token punctuation">}</span> <span class="token property">"demographics"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"LifeExpectancy"</span><span class="token operator">:</span> <span class="token number">78.4000015258789</span><span class="token punctuation">,</span> <span class="token property">"Population"</span><span class="token operator">:</span> <span class="token number">103000</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">240 documents in set (0.00 sec)</span></code></pre> </div> <p> The method produces results that contain operational information in addition to all documents in the collection. </p> <p> An empty set (no matching documents) returns the following information: </p> <pre class="screen">Empty set (0.00 sec) </pre> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="mysql-shell-tutorial-javascript-documents-find-filter-searches"> </a> Filter Searches </h5> </div> </div> </div> <a class="indexterm" name="idm46045127854640"> </a> <p> You can include search conditions with the <code class="literal"> find() </code> method. The syntax for expressions that form a search condition is the same as that of traditional MySQL <a class="xref" href="functions.html" title="Chapter 14 Functions and Operators"> Chapter 14, <i> Functions and Operators </i> </a> . You must enclose all expressions in quotes. For the sake of brevity, some of the examples do not display output. </p> <p> A simple search condition could consist of the <code class="literal"> Name </code> field and a value we know is in a document. The following example returns a single document: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa49397270"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"Name = 'Australia'"</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">351182</span><span class="token punctuation">,</span> <span class="token property">"Code:"</span><span class="token operator">:</span> <span class="token string">"AUS"</span><span class="token punctuation">,</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"Australia"</span><span class="token punctuation">,</span> <span class="token property">"IndepYear"</span><span class="token operator">:</span> <span class="token number">1901</span><span class="token punctuation">,</span> <span class="token property">"geography"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Continent"</span><span class="token operator">:</span> <span class="token string">"Oceania"</span><span class="token punctuation">,</span> <span class="token property">"Region"</span><span class="token operator">:</span> <span class="token string">"Australia and New Zealand"</span><span class="token punctuation">,</span> <span class="token property">"SurfaceArea"</span><span class="token operator">:</span> <span class="token number">7741220</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"government"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"GovernmentForm"</span><span class="token operator">:</span> <span class="token string">"Constitutional Monarchy, Federation"</span><span class="token punctuation">,</span> <span class="token property">"HeadOfState"</span><span class="token operator">:</span> <span class="token string">"Elisabeth II"</span> <span class="token punctuation">}</span> <span class="token property">"demographics"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"LifeExpectancy"</span><span class="token operator">:</span> <span class="token number">79.80000305175781</span><span class="token punctuation">,</span> <span class="token property">"Population"</span><span class="token operator">:</span> <span class="token number">18886000</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> The following example searches for all countries that have a GNP higher than $500 billion. The <code class="literal"> countryinfo </code> collection measures GNP in units of million. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa29624110"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"GNP &gt; 500000"</span><span class="token punctuation">)</span> <span class="token operator">...</span><span class="token punctuation">[</span><em>output removed</em><span class="token punctuation">]</span> <span class="token output">10 documents in set (0.00 sec)</span></code></pre> </div> <p> The Population field in the following query is embedded within the demographics object. To access the embedded field, use a period between demographics and Population to identify the relationship. Document and field names are case-sensitive. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa5570606"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"GNP &gt; 500000 and demographics.Population &lt; 100000000"</span><span class="token punctuation">)</span> <span class="token operator">...</span><span class="token punctuation">[</span><em>output removed</em><span class="token punctuation">]</span> <span class="token output">6 documents in set (0.00 sec)</span></code></pre> </div> <p> Arithmetic operators in the following expression are used to query for countries with a GNP per capita higher than $30000. Search conditions can include arithmetic operators and most MySQL functions. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Seven documents in the <code class="literal"> countryinfo </code> collection have a population value of zero. Therefore warning messages appear at the end of the output. </p> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa82136603"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"GNP*1000000/demographics.Population &gt; 30000"</span><span class="token punctuation">)</span> <span class="token operator">...</span><span class="token punctuation">[</span><em>output removed</em><span class="token punctuation">]</span> <span class="token output">9 documents in set, 7 warnings (0.00 sec)</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span> Warning <span class="token punctuation">(</span>Code <span class="token number">1365</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Division by <span class="token number">0</span></code></pre> </div> <p> You can separate a value from the search condition by using the <code class="literal"> bind() </code> method. For example, instead of specifying a hard-coded country name as the condition, substitute a named placeholder consisting of a colon followed by a name that begins with a letter, such as <span class="emphasis"> <em> country </em> </span> . Then use the <code class="literal"> bind( <em class="replaceable"> <code> placeholder </code> </em> , <em class="replaceable"> <code> value </code> </em> ) </code> method as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa99167742"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"Name = :country"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token string">"country"</span><span class="token punctuation">,</span> <span class="token string">"Italy"</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">{</span> <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">1161755</span><span class="token punctuation">,</span> <span class="token property">"_id"</span><span class="token operator">:</span> <span class="token string">"00005de917d8000000000000006a"</span><span class="token punctuation">,</span> <span class="token property">"Code"</span><span class="token operator">:</span> <span class="token string">"ITA"</span><span class="token punctuation">,</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"Italy"</span><span class="token punctuation">,</span> <span class="token property">"Airports"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"IndepYear"</span><span class="token operator">:</span> <span class="token number">1861</span><span class="token punctuation">,</span> <span class="token property">"geography"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Region"</span><span class="token operator">:</span> <span class="token string">"Southern Europe"</span><span class="token punctuation">,</span> <span class="token property">"Continent"</span><span class="token operator">:</span> <span class="token string">"Europe"</span><span class="token punctuation">,</span> <span class="token property">"SurfaceArea"</span><span class="token operator">:</span> <span class="token number">301316</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"government"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"HeadOfState"</span><span class="token operator">:</span> <span class="token string">"Carlo Azeglio Ciampi"</span><span class="token punctuation">,</span> <span class="token property">"GovernmentForm"</span><span class="token operator">:</span> <span class="token string">"Republic"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"demographics"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Population"</span><span class="token operator">:</span> <span class="token number">57680000</span><span class="token punctuation">,</span> <span class="token property">"LifeExpectancy"</span><span class="token operator">:</span> <span class="token number">79</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span></span> <span class="token output">1 document in set (0.01 sec)</span></code></pre> </div> <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Tip </div> <p> Within a program, binding enables you to specify placeholders in your expressions, which are filled in with values before execution and can benefit from automatic escaping, as appropriate. </p> <p> Always use binding to sanitize input. Avoid introducing values in queries using string concatenation, which can produce invalid input and, in some cases, can cause security issues. </p> </div> <p> You can use placeholders and the <code class="literal"> bind() </code> method to create saved searches which you can then call with different values. For example to create a saved search for a country: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa65128810"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> <span class="token keyword">var</span> myFind <span class="token operator">=</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"Name = :country"</span><span class="token punctuation">)</span> <span class="token prompt">mysql-js&gt;</span> myFind<span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token string">'country'</span><span class="token punctuation">,</span> <span class="token string">'France'</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">{</span> <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">1424285</span><span class="token punctuation">,</span> <span class="token property">"_id"</span><span class="token operator">:</span> <span class="token string">"00005de917d80000000000000048"</span><span class="token punctuation">,</span> <span class="token property">"Code"</span><span class="token operator">:</span> <span class="token string">"FRA"</span><span class="token punctuation">,</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"France"</span><span class="token punctuation">,</span> <span class="token property">"IndepYear"</span><span class="token operator">:</span> <span class="token number">843</span><span class="token punctuation">,</span> <span class="token property">"geography"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Region"</span><span class="token operator">:</span> <span class="token string">"Western Europe"</span><span class="token punctuation">,</span> <span class="token property">"Continent"</span><span class="token operator">:</span> <span class="token string">"Europe"</span><span class="token punctuation">,</span> <span class="token property">"SurfaceArea"</span><span class="token operator">:</span> <span class="token number">551500</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"government"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"HeadOfState"</span><span class="token operator">:</span> <span class="token string">"Jacques Chirac"</span><span class="token punctuation">,</span> <span class="token property">"GovernmentForm"</span><span class="token operator">:</span> <span class="token string">"Republic"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"demographics"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Population"</span><span class="token operator">:</span> <span class="token number">59225700</span><span class="token punctuation">,</span> <span class="token property">"LifeExpectancy"</span><span class="token operator">:</span> <span class="token number">78.80000305175781</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span></span> <span class="token output">1 document in set (0.0028 sec)</span> <span class="token prompt">mysql-js&gt;</span> myFind<span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token string">'country'</span><span class="token punctuation">,</span> <span class="token string">'Germany'</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">{</span> <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">2133367</span><span class="token punctuation">,</span> <span class="token property">"_id"</span><span class="token operator">:</span> <span class="token string">"00005de917d80000000000000038"</span><span class="token punctuation">,</span> <span class="token property">"Code"</span><span class="token operator">:</span> <span class="token string">"DEU"</span><span class="token punctuation">,</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"Germany"</span><span class="token punctuation">,</span> <span class="token property">"IndepYear"</span><span class="token operator">:</span> <span class="token number">1955</span><span class="token punctuation">,</span> <span class="token property">"geography"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Region"</span><span class="token operator">:</span> <span class="token string">"Western Europe"</span><span class="token punctuation">,</span> <span class="token property">"Continent"</span><span class="token operator">:</span> <span class="token string">"Europe"</span><span class="token punctuation">,</span> <span class="token property">"SurfaceArea"</span><span class="token operator">:</span> <span class="token number">357022</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"government"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"HeadOfState"</span><span class="token operator">:</span> <span class="token string">"Johannes Rau"</span><span class="token punctuation">,</span> <span class="token property">"GovernmentForm"</span><span class="token operator">:</span> <span class="token string">"Federal Republic"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"demographics"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"Population"</span><span class="token operator">:</span> <span class="token number">82164700</span><span class="token punctuation">,</span> <span class="token property">"LifeExpectancy"</span><span class="token operator">:</span> <span class="token number">77.4000015258789</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span></span> <span class="token output">1 document in set (0.0026 sec)</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="idm46045127822800"> </a> Project Results </h5> </div> </div> </div> <a class="indexterm" name="idm46045127822128"> </a> <p> You can return specific fields of a document, instead of returning all the fields. The following example returns the GNP and Name fields of all documents in the <code class="literal"> countryinfo </code> collection matching the search conditions. </p> <p> Use the <code class="literal"> fields() </code> method to pass the list of fields to return. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa19696706"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">"GNP &gt; 5000000"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">fields</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">"GNP"</span><span class="token punctuation">,</span> <span class="token string">"Name"</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"GNP"</span><span class="token operator">:</span> <span class="token number">8510700</span><span class="token punctuation">,</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"United States"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span></span> <span class="token output">1 document in set (0.00 sec)</span></code></pre> </div> <p> In addition, you can alter the returned documents—adding, renaming, nesting and even computing new field values—with an expression that describes the document to return. For example, alter the names of the fields with the following expression to return only two documents. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa58614433"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">fields</span><span class="token punctuation">(</span> mysqlx<span class="token punctuation">.</span><span class="token function">expr</span><span class="token punctuation">(</span><span class="token string">'{"Name": upper(Name), "GNPPerCapita": GNP*1000000/demographics.Population}'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">limit</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token inlinejson"><span class="token punctuation">{</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"ARUBA"</span><span class="token punctuation">,</span> <span class="token property">"GNPPerCapita"</span><span class="token operator">:</span> <span class="token number">8038.834951456311</span> <span class="token punctuation">}</span> <span class="token punctuation">{</span> <span class="token property">"Name"</span><span class="token operator">:</span> <span class="token string">"AFGHANISTAN"</span><span class="token punctuation">,</span> <span class="token property">"GNPPerCapita"</span><span class="token operator">:</span> <span class="token number">263.0281690140845</span> <span class="token punctuation">}</span></span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="idm46045127813040"> </a> Limit, Sort, and Skip Results </h5> </div> </div> </div> <a class="indexterm" name="idm46045127812352"> </a> <p> You can apply the <code class="literal"> limit() </code> , <code class="literal"> sort() </code> , and <code class="literal"> skip() </code> methods to manage the number and order of documents returned by the <code class="literal"> find() </code> method. </p> <p> To specify the number of documents included in a result set, append the <code class="literal"> limit() </code> method with a value to the <code class="literal"> find() </code> method. The following query returns the first five documents in the <code class="literal"> countryinfo </code> collection. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa65582705"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">limit</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">...</span> <span class="token punctuation">[</span><em>output removed</em><span class="token punctuation">]</span> <span class="token output">5 documents in set (0.00 sec)</span></code></pre> </div> <p> To specify an order for the results, append the <code class="literal"> sort() </code> method to the <code class="literal"> find() </code> method. Pass to the <code class="literal"> sort() </code> method a list of one or more fields to sort by and, optionally, the descending ( <code class="literal"> desc </code> ) or ascending ( <code class="literal"> asc </code> ) attribute as appropriate. Ascending order is the default order type. </p> <p> For example, the following query sorts all documents by the IndepYear field and then returns the first eight documents in descending order. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa59708222"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">"IndepYear desc"</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">limit</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span> <span class="token operator">...</span> <span class="token punctuation">[</span><em>output removed</em><span class="token punctuation">]</span> <span class="token output">8 documents in set (0.00 sec)</span></code></pre> </div> <p> By default, the <code class="literal"> limit() </code> method starts from the first document in the collection. You can use the <code class="literal"> skip() </code> method to change the starting document. For example, to ignore the first document and return the next eight documents matching the condition, pass to the <code class="literal"> skip() </code> method a value of 1. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa43764905"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> db<span class="token punctuation">.</span>countryinfo<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">"IndepYear desc"</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">limit</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">skip</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">...</span> <span class="token punctuation">[</span><em>output removed</em><span class="token punctuation">]</span> <span class="token output">8 documents in set (0.00 sec)</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="idm46045127790304"> </a> Related Information </h5> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The <a class="link" href="functions.html" title="Chapter 14 Functions and Operators"> MySQL Reference Manual </a> provides detailed documentation on functions and operators. </p> </li> <li class="listitem"> <p> See <a class="ulink" href="/doc/x-devapi-userguide/en/crud-ebnf-collection-crud-functions.html#crud-ebnf-collectionfindfunction" target="_top"> CollectionFindFunction </a> for the full syntax definition. </p> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/ldml-rules.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="ldml-rules"> </a> 12.14.4.2 LDML Syntax Supported in MySQL </h4> </div> </div> </div> <a class="indexterm" name="idm46045215060544"> </a> <p> This section describes the LDML syntax that MySQL recognizes. This is a subset of the syntax described in the LDML specification available at <a class="ulink" href="http://www.unicode.org/reports/tr35/" target="_blank"> http://www.unicode.org/reports/tr35/ </a> , which should be consulted for further information. MySQL recognizes a large enough subset of the syntax that, in many cases, it is possible to download a collation definition from the Unicode Common Locale Data Repository and paste the relevant part (that is, the part between the <code class="literal"> &lt;rules&gt; </code> and <code class="literal"> &lt;/rules&gt; </code> tags) into the MySQL <code class="filename"> Index.xml </code> file. The rules described here are all supported except that character sorting occurs only at the primary level. Rules that specify differences at secondary or higher sort levels are recognized (and thus can be included in collation definitions) but are treated as equality at the primary level. </p> <p> The MySQL server generates diagnostics when it finds problems while parsing the <code class="filename"> Index.xml </code> file. See <a class="xref" href="collation-diagnostics.html" title="12.14.4.3 Diagnostics During Index.xml Parsing"> Section 12.14.4.3, “Diagnostics During Index.xml Parsing” </a> . </p> <p> <span class="bold"> <strong> Character Representation </strong> </span> </p> <p> Characters named in LDML rules can be written literally or in <code class="literal"> \u <em class="replaceable"> <code> nnnn </code> </em> </code> format, where <em class="replaceable"> <code> nnnn </code> </em> is the hexadecimal Unicode code point value. For example, <code class="literal"> A </code> and <code class="literal"> á </code> can be written literally or as <code class="literal"> \u0041 </code> and <code class="literal"> \u00E1 </code> . Within hexadecimal values, the digits <code class="literal"> A </code> through <code class="literal"> F </code> are not case-sensitive; <code class="literal"> \u00E1 </code> and <code class="literal"> \u00e1 </code> are equivalent. For UCA 4.0.0 collations, hexadecimal notation can be used only for characters in the Basic Multilingual Plane, not for characters outside the BMP range of <code class="literal"> 0000 </code> to <code class="literal"> FFFF </code> . For UCA 5.2.0 collations, hexadecimal notation can be used for any character. </p> <p> The <code class="filename"> Index.xml </code> file itself should be written using UTF-8 encoding. </p> <p> <span class="bold"> <strong> Syntax Rules </strong> </span> </p> <p> LDML has reset rules and shift rules to specify character ordering. Orderings are given as a set of rules that begin with a reset rule that establishes an anchor point, followed by shift rules that indicate how characters sort relative to the anchor point. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A <code class="literal"> &lt;reset&gt; </code> rule does not specify any ordering in and of itself. Instead, it <span class="quote"> “ <span class="quote"> resets </span> ” </span> the ordering for subsequent shift rules to cause them to be taken in relation to a given character. Either of the following rules resets subsequent shift rules to be taken in relation to the letter <code class="literal"> 'A' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa16353630"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>A<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>\u0041<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> The <code class="literal"> &lt;p&gt; </code> , <code class="literal"> &lt;s&gt; </code> , and <code class="literal"> &lt;t&gt; </code> shift rules define primary, secondary, and tertiary differences of a character from another character: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Use primary differences to distinguish separate letters. </p> </li> <li class="listitem"> <p> Use secondary differences to distinguish accent variations. </p> </li> <li class="listitem"> <p> Use tertiary differences to distinguish lettercase variations. </p> </li> </ul> </div> <p> Either of these rules specifies a primary shift rule for the <code class="literal"> 'G' </code> character: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa12427996"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>G<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>\u0047<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> The <code class="literal"> &lt;i&gt; </code> shift rule indicates that one character sorts identically to another. The following rules cause <code class="literal"> 'b' </code> to sort the same as <code class="literal"> 'a' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa50691149"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>a<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>i</span><span class="token punctuation">&gt;</span></span>b<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>i</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> Abbreviated shift syntax specifies multiple shift rules using a single pair of tags. The following table shows the correspondence between abbreviated syntax rules and the equivalent nonabbreviated rules. </p> <div class="table"> <a name="abreviated-shift-syntax"> </a> <p class="title"> <b> Table 12.5 Abbreviated Shift Syntax </b> </p> <div class="table-contents"> <table summary="Abbreviated and corresponding nonabbreviated shift syntax rules."> <colgroup> <col style="width: 40%"/> <col style="width: 60%"/> </colgroup> <thead> <tr> <th> Abbreviated Syntax </th> <th> Nonabbreviated Syntax </th> </tr> </thead> <tbody> <tr> <td> <code class="literal"> &lt;pc&gt;xyz&lt;/pc&gt; </code> </td> <td> <code class="literal"> &lt;p&gt;x&lt;/p&gt;&lt;p&gt;y&lt;/p&gt;&lt;p&gt;z&lt;/p&gt; </code> </td> </tr> <tr> <td> <code class="literal"> &lt;sc&gt;xyz&lt;/sc&gt; </code> </td> <td> <code class="literal"> &lt;s&gt;x&lt;/s&gt;&lt;s&gt;y&lt;/s&gt;&lt;s&gt;z&lt;/s&gt; </code> </td> </tr> <tr> <td> <code class="literal"> &lt;tc&gt;xyz&lt;/tc&gt; </code> </td> <td> <code class="literal"> &lt;t&gt;x&lt;/t&gt;&lt;t&gt;y&lt;/t&gt;&lt;t&gt;z&lt;/t&gt; </code> </td> </tr> <tr> <td> <code class="literal"> &lt;ic&gt;xyz&lt;/ic&gt; </code> </td> <td> <code class="literal"> &lt;i&gt;x&lt;/i&gt;&lt;i&gt;y&lt;/i&gt;&lt;i&gt;z&lt;/i&gt; </code> </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> </li> <li class="listitem"> <p> An expansion is a reset rule that establishes an anchor point for a multiple-character sequence. MySQL supports expansions 2 to 6 characters long. The following rules put <code class="literal"> 'z' </code> greater at the primary level than the sequence of three characters <code class="literal"> 'abc' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa48702883"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>abc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>z<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> A contraction is a shift rule that sorts a multiple-character sequence. MySQL supports contractions 2 to 6 characters long. The following rules put the sequence of three characters <code class="literal"> 'xyz' </code> greater at the primary level than <code class="literal"> 'a' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa44079442"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>a<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>xyz<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> Long expansions and long contractions can be used together. These rules put the sequence of three characters <code class="literal"> 'xyz' </code> greater at the primary level than the sequence of three characters <code class="literal"> 'abc' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa40078073"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>abc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>xyz<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> Normal expansion syntax uses <code class="literal"> &lt;x&gt; </code> plus <code class="literal"> &lt;extend&gt; </code> elements to specify an expansion. The following rules put the character <code class="literal"> 'k' </code> greater at the secondary level than the sequence <code class="literal"> 'ch' </code> . That is, <code class="literal"> 'k' </code> behaves as if it expands to a character after <code class="literal"> 'c' </code> followed by <code class="literal"> 'h' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa99695074"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>c<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>x</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>s</span><span class="token punctuation">&gt;</span></span>k<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>s</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>extend</span><span class="token punctuation">&gt;</span></span>h<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>extend</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>x</span><span class="token punctuation">&gt;</span></span></code></pre> </div> <p> This syntax permits long sequences. These rules sort the sequence <code class="literal"> 'ccs' </code> greater at the tertiary level than the sequence <code class="literal"> 'cscs' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa46665990"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>cs<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>x</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>t</span><span class="token punctuation">&gt;</span></span>ccs<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>t</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>extend</span><span class="token punctuation">&gt;</span></span>cs<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>extend</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>x</span><span class="token punctuation">&gt;</span></span></code></pre> </div> <p> The LDML specification describes normal expansion syntax as <span class="quote"> “ <span class="quote"> tricky. </span> ” </span> See that specification for details. </p> </li> <li class="listitem"> <p> Previous context syntax uses <code class="literal"> &lt;x&gt; </code> plus <code class="literal"> &lt;context&gt; </code> elements to specify that the context before a character affects how it sorts. The following rules put <code class="literal"> '-' </code> greater at the secondary level than <code class="literal"> 'a' </code> , but only when <code class="literal"> '-' </code> occurs after <code class="literal"> 'b' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa88155943"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>a<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>x</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>context</span><span class="token punctuation">&gt;</span></span>b<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>context</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>s</span><span class="token punctuation">&gt;</span></span>-<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>s</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>x</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> Previous context syntax can include the <code class="literal"> &lt;extend&gt; </code> element. These rules put <code class="literal"> 'def' </code> greater at the primary level than <code class="literal"> 'aghi' </code> , but only when <code class="literal"> 'def' </code> comes after <code class="literal"> 'abc' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa70885827"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>a<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>x</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>context</span><span class="token punctuation">&gt;</span></span>abc<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>context</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>def<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>extend</span><span class="token punctuation">&gt;</span></span>ghi<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>extend</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>x</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> Reset rules permit a <code class="literal"> before </code> attribute. Normally, shift rules after a reset rule indicate characters that sort after the reset character. Shift rules after a reset rule that has the <code class="literal"> before </code> attribute indicate characters that sort before the reset character. The following rules put the character <code class="literal"> 'b' </code> immediately before <code class="literal"> 'a' </code> at the primary level: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa9601871"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>a<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>b<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre> </div> <p> Permissible <code class="literal"> before </code> attribute values specify the sort level by name or the equivalent numeric value: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa43912994"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>secondary<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>tertiary<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span> <span class="token attr-name">before</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>3<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span></code></pre> </div> </li> <li class="listitem"> <p> A reset rule can name a logical reset position rather than a literal character: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa16695479"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>first_tertiary_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_tertiary_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>first_secondary_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_secondary_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>first_primary_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_primary_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>first_variable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_variable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>first_non_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_non_ignorable</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>first_trailing</span><span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_trailing</span><span class="token punctuation">/&gt;</span></span></code></pre> </div> <p> These rules put <code class="literal"> 'z' </code> greater at the primary level than nonignorable characters that have a Default Unicode Collation Element Table (DUCET) entry and that are not CJK: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa27369716"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>last_non_ignorable</span><span class="token punctuation">/&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>z<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span></code></pre> </div> <p> Logical positions have the code points shown in the following table. </p> <div class="table"> <a name="logical-reset-position-code-points"> </a> <p class="title"> <b> Table 12.6 Logical Reset Position Code Points </b> </p> <div class="table-contents"> <table summary="Logical positions and Unicode 4.0.0 and Unicode 5.2.0 code points."> <colgroup> <col style="width: 40%"/> <col style="width: 30%"/> <col style="width: 30%"/> </colgroup> <thead> <tr> <th scope="col"> Logical Position </th> <th scope="col"> Unicode 4.0.0 Code Point </th> <th scope="col"> Unicode 5.2.0 Code Point </th> </tr> </thead> <tbody> <tr> <th scope="row"> <code class="literal"> &lt;first_non_ignorable/&gt; </code> </th> <td> U+02D0 </td> <td> U+02D0 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;last_non_ignorable/&gt; </code> </th> <td> U+A48C </td> <td> U+1342E </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;first_primary_ignorable/&gt; </code> </th> <td> U+0332 </td> <td> U+0332 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;last_primary_ignorable/&gt; </code> </th> <td> U+20EA </td> <td> U+101FD </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;first_secondary_ignorable/&gt; </code> </th> <td> U+0000 </td> <td> U+0000 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;last_secondary_ignorable/&gt; </code> </th> <td> U+FE73 </td> <td> U+FE73 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;first_tertiary_ignorable/&gt; </code> </th> <td> U+0000 </td> <td> U+0000 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;last_tertiary_ignorable/&gt; </code> </th> <td> U+FE73 </td> <td> U+FE73 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;first_trailing/&gt; </code> </th> <td> U+0000 </td> <td> U+0000 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;last_trailing/&gt; </code> </th> <td> U+0000 </td> <td> U+0000 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;first_variable/&gt; </code> </th> <td> U+0009 </td> <td> U+0009 </td> </tr> <tr> <th scope="row"> <code class="literal"> &lt;last_variable/&gt; </code> </th> <td> U+2183 </td> <td> U+1D371 </td> </tr> </tbody> </table> </div> <div class="table-contents"> <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 431px; width: 607px;"> <thead> <tr> <th scope="col" style="width: 242.281px;"> Logical Position </th> <th scope="col" style="width: 181.703px;"> Unicode 4.0.0 Code Point </th> <th scope="col" style="width: 181.734px;"> Unicode 5.2.0 Code Point </th> </tr> </thead> </table> </div> </div> <br class="table-break"/> </li> <li class="listitem"> <p> The <code class="literal"> &lt;collation&gt; </code> element permits a <code class="literal"> shift-after-method </code> attribute that affects character weight calculation for shift rules. The attribute has these permitted values: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <code class="literal"> simple </code> : Calculate character weights as for reset rules that do not have a <code class="literal"> before </code> attribute. This is the default if the attribute is not given. </p> </li> <li class="listitem"> <p> <code class="literal"> expand </code> : Use expansions for shifts after reset rules. </p> </li> </ul> </div> <p> Suppose that <code class="literal"> '0' </code> and <code class="literal"> '1' </code> have weights of <code class="literal"> 0E29 </code> and <code class="literal"> 0E2A </code> and we want to put all basic Latin letters between <code class="literal"> '0' </code> and <code class="literal"> '1' </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa85076258"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>reset</span><span class="token punctuation">&gt;</span></span>0<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>reset</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>pc</span><span class="token punctuation">&gt;</span></span>abcdefghijklmnopqrstuvwxyz<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>pc</span><span class="token punctuation">&gt;</span></span></code></pre> </div> <p> For simple shift mode, weights are calculated as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa11454493"><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-none">'a' has weight 0E29+1 'b' has weight 0E29+2 'c' has weight 0E29+3 ...</code></pre> </div> <p> However, there are not enough vacant positions to put 26 characters between <code class="literal"> '0' </code> and <code class="literal"> '1' </code> . The result is that digits and letters are intermixed. </p> <p> To solve this, use <code class="literal"> shift-after-method="expand" </code> . Then weights are calculated like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa29372544"><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-none">'a' has weight [0E29][233D+1] 'b' has weight [0E29][233D+2] 'c' has weight [0E29][233D+3] ...</code></pre> </div> <p> <code class="literal"> 233D </code> is the UCA 4.0.0 weight for character <code class="literal"> 0xA48C </code> , which is the last nonignorable character (a sort of the greatest character in the collation, excluding CJK). UCA 5.2.0 is similar but uses <code class="literal"> 3ACA </code> , for character <code class="literal"> 0x1342E </code> . </p> </li> </ul> </div> <p> <span class="bold"> <strong> MySQL-Specific LDML Extensions </strong> </span> </p> <p> An extension to LDML rules permits the <code class="literal"> &lt;collation&gt; </code> element to include an optional <code class="literal"> version </code> attribute in <code class="literal"> &lt;collation&gt; </code> tags to indicate the UCA version on which the collation is based. If the <code class="literal"> version </code> attribute is omitted, its default value is <code class="literal"> 4.0.0 </code> . For example, this specification indicates a collation that is based on UCA 5.2.0: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-xml"><div class="docs-select-all right" id="sa77918906"><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-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>collation</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span><em class="replaceable">nnn</em><span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>utf8mb4_<em class="replaceable">xxx</em>_ci<span class="token punctuation">"</span></span> <span class="token attr-name">version</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>5.2.0<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span> ... <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>collation</span><span class="token punctuation">&gt;</span></span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/innodb-check-availability.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="innodb-check-availability"> </a> 17.1.3 Verifying that InnoDB is the Default Storage Engine </h3> </div> </div> </div> <p> Issue a <a class="link" href="show-engines.html" title="15.7.7.17 SHOW ENGINES Statement"> <code class="literal"> SHOW ENGINES </code> </a> statement to view the available MySQL storage engines. Look for <code class="literal"> DEFAULT </code> in the <code class="literal"> SUPPORT </code> column. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa63875120"><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">ENGINES</span><span class="token punctuation">;</span></code></pre> </div> <p> Alternatively, query the Information Schema <a class="link" href="information-schema-engines-table.html" title="28.3.13 The INFORMATION_SCHEMA ENGINES Table"> <code class="literal"> ENGINES </code> </a> table. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa20686110"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span><span class="token keyword">ENGINES</span><span class="token punctuation">;</span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/innodb-disabling-tablespace-path-validation.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="innodb-disabling-tablespace-path-validation"> </a> 17.6.3.7 Disabling Tablespace Path Validation </h4> </div> </div> </div> <p> At startup, <code class="literal"> InnoDB </code> scans directories defined by the <a class="link" href="innodb-parameters.html#sysvar_innodb_directories"> <code class="literal"> innodb_directories </code> </a> variable for tablespace files. The paths of discovered tablespace files are validated against the paths recorded in the data dictionary. If the paths do not match, the paths in the data dictionary are updated. </p> <p> The <a class="link" href="innodb-parameters.html#sysvar_innodb_validate_tablespace_paths"> <code class="literal"> innodb_validate_tablespace_paths </code> </a> variable permits disabling tablespace path validation. This feature is intended for environments where tablespaces files are not moved. Disabling path validation improves startup time on systems with a large number of tablespace files. If <a class="link" href="server-system-variables.html#sysvar_log_error_verbosity"> <code class="literal"> log_error_verbosity </code> </a> is set to 3, the following message is printed at startup when tablespace path validation is disabled: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa95487896"><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 punctuation">[</span>InnoDB<span class="token punctuation">]</span> Skipping InnoDB tablespace path validation<span class="token punctuation">.</span> Manually moved tablespace files will not be detected!</code></pre> </div> <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Warning </div> <p> Starting the server with tablespace path validation disabled after moving tablespace files can lead to undefined behavior. </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-single-user-mode.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="mysql-cluster-single-user-mode"> </a> 25.6.6 NDB Cluster Single User Mode </h3> </div> </div> </div> <a class="indexterm" name="idm46045092503392"> </a> <a class="indexterm" name="idm46045092501904"> </a> <p> <span class="firstterm"> Single user mode </span> enables the database administrator to restrict access to the database system to a single API node, such as a MySQL server (SQL node) or an instance of <a class="link" href="mysql-cluster-programs-ndb-restore.html" title="25.5.23 ndb_restore — Restore an NDB Cluster Backup"> <span class="command"> <strong> ndb_restore </strong> </span> </a> . When entering single user mode, connections to all other API nodes are closed gracefully and all running transactions are aborted. No new transactions are permitted to start. </p> <p> Once the cluster has entered single user mode, only the designated API node is granted access to the database. </p> <p> You can use the <code class="literal"> ALL STATUS </code> command in the <a class="link" href="mysql-cluster-programs-ndb-mgm.html" title="25.5.5 ndb_mgm — The NDB Cluster Management Client"> <span class="command"> <strong> ndb_mgm </strong> </span> </a> client to see when the cluster has entered single user mode. You can also check the <code class="literal"> status </code> column of the <a class="link" href="mysql-cluster-ndbinfo-nodes.html" title="25.6.17.48 The ndbinfo nodes Table"> <code class="literal"> ndbinfo.nodes </code> </a> table (see <a class="xref" href="mysql-cluster-ndbinfo-nodes.html" title="25.6.17.48 The ndbinfo nodes Table"> Section 25.6.17.48, “The ndbinfo nodes Table” </a> , for more information). </p> <p> Example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-ndbmgm"><div class="docs-select-all right" id="sa95678237"><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-ndbmgm"><span class="token prompt">ndb_mgm&gt;</span> <span class="token keyword">ENTER SINGLE USER MODE</span> 5</code></pre> </div> <p> After this command has executed and the cluster has entered single user mode, the API node whose node ID is <code class="literal"> 5 </code> becomes the cluster's only permitted user. </p> <p> The node specified in the preceding command must be an API node; attempting to specify any other type of node is rejected. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> When the preceding command is invoked, all transactions running on the designated node are aborted, the connection is closed, and the server must be restarted. </p> </div> <p> The command <code class="literal"> EXIT SINGLE USER MODE </code> changes the state of the cluster's data nodes from single user mode to normal mode. API nodes—such as MySQL Servers—waiting for a connection (that is, waiting for the cluster to become ready and available), are again permitted to connect. The API node denoted as the single-user node continues to run (if still connected) during and after the state change. </p> <p> Example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-ndbmgm"><div class="docs-select-all right" id="sa91001271"><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-ndbmgm"><span class="token prompt">ndb_mgm&gt;</span> <span class="token keyword">EXIT SINGLE USER MODE</span></code></pre> </div> <a class="indexterm" name="idm46045092483568"> </a> <p> There are two recommended ways to handle a node failure when running in single user mode: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Method 1: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> Finish all single user mode transactions </p> </li> <li class="listitem"> <p> Issue the <code class="literal"> EXIT SINGLE USER MODE </code> command </p> </li> <li class="listitem"> <p> Restart the cluster's data nodes </p> </li> </ol> </div> </li> <li class="listitem"> <p> Method 2: </p> <p> Restart storage nodes prior to entering single user mode. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/year.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="year"> </a> 13.2.4 The YEAR Type </h3> </div> </div> </div> <a class="indexterm" name="idm46045213518416"> </a> <a class="indexterm" name="idm46045213517344"> </a> <p> The <code class="literal"> YEAR </code> type is a 1-byte type used to represent year values. It can be declared as <code class="literal"> YEAR </code> with an implicit display width of 4 characters, or equivalently as <code class="literal"> YEAR(4) </code> with an explicit display width. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> he <a class="link" href="year.html" title="13.2.4 The YEAR Type"> <code class="literal"> YEAR(4) </code> </a> data type using an explicit display width is deprecated and you should expect support for it to be removed in a future version of MySQL. Instead, use <a class="link" href="year.html" title="13.2.4 The YEAR Type"> <code class="literal"> YEAR </code> </a> without a display width, which has the same meaning. </p> </div> <p> MySQL displays <code class="literal"> YEAR </code> values in <em class="replaceable"> <code> YYYY </code> </em> format, with a range of <code class="literal"> 1901 </code> to <code class="literal"> 2155 </code> , and <code class="literal"> 0000 </code> . </p> <p> <code class="literal"> YEAR </code> accepts input values in a variety of formats: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> As 4-digit strings in the range <code class="literal"> '1901' </code> to <code class="literal"> '2155' </code> . </p> </li> <li class="listitem"> <p> As 4-digit numbers in the range <code class="literal"> 1901 </code> to <code class="literal"> 2155 </code> . </p> </li> <li class="listitem"> <p> As 1- or 2-digit strings in the range <code class="literal"> '0' </code> to <code class="literal"> '99' </code> . MySQL converts values in the ranges <code class="literal"> '0' </code> to <code class="literal"> '69' </code> and <code class="literal"> '70' </code> to <code class="literal"> '99' </code> to <code class="literal"> YEAR </code> values in the ranges <code class="literal"> 2000 </code> to <code class="literal"> 2069 </code> and <code class="literal"> 1970 </code> to <code class="literal"> 1999 </code> . </p> </li> <li class="listitem"> <p> As 1- or 2-digit numbers in the range <code class="literal"> 0 </code> to <code class="literal"> 99 </code> . MySQL converts values in the ranges <code class="literal"> 1 </code> to <code class="literal"> 69 </code> and <code class="literal"> 70 </code> to <code class="literal"> 99 </code> to <code class="literal"> YEAR </code> values in the ranges <code class="literal"> 2001 </code> to <code class="literal"> 2069 </code> and <code class="literal"> 1970 </code> to <code class="literal"> 1999 </code> . </p> <p> The result of inserting a numeric <code class="literal"> 0 </code> has a display value of <code class="literal"> 0000 </code> and an internal value of <code class="literal"> 0000 </code> . To insert zero and have it be interpreted as <code class="literal"> 2000 </code> , specify it as a string <code class="literal"> '0' </code> or <code class="literal"> '00' </code> . </p> </li> <li class="listitem"> <p> As the result of functions that return a value that is acceptable in <code class="literal"> YEAR </code> context, such as <a class="link" href="date-and-time-functions.html#function_now"> <code class="literal"> NOW() </code> </a> . </p> </li> </ul> </div> <p> If strict SQL mode is not enabled, MySQL converts invalid <code class="literal"> YEAR </code> values to <code class="literal"> 0000 </code> . In strict SQL mode, attempting to insert an invalid <code class="literal"> YEAR </code> value produces an error. </p> <p> See also <a class="xref" href="two-digit-years.html" title="13.2.9 2-Digit Years in Dates"> Section 13.2.9, “2-Digit Years in Dates” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-privilege-checks-account.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-privilege-checks-account"> </a> 19.3.3.1 Privileges For The Replication PRIVILEGE_CHECKS_USER Account </h4> </div> </div> </div> <p> The user account that is specified using the <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement"> <code class="literal"> CHANGE REPLICATION SOURCE TO </code> </a> statement as the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account for a replication channel must have the <a class="link" href="privileges-provided.html#priv_replication-applier"> <code class="literal"> REPLICATION_APPLIER </code> </a> privilege, otherwise the replication applier thread does not start. As explained in <a class="xref" href="replication-privilege-checks.html" title="19.3.3 Replication Privilege Checks"> Section 19.3.3, “Replication Privilege Checks” </a> , the account requires further privileges that are sufficient to apply all the expected transactions expected on the replication channel. These privileges are checked only when relevant transactions are executed. </p> <p> The use of row-based binary logging ( <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=ROW </code> </a> ) is strongly recommended for replication channels that are secured using a <code class="literal"> PRIVILEGE_CHECKS_USER </code> account. With statement-based binary logging, some administrator-level privileges might be required for the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account to execute transactions successfully. The <code class="literal"> REQUIRE_ROW_FORMAT </code> setting can be applied to secured channels, which restricts the channel from executing events that would require these privileges. </p> <p> The <a class="link" href="privileges-provided.html#priv_replication-applier"> <code class="literal"> REPLICATION_APPLIER </code> </a> privilege explicitly or implicitly allows the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account to carry out the following operations that a replication thread needs to perform: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Setting the value of the system variables <a class="link" href="replication-options-gtids.html#sysvar_gtid_next"> <code class="literal"> gtid_next </code> </a> , <a class="link" href="replication-options-binary-log.html#sysvar_original_commit_timestamp"> <code class="literal"> original_commit_timestamp </code> </a> , <a class="link" href="replication-options-source.html#sysvar_original_server_version"> <code class="literal"> original_server_version </code> </a> , <a class="link" href="replication-options-source.html#sysvar_immediate_server_version"> <code class="literal"> immediate_server_version </code> </a> , and <a class="link" href="server-system-variables.html#sysvar_pseudo_replica_mode"> <code class="literal"> pseudo_replica_mode </code> </a> , to apply appropriate metadata and behaviors when executing transactions. </p> </li> <li class="listitem"> <p> Executing internal-use <a class="link" href="binlog.html" title="15.7.8.1 BINLOG Statement"> <code class="literal"> BINLOG </code> </a> statements to apply <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files"> <span class="command"> <strong> mysqlbinlog </strong> </span> </a> output, provided that the account also has permission for the tables and operations in those statements. </p> </li> <li class="listitem"> <p> Updating the system tables <code class="literal"> mysql.gtid_executed </code> , <code class="literal"> mysql.slave_relay_log_info </code> , <code class="literal"> mysql.slave_worker_info </code> , and <code class="literal"> mysql.slave_master_info </code> , to update replication metadata. (If events access these tables explicitly for other purposes, you must grant the appropriate privileges on the tables.) </p> </li> <li class="listitem"> <p> Applying a binary log <code class="literal"> Table_map_log_event </code> , which provides table metadata but does not make any database changes. </p> </li> </ul> </div> <p> If the <code class="literal"> REQUIRE_TABLE_PRIMARY_KEY_CHECK </code> option of the <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement"> <code class="literal"> CHANGE REPLICATION SOURCE TO </code> </a> statement is set to the default value <code class="literal"> STREAM </code> , the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account needs privileges sufficient to set restricted session variables, so that it can change the value of the <a class="link" href="server-system-variables.html#sysvar_sql_require_primary_key"> <code class="literal"> sql_require_primary_key </code> </a> system variable for the duration of a session to match the setting replicated from the source. The <a class="link" href="privileges-provided.html#priv_session-variables-admin"> <code class="literal"> SESSION_VARIABLES_ADMIN </code> </a> privilege gives the account this capability. This privilege also allows the account to apply <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files"> <span class="command"> <strong> mysqlbinlog </strong> </span> </a> output that was created using the <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_disable-log-bin"> <code class="option"> --disable-log-bin </code> </a> option. If you set <code class="literal"> REQUIRE_TABLE_PRIMARY_KEY_CHECK </code> to either <code class="literal"> ON </code> or <code class="literal"> OFF </code> , the replica always uses that value for the <a class="link" href="server-system-variables.html#sysvar_sql_require_primary_key"> <code class="literal"> sql_require_primary_key </code> </a> system variable in replication operations, and so does not need these session administration level privileges. </p> <p> If table encryption is in use, the <a class="link" href="server-system-variables.html#sysvar_table_encryption_privilege_check"> <code class="literal"> table_encryption_privilege_check </code> </a> system variable is set to <code class="literal"> ON </code> , and the encryption setting for the tablespace involved in any event differs from the applying server's default encryption setting (specified by the <a class="link" href="server-system-variables.html#sysvar_default_table_encryption"> <code class="literal"> default_table_encryption </code> </a> system variable), the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account needs the <a class="link" href="privileges-provided.html#priv_table-encryption-admin"> <code class="literal"> TABLE_ENCRYPTION_ADMIN </code> </a> privilege in order to override the default encryption setting. It is strongly recommended that you do not grant this privilege. Instead, ensure that the default encryption setting on a replica matches the encryption status of the tablespaces that it replicates, and that replication group members have the same default encryption setting, so that the privilege is not needed. </p> <p> In order to execute specific replicated transactions from the relay log, or transactions from <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files"> <span class="command"> <strong> mysqlbinlog </strong> </span> </a> output as required, the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account must have the following privileges: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> For a row insertion logged in row format (which are logged as a <code class="literal"> Write_rows_log_event </code> ), the <a class="link" href="privileges-provided.html#priv_insert"> <code class="literal"> INSERT </code> </a> privilege on the relevant table. </p> </li> <li class="listitem"> <p> For a row update logged in row format (which are logged as an <code class="literal"> Update_rows_log_event </code> ), the <a class="link" href="privileges-provided.html#priv_update"> <code class="literal"> UPDATE </code> </a> privilege on the relevant table. </p> </li> <li class="listitem"> <p> For a row deletion logged in row format (which are logged as a <code class="literal"> Delete_rows_log_event </code> ), the <a class="link" href="privileges-provided.html#priv_delete"> <code class="literal"> DELETE </code> </a> privilege on the relevant table. </p> </li> </ul> </div> <p> If statement-based binary logging is in use (which is not recommended with a <code class="literal"> PRIVILEGE_CHECKS_USER </code> account), for a transaction control statement such as <code class="literal"> BEGIN </code> or <code class="literal"> COMMIT </code> or DML logged in statement format (which are logged as a <code class="literal"> Query_log_event </code> ), the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account needs privileges to execute the statement contained in the event. </p> <p> If <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> operations need to be carried out on the replication channel, use row-based binary logging ( <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=ROW </code> </a> ). With this logging format, the <a class="link" href="privileges-provided.html#priv_file"> <code class="literal"> FILE </code> </a> privilege is not needed to execute the event, so do not give the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account this privilege. The use of row-based binary logging is strongly recommended with replication channels that are secured using a <code class="literal"> PRIVILEGE_CHECKS_USER </code> account. If <code class="literal"> REQUIRE_ROW_FORMAT </code> is set for the channel, row-based binary logging is required. The <code class="literal"> Format_description_log_event </code> , which deletes any temporary files created by <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> events, is processed without privilege checks. For more information, see <a class="xref" href="replication-features-load-data.html" title="19.5.1.19 Replication and LOAD DATA"> Section 19.5.1.19, “Replication and LOAD DATA” </a> . </p> <p> If the <a class="link" href="replication-options-replica.html#sysvar_init_replica"> <code class="literal"> init_replica </code> </a> system variable is set to specify one or more SQL statements to be executed when the replication SQL thread starts, the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account must have the privileges needed to execute these statements. </p> <p> It is recommended that you never give any ACL privileges to the <code class="literal"> PRIVILEGE_CHECKS_USER </code> account, including <a class="link" href="privileges-provided.html#priv_create-user"> <code class="literal"> CREATE USER </code> </a> , <a class="link" href="privileges-provided.html#priv_create-role"> <code class="literal"> CREATE ROLE </code> </a> , <a class="link" href="privileges-provided.html#priv_drop-role"> <code class="literal"> DROP ROLE </code> </a> , and <a class="link" href="privileges-provided.html#priv_grant-option"> <code class="literal"> GRANT OPTION </code> </a> , and do not permit the account to update the <code class="literal"> mysql.user </code> table. With these privileges, the account could be used to create or modify user accounts on the server. To avoid ACL statements issued on the source server being replicated to the secured channel for execution (where they fail in the absence of these privileges), you can issue <code class="literal"> SET sql_log_bin = 0 </code> before all ACL statements and <code class="literal"> SET sql_log_bin = 1 </code> after them, to omit the statements from the source's binary log. Alternatively, you can set a dedicated current database before executing all ACL statements, and use a replication filter ( <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db"> <code class="option"> --binlog-ignore-db </code> </a> ) to filter out this database on the replica. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-install-windows-binary.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="mysql-cluster-install-windows-binary"> </a> 25.3.2.1 Installing NDB Cluster on Windows from a Binary Release </h4> </div> </div> </div> <a class="indexterm" name="idm46045122578256"> </a> <a class="indexterm" name="idm46045122576768"> </a> <p> This section describes a basic installation of NDB Cluster on Windows using a binary <span class="quote"> “ <span class="quote"> no-install </span> ” </span> NDB Cluster release provided by Oracle, using the same 4-node setup outlined in the beginning of this section (see <a class="xref" href="mysql-cluster-installation.html" title="25.3 NDB Cluster Installation"> Section 25.3, “NDB Cluster Installation” </a> ), as shown in the following table: </p> <div class="table"> <a name="idm46045122572576"> </a> <p class="title"> <b> Table 25.6 Network addresses of nodes in example cluster </b> </p> <div class="table-contents"> <table> <colgroup> <col style="width: 50%"/> <col style="width: 50%"/> </colgroup> <thead> <tr> <th> Node </th> <th> IP Address </th> </tr> </thead> <tbody> <tr> <td> Management node ( <span class="command"> <strong> mgmd </strong> </span> ) </td> <td> 198.51.100.10 </td> </tr> <tr> <td> SQL node ( <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> ) </td> <td> 198.51.100.20 </td> </tr> <tr> <td> Data node "A" ( <a class="link" href="mysql-cluster-programs-ndbd.html" title="25.5.1 ndbd — The NDB Cluster Data Node Daemon"> <span class="command"> <strong> ndbd </strong> </span> </a> ) </td> <td> 198.51.100.30 </td> </tr> <tr> <td> Data node "B" ( <a class="link" href="mysql-cluster-programs-ndbd.html" title="25.5.1 ndbd — The NDB Cluster Data Node Daemon"> <span class="command"> <strong> ndbd </strong> </span> </a> ) </td> <td> 198.51.100.40 </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <p> As on other platforms, the NDB Cluster host computer running an SQL node must have installed on it a MySQL Server binary ( <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld.exe </strong> </span> </a> ). You should also have the MySQL client ( <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client"> <span class="command"> <strong> mysql.exe </strong> </span> </a> ) on this host. For management nodes and data nodes, it is not necessary to install the MySQL Server binary; however, each management node requires the management server daemon ( <a class="link" href="mysql-cluster-programs-ndb-mgmd.html" title="25.5.4 ndb_mgmd — The NDB Cluster Management Server Daemon"> <span class="command"> <strong> ndb_mgmd.exe </strong> </span> </a> ); each data node requires the data node daemon ( <a class="link" href="mysql-cluster-programs-ndbd.html" title="25.5.1 ndbd — The NDB Cluster Data Node Daemon"> <span class="command"> <strong> ndbd.exe </strong> </span> </a> or <a class="link" href="mysql-cluster-programs-ndbmtd.html" title="25.5.3 ndbmtd — The NDB Cluster Data Node Daemon (Multi-Threaded)"> <span class="command"> <strong> ndbmtd.exe </strong> </span> </a> ). For this example, we refer to <a class="link" href="mysql-cluster-programs-ndbd.html" title="25.5.1 ndbd — The NDB Cluster Data Node Daemon"> <span class="command"> <strong> ndbd.exe </strong> </span> </a> as the data node executable, but you can install <a class="link" href="mysql-cluster-programs-ndbmtd.html" title="25.5.3 ndbmtd — The NDB Cluster Data Node Daemon (Multi-Threaded)"> <span class="command"> <strong> ndbmtd.exe </strong> </span> </a> , the multithreaded version of this program, instead, in exactly the same way. You should also install the management client ( <a class="link" href="mysql-cluster-programs-ndb-mgm.html" title="25.5.5 ndb_mgm — The NDB Cluster Management Client"> <span class="command"> <strong> ndb_mgm.exe </strong> </span> </a> ) on the management server host. This section covers the steps necessary to install the correct Windows binaries for each type of NDB Cluster node. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> As with other Windows programs, NDB Cluster executables are named with the <code class="filename"> .exe </code> file extension. However, it is not necessary to include the <code class="filename"> .exe </code> extension when invoking these programs from the command line. Therefore, we often simply refer to these programs in this documentation as <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> , <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client"> <span class="command"> <strong> mysql </strong> </span> </a> , <a class="link" href="mysql-cluster-programs-ndb-mgmd.html" title="25.5.4 ndb_mgmd — The NDB Cluster Management Server Daemon"> <span class="command"> <strong> ndb_mgmd </strong> </span> </a> , and so on. You should understand that, whether we refer (for example) to <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> or <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld.exe </strong> </span> </a> , either name means the same thing (the MySQL Server program). </p> </div> <p> For setting up an NDB Cluster using Oracles's <code class="literal"> no-install </code> binaries, the first step in the installation process is to download the latest NDB Cluster Windows ZIP binary archive from <a class="ulink" href="https://dev.mysql.com/downloads/cluster/" target="_top"> https://dev.mysql.com/downloads/cluster/ </a> . This archive has a filename of the <code class="filename"> mysql-cluster-gpl- <em class="replaceable"> <code> ver </code> </em> -win <em class="replaceable"> <code> arch </code> </em> .zip </code> , where <em class="replaceable"> <code> ver </code> </em> is the <code class="literal"> NDB </code> storage engine version (such as <code class="literal"> 8.4.0 </code> ), and <em class="replaceable"> <code> arch </code> </em> is the architecture ( <code class="literal"> 32 </code> for 32-bit binaries, and <code class="literal"> 64 </code> for 64-bit binaries). For example, the NDB Cluster 8.4.0 archive for 64-bit Windows systems is named <code class="filename"> mysql-cluster-gpl-8.4.0-win64.zip </code> . </p> <p> You can run 32-bit NDB Cluster binaries on both 32-bit and 64-bit versions of Windows; however, 64-bit NDB Cluster binaries can be used only on 64-bit versions of Windows. If you are using a 32-bit version of Windows on a computer that has a 64-bit CPU, then you must use the 32-bit NDB Cluster binaries. </p> <p> To minimize the number of files that need to be downloaded from the Internet or copied between machines, we start with the computer where you intend to run the SQL node. </p> <p> <b> SQL node. </b> We assume that you have placed a copy of the archive in the directory <code class="filename"> C:\Documents and Settings\ <em class="replaceable"> <code> username </code> </em> \My Documents\Downloads </code> on the computer having the IP address 198.51.100.20, where <em class="replaceable"> <code> username </code> </em> is the name of the current user. (You can obtain this name using <code class="literal"> ECHO %USERNAME% </code> on the command line.) To install and run NDB Cluster executables as Windows services, this user should be a member of the <code class="literal"> Administrators </code> group. </p> <p> Extract all the files from the archive. The Extraction Wizard integrated with Windows Explorer is adequate for this task. (If you use a different archive program, be sure that it extracts all files and directories from the archive, and that it preserves the archive's directory structure.) When you are asked for a destination directory, enter <code class="filename"> C:\ </code> , which causes the Extraction Wizard to extract the archive to the directory <code class="filename"> C:\mysql-cluster-gpl- <em class="replaceable"> <code> ver </code> </em> -win <em class="replaceable"> <code> arch </code> </em> </code> . Rename this directory to <code class="filename"> C:\mysql </code> . </p> <p> It is possible to install the NDB Cluster binaries to directories other than <code class="filename"> C:\mysql\bin </code> ; however, if you do so, you must modify the paths shown in this procedure accordingly. In particular, if the MySQL Server (SQL node) binary is installed to a location other than <code class="filename"> C:\mysql </code> or <code class="filename"> C:\Program Files\MySQL\MySQL Server 8.4 </code> , or if the SQL node's data directory is in a location other than <code class="filename"> C:\mysql\data </code> or <code class="filename"> C:\Program Files\MySQL\MySQL Server 8.4\data </code> , extra configuration options must be used on the command line or added to the <code class="filename"> my.ini </code> or <code class="filename"> my.cnf </code> file when starting the SQL node. For more information about configuring a MySQL Server to run in a nonstandard location, see <a class="xref" href="windows-install-archive.html" title="2.3.3 Configuration: Manually"> Section 2.3.3, “Configuration: Manually” </a> . </p> <p> For a MySQL Server with NDB Cluster support to run as part of an NDB Cluster, it must be started with the options <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndbcluster"> <code class="option"> --ndbcluster </code> </a> and <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-connectstring"> <code class="option"> --ndb-connectstring </code> </a> . While you can specify these options on the command line, it is usually more convenient to place them in an option file. To do this, create a new text file in Notepad or another text editor. Enter the following configuration information into this file: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa55344248"><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-ini"><span class="token selector">[mysqld]</span> <span class="token comment" spellcheck="true"># Options for mysqld process:</span> ndbcluster <span class="token comment" spellcheck="true"># run NDB storage engine</span> <span class="token constant">ndb-connectstring</span><span class="token attr-value"><span class="token punctuation">=</span>198.51.100.10 </span><span class="token comment" spellcheck="true"># location of management server</span></code></pre> </div> <p> You can add other options used by this MySQL Server if desired (see <a class="xref" href="windows-create-option-file.html" title="2.3.3.2 Creating an Option File"> Section 2.3.3.2, “Creating an Option File” </a> ), but the file must contain the options shown, at a minimum. Save this file as <code class="filename"> C:\mysql\my.ini </code> . This completes the installation and setup for the SQL node. </p> <p> <b> Data nodes. </b> An NDB Cluster data node on a Windows host requires only a single executable, one of either <a class="link" href="mysql-cluster-programs-ndbd.html" title="25.5.1 ndbd — The NDB Cluster Data Node Daemon"> <span class="command"> <strong> ndbd.exe </strong> </span> </a> or <a class="link" href="mysql-cluster-programs-ndbmtd.html" title="25.5.3 ndbmtd — The NDB Cluster Data Node Daemon (Multi-Threaded)"> <span class="command"> <strong> ndbmtd.exe </strong> </span> </a> . For this example, we assume that you are using <a class="link" href="mysql-cluster-programs-ndbd.html" title="25.5.1 ndbd — The NDB Cluster Data Node Daemon"> <span class="command"> <strong> ndbd.exe </strong> </span> </a> , but the same instructions apply when using <a class="link" href="mysql-cluster-programs-ndbmtd.html" title="25.5.3 ndbmtd — The NDB Cluster Data Node Daemon (Multi-Threaded)"> <span class="command"> <strong> ndbmtd.exe </strong> </span> </a> . On each computer where you wish to run a data node (the computers having the IP addresses 198.51.100.30 and 198.51.100.40), create the directories <code class="filename"> C:\mysql </code> , <code class="filename"> C:\mysql\bin </code> , and <code class="filename"> C:\mysql\cluster-data </code> ; then, on the computer where you downloaded and extracted the <code class="literal"> no-install </code> archive, locate <code class="filename"> ndbd.exe </code> in the <code class="filename"> C:\mysql\bin </code> directory. Copy this file to the <code class="filename"> C:\mysql\bin </code> directory on each of the two data node hosts. </p> <p> To function as part of an NDB Cluster, each data node must be given the address or hostname of the management server. You can supply this information on the command line using the <a class="link" href="mysql-cluster-programs-ndb-config.html#option_ndb_config_ndb-connectstring"> <code class="option"> --ndb-connectstring </code> </a> or <code class="option"> -c </code> option when starting each data node process. However, it is usually preferable to put this information in an option file. To do this, create a new text file in Notepad or another text editor and enter the following text: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa23994140"><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-ini"><span class="token selector">[mysql_cluster]</span> <span class="token comment" spellcheck="true"># Options for data node process:</span> <span class="token constant">ndb-connectstring</span><span class="token attr-value"><span class="token punctuation">=</span>198.51.100.10 </span><span class="token comment" spellcheck="true"># location of management server</span></code></pre> </div> <p> Save this file as <code class="filename"> C:\mysql\my.ini </code> on the data node host. Create another text file containing the same information and save it on as <code class="filename"> C:mysql\my.ini </code> on the other data node host, or copy the my.ini file from the first data node host to the second one, making sure to place the copy in the second data node's <code class="filename"> C:\mysql </code> directory. Both data node hosts are now ready to be used in the NDB Cluster, which leaves only the management node to be installed and configured. </p> <p> <b> Management node. </b> The only executable program required on a computer used for hosting an NDB Cluster management node is the management server program <a class="link" href="mysql-cluster-programs-ndb-mgmd.html" title="25.5.4 ndb_mgmd — The NDB Cluster Management Server Daemon"> <span class="command"> <strong> ndb_mgmd.exe </strong> </span> </a> . However, in order to administer the NDB Cluster once it has been started, you should also install the NDB Cluster management client program <a class="link" href="mysql-cluster-programs-ndb-mgm.html" title="25.5.5 ndb_mgm — The NDB Cluster Management Client"> <span class="command"> <strong> ndb_mgm.exe </strong> </span> </a> on the same machine as the management server. Locate these two programs on the machine where you downloaded and extracted the <code class="literal"> no-install </code> archive; this should be the directory <code class="filename"> C:\mysql\bin </code> on the SQL node host. Create the directory <code class="filename"> C:\mysql\bin </code> on the computer having the IP address 198.51.100.10, then copy both programs to this directory. </p> <p> You should now create two configuration files for use by <code class="filename"> ndb_mgmd.exe </code> : </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> A local configuration file to supply configuration data specific to the management node itself. Typically, this file needs only to supply the location of the NDB Cluster global configuration file (see item 2). </p> <p> To create this file, start a new text file in Notepad or another text editor, and enter the following information: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa48438070"><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-ini"><span class="token selector">[mysql_cluster]</span> <span class="token comment" spellcheck="true"># Options for management node process</span> <span class="token constant">config-file</span><span class="token attr-value"><span class="token punctuation">=</span>C:/mysql/bin/config.ini</span></code></pre> </div> <p> Save this file as the text file <code class="filename"> C:\mysql\bin\my.ini </code> . </p> </li> <li class="listitem"> <p> A global configuration file from which the management node can obtain configuration information governing the NDB Cluster as a whole. At a minimum, this file must contain a section for each node in the NDB Cluster, and the IP addresses or hostnames for the management node and all data nodes ( <code class="literal"> HostName </code> configuration parameter). It is also advisable to include the following additional information: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The IP address or hostname of any SQL nodes </p> </li> <li class="listitem"> <p> The data memory and index memory allocated to each data node ( <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datamemory"> <code class="literal"> DataMemory </code> </a> and <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-indexmemory"> <code class="literal"> IndexMemory </code> </a> configuration parameters) </p> </li> <li class="listitem"> <p> The number of fragment replicas, using the <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-noofreplicas"> <code class="literal"> NoOfReplicas </code> </a> configuration parameter (see <a class="xref" href="mysql-cluster-nodes-groups.html" title="25.2.2 NDB Cluster Nodes, Node Groups, Fragment Replicas, and Partitions"> Section 25.2.2, “NDB Cluster Nodes, Node Groups, Fragment Replicas, and Partitions” </a> ) </p> </li> <li class="listitem"> <p> The directory where each data node stores it data and log file, and the directory where the management node keeps its log files (in both cases, the <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datadir"> <code class="literal"> DataDir </code> </a> configuration parameter) </p> </li> </ul> </div> <p> Create a new text file using a text editor such as Notepad, and input the following information: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa21813041"><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-ini"><span class="token selector">[ndbd default]</span> <span class="token comment" spellcheck="true"># Options affecting ndbd processes on all data nodes:</span> <span class="token constant">NoOfReplicas</span><span class="token attr-value"><span class="token punctuation">=</span>2 </span><span class="token comment" spellcheck="true"># Number of fragment replicas</span> <span class="token constant">DataDir</span><span class="token attr-value"><span class="token punctuation">=</span>C:/mysql/cluster-data </span><span class="token comment" spellcheck="true"># Directory for each data node's data files</span> <span class="token comment" spellcheck="true"> # Forward slashes used in directory path,</span> <span class="token comment" spellcheck="true"> # rather than backslashes. This is correct;</span> <span class="token comment" spellcheck="true"> # see Important note in text</span> <span class="token constant">DataMemory</span><span class="token attr-value"><span class="token punctuation">=</span>80M </span><span class="token comment" spellcheck="true"># Memory allocated to data storage</span> <span class="token constant">IndexMemory</span><span class="token attr-value"><span class="token punctuation">=</span>18M </span><span class="token comment" spellcheck="true"># Memory allocated to index storage</span> <span class="token comment" spellcheck="true"> # For DataMemory and IndexMemory, we have used the</span> <span class="token comment" spellcheck="true"> # default values. Since the "world" database takes up</span> <span class="token comment" spellcheck="true"> # only about 500KB, this should be more than enough for</span> <span class="token comment" spellcheck="true"> # this example Cluster setup.</span> <span class="token selector">[ndb_mgmd]</span> <span class="token comment" spellcheck="true"># Management process options:</span> <span class="token constant">HostName</span><span class="token attr-value"><span class="token punctuation">=</span>198.51.100.10 </span><span class="token comment" spellcheck="true"># Hostname or IP address of management node</span> <span class="token constant">DataDir</span><span class="token attr-value"><span class="token punctuation">=</span>C:/mysql/bin/cluster-logs </span><span class="token comment" spellcheck="true"># Directory for management node log files</span> <span class="token selector">[ndbd]</span> <span class="token comment" spellcheck="true"># Options for data node "A":</span> <span class="token comment" spellcheck="true"> # (one [ndbd] section per data node)</span> <span class="token constant">HostName</span><span class="token attr-value"><span class="token punctuation">=</span>198.51.100.30 </span><span class="token comment" spellcheck="true"># Hostname or IP address</span> <span class="token selector">[ndbd]</span> <span class="token comment" spellcheck="true"># Options for data node "B":</span> <span class="token constant">HostName</span><span class="token attr-value"><span class="token punctuation">=</span>198.51.100.40 </span><span class="token comment" spellcheck="true"># Hostname or IP address</span> <span class="token selector">[mysqld]</span> <span class="token comment" spellcheck="true"># SQL node options:</span> <span class="token constant">HostName</span><span class="token attr-value"><span class="token punctuation">=</span>198.51.100.20 </span><span class="token comment" spellcheck="true"># Hostname or IP address</span></code></pre> </div> <p> Save this file as the text file <code class="filename"> C:\mysql\bin\config.ini </code> . </p> </li> </ol> </div> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> A single backslash character ( <code class="literal"> \ </code> ) cannot be used when specifying directory paths in program options or configuration files used by NDB Cluster on Windows. Instead, you must either escape each backslash character with a second backslash ( <code class="literal"> \\ </code> ), or replace the backslash with a forward slash character ( <code class="literal"> / </code> ). For example, the following line from the <code class="literal"> [ndb_mgmd] </code> section of an NDB Cluster <code class="filename"> config.ini </code> file does not work: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa94433102"><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-ini"><span class="token constant">DataDir</span><span class="token attr-value"><span class="token punctuation">=</span>C:\mysql\bin\cluster-logs</span></code></pre> </div> <p> Instead, you may use either of the following: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa12508582"><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-ini"><span class="token constant">DataDir</span><span class="token attr-value"><span class="token punctuation">=</span>C:\\mysql\\bin\\cluster-logs </span><span class="token comment" spellcheck="true"># Escaped backslashes</span></code></pre> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa88477257"><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-ini"><span class="token constant">DataDir</span><span class="token attr-value"><span class="token punctuation">=</span>C:/mysql/bin/cluster-logs </span><span class="token comment" spellcheck="true"># Forward slashes</span></code></pre> </div> <p> For reasons of brevity and legibility, we recommend that you use forward slashes in directory paths used in NDB Cluster program options and configuration files on Windows. </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-features-temptables.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-features-temptables"> </a> 19.5.1.31 Replication and Temporary Tables </h4> </div> </div> </div> <a class="indexterm" name="idm46045135125184"> </a> <a class="indexterm" name="idm46045135123696"> </a> <a class="indexterm" name="idm46045135122208"> </a> <p> In MySQL 8.4, when <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is set to <code class="literal"> ROW </code> or <code class="literal"> MIXED </code> , statements that exclusively use temporary tables are not logged on the source, and therefore the temporary tables are not replicated. Statements that involve a mix of temporary and nontemporary tables are logged on the source only for the operations on nontemporary tables, and the operations on temporary tables are not logged. This means that there are never any temporary tables on the replica to be lost in the event of an unplanned shutdown by the replica. For more information about row-based replication and temporary tables, see <a class="xref" href="replication-rbr-usage.html#replication-rbr-usage-temptables" title="Row-based logging of temporary tables"> Row-based logging of temporary tables </a> . </p> <p> When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is set to <code class="literal"> STATEMENT </code> , operations on temporary tables are logged on the source and replicated on the replica, provided that the statements involving temporary tables can be logged safely using statement-based format. In this situation, loss of replicated temporary tables on the replica can be an issue. In statement-based replication mode, <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TEMPORARY TABLE </code> </a> and <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement"> <code class="literal"> DROP TEMPORARY TABLE </code> </a> statements cannot be used inside a transaction, procedure, function, or trigger when GTIDs are in use on the server (that is, when the <a class="link" href="replication-options-gtids.html#sysvar_enforce_gtid_consistency"> <code class="literal"> enforce_gtid_consistency </code> </a> system variable is set to <code class="literal"> ON </code> ). They can be used outside these contexts when GTIDs are in use, provided that <a class="link" href="server-system-variables.html#sysvar_autocommit"> <code class="literal"> autocommit=1 </code> </a> is set. </p> <p> Because of the differences in behavior between row-based or mixed replication mode and statement-based replication mode regarding temporary tables, you cannot switch the replication format at runtime, if the change applies to a context (global or session) that contains any open temporary tables. For more details, see the description of the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> option. </p> <p> <b> Safe replica shutdown when using temporary tables. </b> In statement-based replication mode, temporary tables are replicated except in the case where you stop the replica server (not just the replication threads) and you have replicated temporary tables that are open for use in updates that have not yet been executed on the replica. If you stop the replica server, the temporary tables needed by those updates are no longer available when the replica is restarted. To avoid this problem, do not shut down the replica while it has temporary tables open. Instead, use the following procedure: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> Issue a <code class="literal"> STOP REPLICA SQL_THREAD </code> statement. </p> </li> <li class="listitem"> <p> Use <a class="link" href="show-status.html" title="15.7.7.37 SHOW STATUS Statement"> <code class="literal"> SHOW STATUS </code> </a> to check the value of the <a class="link" href="server-status-variables.html#statvar_Replica_open_temp_tables"> <code class="literal"> Replica_open_temp_tables </code> </a> status variable. </p> </li> <li class="listitem"> <p> If the value is not 0, restart the replication SQL thread with <code class="literal"> START REPLICA SQL_THREAD </code> and repeat the procedure later. </p> </li> <li class="listitem"> <p> When the value is 0, issue a <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program"> <span class="command"> <strong> mysqladmin shutdown </strong> </span> </a> command to stop the replica. </p> </li> </ol> </div> <p> <b> Temporary tables and replication options. </b> By default, with statement-based replication, all temporary tables are replicated; this happens whether or not there are any matching <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db"> <code class="option"> --replicate-do-db </code> </a> , <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-table"> <code class="option"> --replicate-do-table </code> </a> , or <a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-do-table"> <code class="option"> --replicate-wild-do-table </code> </a> options in effect. However, the <a class="link" href="replication-options-replica.html#option_mysqld_replicate-ignore-table"> <code class="option"> --replicate-ignore-table </code> </a> and <a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-ignore-table"> <code class="option"> --replicate-wild-ignore-table </code> </a> options are honored for temporary tables. The exception is that to enable correct removal of temporary tables at the end of a session, a replica always replicates a <code class="literal"> DROP TEMPORARY TABLE IF EXISTS </code> statement, regardless of any exclusion rules that would normally apply for the specified table. </p> <p> A recommended practice when using statement-based replication is to designate a prefix for exclusive use in naming temporary tables that you do not want replicated, then employ a <a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-ignore-table"> <code class="option"> --replicate-wild-ignore-table </code> </a> option to match that prefix. For example, you might give all such tables names beginning with <code class="literal"> norep </code> (such as <code class="literal"> norepmytable </code> , <code class="literal"> norepyourtable </code> , and so on), then use <a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-ignore-table"> <code class="option"> --replicate-wild-ignore-table=norep% </code> </a> to prevent them from being replicated. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-oci-marketplace-connecting.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="mysql-oci-marketplace-connecting"> </a> 34.4 Connecting </h2> </div> </div> </div> <p> This section describes the various connection methods for connecting to the deployed MySQL server on the OCI Compute Instance. </p> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="mysql-oci-marketplace-connecting-ssh"> </a> Connecting with SSH </h3> </div> </div> </div> <p> This section gives some detail on connecting from a UNIX-like platform to the OCI Compute. For more information on connecting with SSH, see <a class="ulink" href="https://docs.oracle.com/en/cloud/iaas/compute-iaas-cloud/stcsg/accessing-oracle-linux-instance-using-ssh.html#GUID-D947E2CC-0D4C-43F4-B2A9-A517037D6C11" target="_blank"> Accessing an Oracle Linux Instance Using SSH </a> and <a class="ulink" href="https://docs.cloud.oracle.com/iaas/Content/GSG/Tasks/testingconnection.htm" target="_blank"> Connecting to Your Instance </a> . </p> <p> To connect to the Oracle Linux running on the Compute Instance with SSH, run the following command: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa82733816"><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-simple">ssh opc@<em class="replaceable">computeIP</em></code></pre> </div> <p> where <code class="literal"> opc </code> is the compute user and <em class="replaceable"> <code> computeIP </code> </em> is the IP address of your Compute Instance. </p> <p> To find the temporary root password created for the root user, run the following command: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa5254481"><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">sudo grep <span class="token atrule">'temporary password'</span> /var/log/mysqld<span class="token punctuation">.</span>log</code></pre> </div> <p> To change your default password, log in to the server using the generated, temporary password, using the following command: <code class="literal"> mysql -uroot -p </code> . Then run the following: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa37994823"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'MyNewPass4!'</span><span class="token punctuation">;</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="mysql-oci-marketplace-connecting-mysqlclient"> </a> Connecting with MySQL Client </h3> </div> </div> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> To connect from your local MySQL client, you must first create on the MySQL server a user which allows remote login. </p> </div> <p> To connect to the MySQL Server from your local MySQL client, run the following command from your shell session: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa30912652"><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-simple">mysql <span class="token operator">-</span>uroot <span class="token operator">-</span>p <span class="token operator">-</span>h<em class="replaceable">computeIP</em></code></pre> </div> <p> where <em class="replaceable"> <code> computeIP </code> </em> is the IP address of your Compute Instance. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="mysql-oci-marketplace-connecting-mysqlshell"> </a> Connecting with MySQL Shell </h3> </div> </div> </div> <p> To connect to the MySQL Server from your local MySQL Shell, run the following command to start your shell session: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa34165496"><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">mysqlsh root@<em class="replaceable">computeIP</em></code></pre> </div> <p> where <em class="replaceable"> <code> computeIP </code> </em> is the IP address of your Compute Instance. </p> <p> For more information on MySQL Shell connections, see <a class="ulink" href="/doc/mysql-shell/8.4/en/mysql-shell-connections.html" target="_top"> MySQL Shell Connections </a> . </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="mysql-oci-marketplace-connecting-workbench"> </a> Connecting with Workbench </h3> </div> </div> </div> <p> To connect to the MySQL Server from MySQL Workbench, see <a class="ulink" href="/doc/workbench/en/wb-mysql-connections.html" target="_top"> Connections in MySQL Workbench </a> . </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/silent-column-changes.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="silent-column-changes"> </a> 15.1.20.7 Silent Column Specification Changes </h4> </div> </div> </div> <a class="indexterm" name="idm46045184842560"> </a> <p> In some cases, MySQL silently changes column specifications from those given in a <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> or <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement. These might be changes to a data type, to attributes associated with a data type, or to an index specification. </p> <p> All changes are subject to the internal row-size limit of 65,535 bytes, which may cause some attempts at data type changes to fail. See <a class="xref" href="column-count-limit.html" title="10.4.7 Limits on Table Column Count and Row Size"> Section 10.4.7, “Limits on Table Column Count and Row Size” </a> . </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Columns that are part of a <code class="literal"> PRIMARY KEY </code> are made <code class="literal"> NOT NULL </code> even if not declared that way. </p> </li> <li class="listitem"> <p> Trailing spaces are automatically deleted from <a class="link" href="enum.html" title="13.3.5 The ENUM Type"> <code class="literal"> ENUM </code> </a> and <a class="link" href="set.html" title="13.3.6 The SET Type"> <code class="literal"> SET </code> </a> member values when the table is created. </p> </li> <li class="listitem"> <p> MySQL maps certain data types used by other SQL database vendors to MySQL types. See <a class="xref" href="other-vendor-data-types.html" title="13.9 Using Data Types from Other Database Engines"> Section 13.9, “Using Data Types from Other Database Engines” </a> . </p> </li> <li class="listitem"> <p> If you include a <code class="literal"> USING </code> clause to specify an index type that is not permitted for a given storage engine, but there is another index type available that the engine can use without affecting query results, the engine uses the available type. </p> </li> <li class="listitem"> <p> If strict SQL mode is not enabled, a <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> column with a length specification greater than 65535 is converted to <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> , and a <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> VARBINARY </code> </a> column with a length specification greater than 65535 is converted to <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> . Otherwise, an error occurs in either of these cases. </p> </li> <li class="listitem"> <p> Specifying the <code class="literal"> CHARACTER SET binary </code> attribute for a character data type causes the column to be created as the corresponding binary data type: <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> becomes <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> BINARY </code> </a> , <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> becomes <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> VARBINARY </code> </a> , and <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> becomes <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> . For the <a class="link" href="enum.html" title="13.3.5 The ENUM Type"> <code class="literal"> ENUM </code> </a> and <a class="link" href="set.html" title="13.3.6 The SET Type"> <code class="literal"> SET </code> </a> data types, this does not occur; they are created as declared. Suppose that you specify a table using this definition: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72594072"><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">TABLE</span> t <span class="token punctuation">(</span> c1 <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token datatype">binary</span><span class="token punctuation">,</span> c2 <span class="token datatype">TEXT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token datatype">binary</span><span class="token punctuation">,</span> c3 <span class="token datatype">ENUM</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span><span class="token string">'b'</span><span class="token punctuation">,</span><span class="token string">'c'</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token datatype">binary</span> <span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> The resulting table has this definition: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa2759581"><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">TABLE</span> t <span class="token punctuation">(</span> c1 <span class="token datatype">VARBINARY</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span> c2 <span class="token datatype">BLOB</span><span class="token punctuation">,</span> c3 <span class="token datatype">ENUM</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span><span class="token string">'b'</span><span class="token punctuation">,</span><span class="token string">'c'</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token datatype">binary</span> <span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> To see whether MySQL used a data type other than the one you specified, issue a <a class="link" href="describe.html" title="15.8.1 DESCRIBE Statement"> <code class="literal"> DESCRIBE </code> </a> or <a class="link" href="show-create-table.html" title="15.7.7.11 SHOW CREATE TABLE Statement"> <code class="literal"> SHOW CREATE TABLE </code> </a> statement after creating or altering the table. </p> <a class="indexterm" name="idm46045184804576"> </a> <p> Certain other data type changes can occur if you compress a table using <a class="link" href="myisampack.html" title="6.6.6 myisampack — Generate Compressed, Read-Only MyISAM Tables"> <span class="command"> <strong> myisampack </strong> </span> </a> . See <a class="xref" href="compressed-format.html" title="18.2.3.3 Compressed Table Characteristics"> Section 18.2.3.3, “Compressed Table Characteristics” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/show-binary-log-status.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="show-binary-log-status"> </a> 15.7.7.1 SHOW BINARY LOG STATUS Statement </h4> </div> </div> </div> <a class="indexterm" name="idm46045171215856"> </a> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa22756206"><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">SHOW</span> <span class="token datatype">BINARY</span> LOG <span class="token keyword">STATUS</span></code></pre> </div> <p> This statement provides status information about binary log files on the source server, and requires the <a class="link" href="privileges-provided.html#priv_replication-client"> <code class="literal"> REPLICATION CLIENT </code> </a> privilege (or the deprecated <a class="link" href="privileges-provided.html#priv_super"> <code class="literal"> SUPER </code> </a> privilege). </p> <p> Example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa27604714"><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 datatype">BINARY</span> LOG <span class="token keyword">STATUS</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> File<span class="token punctuation">:</span> source-bin.000002 Position<span class="token punctuation">:</span> 1307 Binlog_Do_DB<span class="token punctuation">:</span> test Binlog_Ignore_DB<span class="token punctuation">:</span> manual, mysql Executed_Gtid_Set<span class="token punctuation">:</span> 3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>1-5 </span><span class="token output">1 row in set (0.00 sec)</span></code></pre> </div> <p> When global transaction IDs are in use, <code class="literal"> Executed_Gtid_Set </code> shows the set of GTIDs for transactions that have been executed on the source. This is the same as the value for the <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed"> <code class="literal"> gtid_executed </code> </a> system variable on this server, as well as the value for <code class="literal"> Executed_Gtid_Set </code> in the output of <a class="link" href="show-replica-status.html" title="15.7.7.35 SHOW REPLICA STATUS Statement"> <code class="literal"> SHOW REPLICA STATUS </code> </a> on this server. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-features-memory.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-features-memory"> </a> 19.5.1.21 Replication and MEMORY Tables </h4> </div> </div> </div> <a class="indexterm" name="idm46045135331520"> </a> <a class="indexterm" name="idm46045135330032"> </a> <p> When a replication source server shuts down and restarts, its <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables become empty. To replicate this effect to replicas, the first time that the source uses a given <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> table after startup, it logs an event that notifies replicas that the table must be emptied by writing a <a class="link" href="delete.html" title="15.2.2 DELETE Statement"> <code class="literal"> DELETE </code> </a> or <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> statement for that table to the binary log. This generated event is identifiable by a comment in the binary log, and if GTIDs are in use on the server, it has a GTID assigned. The statement is always logged in statement format, even if the binary logging format is set to <code class="literal"> ROW </code> , and it is written even if <code class="literal"> read_only </code> or <code class="literal"> super_read_only </code> mode is set on the server. Note that the replica still has outdated data in a <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> table during the interval between the source's restart and its first use of the table. To avoid this interval when a direct query to the replica could return stale data, you can set the <a class="link" href="server-system-variables.html#sysvar_init_file"> <code class="literal"> init_file </code> </a> system variable to name a file containing statements that populate the <code class="literal"> MEMORY </code> table on the source at startup. </p> <p> When a replica server shuts down and restarts, its <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables become empty. This causes the replica to be out of synchrony with the source and may lead to other failures or cause the replica to stop: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Row-format updates and deletes received from the source may fail with <code class="literal"> Can't find record in ' <em class="replaceable"> <code> memory_table </code> </em> ' </code> . </p> </li> <li class="listitem"> <p> Statements such as <a class="link" href="insert-select.html" title="15.2.7.1 INSERT ... SELECT Statement"> <code class="literal"> INSERT INTO ... SELECT FROM <em class="replaceable"> <code> memory_table </code> </em> </code> </a> may insert a different set of rows on the source and replica. </p> </li> </ul> </div> <p> The replica also writes a <a class="link" href="delete.html" title="15.2.2 DELETE Statement"> <code class="literal"> DELETE </code> </a> or <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> statement to its own binary log, which is passed on to any downstream replicas, causing them to empty their own <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables. </p> <p> The safe way to restart a replica that is replicating <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables is to first drop or delete all rows from the <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables on the source and wait until those changes have replicated to the replica. Then it is safe to restart the replica. </p> <p> An alternative restart method may apply in some cases. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=ROW </code> </a> , you can prevent the replica from stopping if you set <a class="link" href="replication-options-replica.html#sysvar_replica_exec_mode"> <code class="literal"> replica_exec_mode=IDEMPOTENT </code> </a> before you start the replica again. This allows the replica to continue to replicate, but its <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables still differ from those on the source. This is acceptable if the application logic is such that the contents of <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables can be safely lost (for example, if the <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables are used for caching). <a class="link" href="replication-options-replica.html#sysvar_replica_exec_mode"> <code class="literal"> replica_exec_mode=IDEMPOTENT </code> </a> applies globally to all tables, so it may hide other replication errors in non- <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables. </p> <p> (The method just described is not applicable in NDB Cluster, where <a class="link" href="replication-options-replica.html#sysvar_replica_exec_mode"> <code class="literal"> replica_exec_mode </code> </a> is always <code class="literal"> IDEMPOTENT </code> , and cannot be changed.) </p> <p> The size of <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables is limited by the value of the <a class="link" href="server-system-variables.html#sysvar_max_heap_table_size"> <code class="literal"> max_heap_table_size </code> </a> system variable, which is not replicated (see <a class="xref" href="replication-features-variables.html" title="19.5.1.39 Replication and Variables"> Section 19.5.1.39, “Replication and Variables” </a> ). A change in <code class="literal"> max_heap_table_size </code> takes effect for <code class="literal"> MEMORY </code> tables that are created or updated using <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE ... ENGINE = MEMORY </code> </a> or <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> following the change, or for all <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables following a server restart. If you increase the value of this variable on the source without doing so on the replica, it becomes possible for a table on the source to grow larger than its counterpart on the replica, leading to inserts that succeed on the source but fail on the replica with <span class="errortext"> Table is full </span> errors. This is a known issue (Bug #48666). In such cases, you must set the global value of <a class="link" href="server-system-variables.html#sysvar_max_heap_table_size"> <code class="literal"> max_heap_table_size </code> </a> on the replica as well as on the source, then restart replication. It is also recommended that you restart both the source and replica MySQL servers, to ensure that the new value takes complete (global) effect on each of them. </p> <p> See <a class="xref" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> Section 18.3, “The MEMORY Storage Engine” </a> , for more information about <a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine"> <code class="literal"> MEMORY </code> </a> tables. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/group-replication-monitoring.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="group-replication-monitoring"> </a> 20.4 Monitoring Group Replication </h2> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="group-replication-gtids.html"> 20.4.1 GTIDs and Group Replication </a> </span> </dt> <dt> <span class="section"> <a href="group-replication-server-states.html"> 20.4.2 Group Replication Server States </a> </span> </dt> <dt> <span class="section"> <a href="group-replication-replication-group-members.html"> 20.4.3 The replication_group_members Table </a> </span> </dt> <dt> <span class="section"> <a href="group-replication-replication-group-member-stats.html"> 20.4.4 The replication_group_member_stats Table </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045133752064"> </a> <p> You can use the MySQL <a class="link" href="performance-schema.html" title="Chapter 29 MySQL Performance Schema"> Performance Schema </a> to monitor Group Replication. These Performance Schema tables display information specific to Group Replication: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="link" href="performance-schema-replication-group-member-stats-table.html" title="29.12.11.15 The replication_group_member_stats Table"> <code class="literal"> replication_group_member_stats </code> </a> : See <a class="xref" href="group-replication-replication-group-member-stats.html" title="20.4.4 The replication_group_member_stats Table"> Section 20.4.4, “The replication_group_member_stats Table” </a> . </p> </li> <li class="listitem"> <p> <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> : See <a class="xref" href="group-replication-replication-group-members.html" title="20.4.3 The replication_group_members Table"> Section 20.4.3, “The replication_group_members Table” </a> . </p> </li> <li class="listitem"> <p> <a class="link" href="performance-schema-replication-group-communication-information-table.html" title="29.12.11.10 The replication_group_communication_information Table"> <code class="literal"> replication_group_communication_information </code> </a> : See <a class="xref" href="performance-schema-replication-group-communication-information-table.html" title="29.12.11.10 The replication_group_communication_information Table"> Section 29.12.11.10, “The replication_group_communication_information Table” </a> . </p> </li> </ul> </div> <p> These Performance Schema replication tables also show information relating to Group Replication: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="link" href="performance-schema-replication-connection-status-table.html" title="29.12.11.13 The replication_connection_status Table"> <code class="literal"> replication_connection_status </code> </a> shows information regarding Group Replication, such as transactions received from the group and queued in the applier queue (relay log). </p> </li> <li class="listitem"> <p> <a class="link" href="performance-schema-replication-applier-status-table.html" title="29.12.11.5 The replication_applier_status Table"> <code class="literal"> replication_applier_status </code> </a> shows the states of channels and threads relating to Group Replication. These can also be used to monitor what individual worker threads are doing. </p> </li> </ul> </div> <p> Replication channels created by the Group Replication plugin are listed here: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> group_replication_recovery </code> : Used for replication changes related to distributed recovery. </p> </li> <li class="listitem"> <p> <code class="literal"> group_replication_applier </code> : Used for the incoming changes from the group, to apply transactions coming directly from the group. </p> </li> </ul> </div> <p> For information about system variables affecting Group Replication, see <a class="xref" href="group-replication-system-variables.html" title="20.9.1 Group Replication System Variables"> Section 20.9.1, “Group Replication System Variables” </a> . See <a class="xref" href="group-replication-status-variables.html" title="20.9.2 Group Replication Status Variables"> Section 20.9.2, “Group Replication Status Variables” </a> , for status variables providing information about Group Replication. </p> <p> Messages relating to Group Replication lifecycle events other than errors are classified as system messages; these are always written to the replication group member' error log. You can use this information to review the history of a given server's membership in a replication group. </p> <p> Some lifecycle events that affect the whole group are logged on every group member, such as a new member entering <code class="literal"> ONLINE </code> status in the group or a primary election. Other events are logged only on the member where they take place, such as super read only mode being enabled or disabled on the member, or the member leaving the group. A number of lifecycle events that can indicate an issue if they occur frequently are logged as warning messages, including a member becoming unreachable and then reachable again, and a member starting distributed recovery by state transfer from the binary log or by a remote cloning operation. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If you are monitoring one or more secondary instances using <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program"> <span class="command"> <strong> mysqladmin </strong> </span> </a> , you should be aware that a <a class="link" href="flush.html#flush-status"> <code class="literal"> FLUSH STATUS </code> </a> statement executed by this utility creates a GTID event on the local instance which may impact future group operations. </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-option-tables.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="mysql-cluster-option-tables"> </a> 25.4.2.5 NDB Cluster mysqld Option and Variable Reference </h4> </div> </div> </div> <p> The following list includes command-line options, system variables, and status variables applicable within <code class="literal"> mysqld </code> when it is running as an SQL node in an NDB Cluster. For a reference to <span class="emphasis"> <em> all </em> </span> command-line options, system variables, and status variables used with or relating to <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> , see <a class="xref" href="server-option-variable-reference.html" title="7.1.4 Server Option, System Variable, and Status Variable Reference"> Section 7.1.4, “Server Option, System Variable, and Status Variable Reference” </a> . </p> <div class="itemizedlist"> <a name="mysql-cluster-mysqld-optvars-summary-list"> </a> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> <a class="link" href="server-status-variables.html#statvar_Com_xxx"> Com_show_ndb_status </a> </code> : Count of SHOW NDB STATUS statements. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Handler_discover"> Handler_discover </a> </code> : Number of times that tables have been discovered. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-applier-allow-skip-epoch"> ndb-applier-allow-skip-epoch </a> </code> : Lets replication applier skip epochs. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-batch-size"> ndb-batch-size </a> </code> : Size (in bytes) to use for NDB transaction batches. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-blob-read-batch-bytes"> ndb-blob-read-batch-bytes </a> </code> : Specifies size in bytes that large BLOB reads should be batched into. 0 = no limit. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-blob-write-batch-bytes"> ndb-blob-write-batch-bytes </a> </code> : Specifies size in bytes that large BLOB writes should be batched into. 0 = no limit. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-cluster-connection-pool"> ndb-cluster-connection-pool </a> </code> : Number of connections to cluster used by MySQL. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-cluster-connection-pool-nodeids"> ndb-cluster-connection-pool-nodeids </a> </code> : Comma-separated list of node IDs for connections to cluster used by MySQL; number of nodes in list must match value set for --ndb-cluster-connection-pool. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-connectstring"> ndb-connectstring </a> </code> : Address of NDB management server distributing configuration information for this cluster. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-default-column-format"> ndb-default-column-format </a> </code> : Use this value (FIXED or DYNAMIC) by default for COLUMN_FORMAT and ROW_FORMAT options when creating or adding table columns. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-deferred-constraints"> ndb-deferred-constraints </a> </code> : Specifies that constraint checks on unique indexes (where these are supported) should be deferred until commit time. Not normally needed or used; for testing purposes only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-distribution"> ndb-distribution </a> </code> : Default distribution for new tables in NDBCLUSTER (KEYHASH or LINHASH, default is KEYHASH). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-apply-status"> ndb-log-apply-status </a> </code> : Cause MySQL server acting as replica to log mysql.ndb_apply_status updates received from its immediate source in its own binary log, using its own server ID. Effective only if server is started with --ndbcluster option. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-empty-epochs"> ndb-log-empty-epochs </a> </code> : When enabled, causes epochs in which there were no changes to be written to ndb_apply_status and ndb_binlog_index tables, even when --log-slave-updates is enabled. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-empty-update"> ndb-log-empty-update </a> </code> : When enabled, causes updates that produced no changes to be written to ndb_apply_status and ndb_binlog_index tables, even when --log-slave-updates is enabled. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-exclusive-reads"> ndb-log-exclusive-reads </a> </code> : Log primary key reads with exclusive locks; allow conflict resolution based on read conflicts. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-fail-terminate"> ndb-log-fail-terminate </a> </code> : Terminate mysqld process if complete logging of all found row events is not possible. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-orig"> ndb-log-orig </a> </code> : Log originating server id and epoch in mysql.ndb_binlog_index table. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-transaction-dependency"> ndb-log-transaction-dependency </a> </code> : Make binary log thread calculate transaction dependencies for every transaction it writes to binary log. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-transaction-id"> ndb-log-transaction-id </a> </code> : Write NDB transaction IDs in binary log. Requires --log-bin-v1-events=OFF. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-minimal"> ndb-log-update-minimal </a> </code> : Log updates in minimal format. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-updated-only"> ndb-log-updated-only </a> </code> : Log updates only (ON) or complete rows (OFF). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-as-write"> ndb-log-update-as-write </a> </code> : Toggles logging of updates on source between updates (OFF) and writes (ON). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-mgm-tls"> ndb-mgm-tls </a> </code> : Whether TLS connection requirements are strict or relaxed. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-mgmd-host"> ndb-mgmd-host </a> </code> : Set host (and port, if desired) for connecting to management server. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-nodeid"> ndb-nodeid </a> </code> : NDB Cluster node ID for this MySQL server. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-optimized-node-selection"> ndb-optimized-node-selection </a> </code> : Enable optimizations for selection of nodes for transactions. Enabled by default; use --skip-ndb-optimized-node-selection to disable. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-tls-search-path"> ndb-tls-search-path </a> </code> : Directories to search for NDB TLS CAs and private keys. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-transid-mysql-connection-map"> ndb-transid-mysql-connection-map </a> </code> : Enable or disable ndb_transid_mysql_connection_map plugin; that is, enable or disable INFORMATION_SCHEMA table having that name. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-wait-connected"> ndb-wait-connected </a> </code> : Time (in seconds) for MySQL server to wait for connection to cluster management and data nodes before accepting MySQL client connections. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-wait-setup"> ndb-wait-setup </a> </code> : Time (in seconds) for MySQL server to wait for NDB engine setup to complete. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-allow-copying-alter-table"> ndb-allow-copying-alter-table </a> </code> : Set to OFF to keep ALTER TABLE from using copying operations on NDB tables. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_deferred_count"> Ndb_api_adaptive_send_deferred_count </a> </code> : Number of adaptive send calls not actually sent by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_deferred_count_session"> Ndb_api_adaptive_send_deferred_count_session </a> </code> : Number of adaptive send calls not actually sent in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_deferred_count_replica"> Ndb_api_adaptive_send_deferred_count_replica </a> </code> : Number of adaptive send calls not actually sent by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_deferred_count_slave"> Ndb_api_adaptive_send_deferred_count_slave </a> </code> : Number of adaptive send calls not actually sent by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_forced_count"> Ndb_api_adaptive_send_forced_count </a> </code> : Number of adaptive sends with forced-send set sent by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_forced_count_session"> Ndb_api_adaptive_send_forced_count_session </a> </code> : Number of adaptive sends with forced-send set in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_forced_count_replica"> Ndb_api_adaptive_send_forced_count_replica </a> </code> : Number of adaptive sends with forced-send set sent by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_forced_count_slave"> Ndb_api_adaptive_send_forced_count_slave </a> </code> : Number of adaptive sends with forced-send set sent by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_unforced_count"> Ndb_api_adaptive_send_unforced_count </a> </code> : Number of adaptive sends without forced-send sent by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_unforced_count_session"> Ndb_api_adaptive_send_unforced_count_session </a> </code> : Number of adaptive sends without forced-send in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_unforced_count_replica"> Ndb_api_adaptive_send_unforced_count_replica </a> </code> : Number of adaptive sends without forced-send sent by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_adaptive_send_unforced_count_slave"> Ndb_api_adaptive_send_unforced_count_slave </a> </code> : Number of adaptive sends without forced-send sent by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count"> Ndb_api_bytes_received_count </a> </code> : Quantity of data (in bytes) received from data nodes by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count_session"> Ndb_api_bytes_received_count_session </a> </code> : Quantity of data (in bytes) received from data nodes in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count_replica"> Ndb_api_bytes_received_count_replica </a> </code> : Quantity of data (in bytes) received from data nodes by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count_slave"> Ndb_api_bytes_received_count_slave </a> </code> : Quantity of data (in bytes) received from data nodes by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count"> Ndb_api_bytes_sent_count </a> </code> : Quantity of data (in bytes) sent to data nodes by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count_session"> Ndb_api_bytes_sent_count_session </a> </code> : Quantity of data (in bytes) sent to data nodes in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count_replica"> Ndb_api_bytes_sent_count_replica </a> </code> : Qunatity of data (in bytes) sent to data nodes by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count_slave"> Ndb_api_bytes_sent_count_slave </a> </code> : Qunatity of data (in bytes) sent to data nodes by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_event_bytes_count"> Ndb_api_event_bytes_count </a> </code> : Number of bytes of events received by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_event_bytes_count_injector"> Ndb_api_event_bytes_count_injector </a> </code> : Number of bytes of event data received by NDB binary log injector thread. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_event_data_count"> Ndb_api_event_data_count </a> </code> : Number of row change events received by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_event_data_count_injector"> Ndb_api_event_data_count_injector </a> </code> : Number of row change events received by NDB binary log injector thread. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_event_nondata_count"> Ndb_api_event_nondata_count </a> </code> : Number of events received, other than row change events, by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_event_nondata_count_injector"> Ndb_api_event_nondata_count_injector </a> </code> : Number of events received, other than row change events, by NDB binary log injector thread. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count"> Ndb_api_pk_op_count </a> </code> : Number of operations based on or using primary keys by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count_session"> Ndb_api_pk_op_count_session </a> </code> : Number of operations based on or using primary keys in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count_replica"> Ndb_api_pk_op_count_replica </a> </code> : Number of operations based on or using primary keys by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count_slave"> Ndb_api_pk_op_count_slave </a> </code> : Number of operations based on or using primary keys by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count"> Ndb_api_pruned_scan_count </a> </code> : Number of scans that have been pruned to one partition by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count_session"> Ndb_api_pruned_scan_count_session </a> </code> : Number of scans that have been pruned to one partition in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count_replica"> Ndb_api_pruned_scan_count_replica </a> </code> : Number of scans that have been pruned to one partition by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count_slave"> Ndb_api_pruned_scan_count_slave </a> </code> : Number of scans that have been pruned to one partition by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count"> Ndb_api_range_scan_count </a> </code> : Number of range scans that have been started by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count_session"> Ndb_api_range_scan_count_session </a> </code> : Number of range scans that have been started in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count_replica"> Ndb_api_range_scan_count_replica </a> </code> : Number of range scans that have been started by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count_slave"> Ndb_api_range_scan_count_slave </a> </code> : Number of range scans that have been started by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count"> Ndb_api_read_row_count </a> </code> : Total number of rows that have been read by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count_session"> Ndb_api_read_row_count_session </a> </code> : Total number of rows that have been read in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count_replica"> Ndb_api_read_row_count_replica </a> </code> : Total number of rows that have been read by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count_slave"> Ndb_api_read_row_count_slave </a> </code> : Total number of rows that have been read by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count"> Ndb_api_scan_batch_count </a> </code> : Number of batches of rows received by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count_session"> Ndb_api_scan_batch_count_session </a> </code> : Number of batches of rows received in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count_replica"> Ndb_api_scan_batch_count_replica </a> </code> : Number of batches of rows received by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count_slave"> Ndb_api_scan_batch_count_slave </a> </code> : Number of batches of rows received by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count"> Ndb_api_table_scan_count </a> </code> : Number of table scans that have been started, including scans of internal tables, by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count_session"> Ndb_api_table_scan_count_session </a> </code> : Number of table scans that have been started, including scans of internal tables, in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count_replica"> Ndb_api_table_scan_count_replica </a> </code> : Number of table scans that have been started, including scans of internal tables, by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count_slave"> Ndb_api_table_scan_count_slave </a> </code> : Number of table scans that have been started, including scans of internal tables, by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count"> Ndb_api_trans_abort_count </a> </code> : Number of transactions aborted by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count_session"> Ndb_api_trans_abort_count_session </a> </code> : Number of transactions aborted in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count_replica"> Ndb_api_trans_abort_count_replica </a> </code> : Number of transactions aborted by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count_slave"> Ndb_api_trans_abort_count_slave </a> </code> : Number of transactions aborted by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count"> Ndb_api_trans_close_count </a> </code> : Number of transactions closed by this MySQL Server (SQL node); may be greater than sum of TransCommitCount and TransAbortCount. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count_session"> Ndb_api_trans_close_count_session </a> </code> : Number of transactions aborted (may be greater than sum of TransCommitCount and TransAbortCount) in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count_replica"> Ndb_api_trans_close_count_replica </a> </code> : Number of transactions aborted (may be greater than sum of TransCommitCount and TransAbortCount) by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count_slave"> Ndb_api_trans_close_count_slave </a> </code> : Number of transactions aborted (may be greater than sum of TransCommitCount and TransAbortCount) by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count"> Ndb_api_trans_commit_count </a> </code> : Number of transactions committed by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count_session"> Ndb_api_trans_commit_count_session </a> </code> : Number of transactions committed in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count_replica"> Ndb_api_trans_commit_count_replica </a> </code> : Number of transactions committed by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count_slave"> Ndb_api_trans_commit_count_slave </a> </code> : Number of transactions committed by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count"> Ndb_api_trans_local_read_row_count </a> </code> : Total number of rows that have been read by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count_session"> Ndb_api_trans_local_read_row_count_session </a> </code> : Total number of rows that have been read in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count_replica"> Ndb_api_trans_local_read_row_count_replica </a> </code> : Total number of rows that have been read by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count_slave"> Ndb_api_trans_local_read_row_count_slave </a> </code> : Total number of rows that have been read by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count"> Ndb_api_trans_start_count </a> </code> : Number of transactions started by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count_session"> Ndb_api_trans_start_count_session </a> </code> : Number of transactions started in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count_replica"> Ndb_api_trans_start_count_replica </a> </code> : Number of transactions started by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count_slave"> Ndb_api_trans_start_count_slave </a> </code> : Number of transactions started by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count"> Ndb_api_uk_op_count </a> </code> : Number of operations based on or using unique keys by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count_session"> Ndb_api_uk_op_count_session </a> </code> : Number of operations based on or using unique keys in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count_replica"> Ndb_api_uk_op_count_replica </a> </code> : Number of operations based on or using unique keys by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count_slave"> Ndb_api_uk_op_count_slave </a> </code> : Number of operations based on or using unique keys by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count"> Ndb_api_wait_exec_complete_count </a> </code> : Number of times thread has been blocked while waiting for operation execution to complete by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count_session"> Ndb_api_wait_exec_complete_count_session </a> </code> : Number of times thread has been blocked while waiting for operation execution to complete in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count_replica"> Ndb_api_wait_exec_complete_count_replica </a> </code> : Number of times thread has been blocked while waiting for operation execution to complete by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count_slave"> Ndb_api_wait_exec_complete_count_slave </a> </code> : Number of times thread has been blocked while waiting for operation execution to complete by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count"> Ndb_api_wait_meta_request_count </a> </code> : Number of times thread has been blocked waiting for metadata-based signal by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count_session"> Ndb_api_wait_meta_request_count_session </a> </code> : Number of times thread has been blocked waiting for metadata-based signal in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count_replica"> Ndb_api_wait_meta_request_count_replica </a> </code> : Number of times thread has been blocked waiting for metadata-based signal by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count_slave"> Ndb_api_wait_meta_request_count_slave </a> </code> : Number of times thread has been blocked waiting for metadata-based signal by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count"> Ndb_api_wait_nanos_count </a> </code> : Total time (in nanoseconds) spent waiting for some type of signal from data nodes by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_session"> Ndb_api_wait_nanos_count_session </a> </code> : Total time (in nanoseconds) spent waiting for some type of signal from data nodes in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_replica"> Ndb_api_wait_nanos_count_replica </a> </code> : Total time (in nanoseconds) spent waiting for some type of signal from data nodes by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_slave"> Ndb_api_wait_nanos_count_slave </a> </code> : Total time (in nanoseconds) spent waiting for some type of signal from data nodes by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count"> Ndb_api_wait_scan_result_count </a> </code> : Number of times thread has been blocked while waiting for scan-based signal by this MySQL Server (SQL node). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count_session"> Ndb_api_wait_scan_result_count_session </a> </code> : Number of times thread has been blocked while waiting for scan-based signal in this client session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count_replica"> Ndb_api_wait_scan_result_count_replica </a> </code> : Number of times thread has been blocked while waiting for scan-based signal by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count_slave"> Ndb_api_wait_scan_result_count_slave </a> </code> : Number of times thread has been blocked while waiting for scan-based signal by this replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_autoincrement_prefetch_sz"> ndb_autoincrement_prefetch_sz </a> </code> : NDB auto-increment prefetch size. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_clear_apply_status"> ndb_clear_apply_status </a> </code> : Causes RESET SLAVE/RESET REPLICA to clear all rows from ndb_apply_status table; ON by default. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_cluster_node_id"> Ndb_cluster_node_id </a> </code> : Node ID of this server when acting as NDB Cluster SQL node. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_config_from_host"> Ndb_config_from_host </a> </code> : NDB Cluster management server host name or IP address. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_config_from_port"> Ndb_config_from_port </a> </code> : Port for connecting to NDB Cluster management server. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_config_generation"> Ndb_config_generation </a> </code> : Generation number of the current configuration of the cluster. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_epoch"> Ndb_conflict_fn_epoch </a> </code> : Number of rows that have been found in conflict by NDB$EPOCH() NDB replication conflict detection function. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_epoch2"> Ndb_conflict_fn_epoch2 </a> </code> : Number of rows that have been found in conflict by NDB replication NDB$EPOCH2() conflict detection function. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_epoch2_trans"> Ndb_conflict_fn_epoch2_trans </a> </code> : Number of rows that have been found in conflict by NDB replication NDB$EPOCH2_TRANS() conflict detection function. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_epoch_trans"> Ndb_conflict_fn_epoch_trans </a> </code> : Number of rows that have been found in conflict by NDB$EPOCH_TRANS() conflict detection function. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_max"> Ndb_conflict_fn_max </a> </code> : Number of times that NDB replication conflict resolution based on "greater timestamp wins" has been applied to update and delete operations. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_max_del_win"> Ndb_conflict_fn_max_del_win </a> </code> : Number of times that NDB replication conflict resolution based on outcome of NDB$MAX_DELETE_WIN() has been applied to update and delete operations. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_max_ins"> Ndb_conflict_fn_max_ins </a> </code> : Number of times that NDB replication conflict resolution based on "greater timestamp wins" has been applied to insert operations. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_max_del_win_ins"> Ndb_conflict_fn_max_del_win_ins </a> </code> : Number of times that NDB replication conflict resolution based on outcome of NDB$MAX_DEL_WIN_INS() has been applied to insert operations. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_fn_old"> Ndb_conflict_fn_old </a> </code> : Number of times that NDB replication "same timestamp wins" conflict resolution has been applied. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_last_conflict_epoch"> Ndb_conflict_last_conflict_epoch </a> </code> : Most recent NDB epoch on this replica in which some conflict was detected. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_last_stable_epoch"> Ndb_conflict_last_stable_epoch </a> </code> : Most recent epoch containing no conflicts. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_reflected_op_discard_count"> Ndb_conflict_reflected_op_discard_count </a> </code> : Number of reflected operations that were not applied due error during execution. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_reflected_op_prepare_count"> Ndb_conflict_reflected_op_prepare_count </a> </code> : Number of reflected operations received that have been prepared for execution. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_refresh_op_count"> Ndb_conflict_refresh_op_count </a> </code> : Number of refresh operations that have been prepared. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_conflict_role"> ndb_conflict_role </a> </code> : Role for replica to play in conflict detection and resolution. Value is one of PRIMARY, SECONDARY, PASS, or NONE (default). Can be changed only when replication SQL thread is stopped. See documentation for further information. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_trans_conflict_commit_count"> Ndb_conflict_trans_conflict_commit_count </a> </code> : Number of epoch transactions committed after requiring transactional conflict handling. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_trans_detect_iter_count"> Ndb_conflict_trans_detect_iter_count </a> </code> : Number of internal iterations required to commit epoch transaction. Should be (slightly) greater than or equal to Ndb_conflict_trans_conflict_commit_count. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_trans_reject_count"> Ndb_conflict_trans_reject_count </a> </code> : Number of transactions rejected after being found in conflict by transactional conflict function. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_trans_row_conflict_count"> Ndb_conflict_trans_row_conflict_count </a> </code> : Number of rows found in conflict by transactional conflict function. Includes any rows included in or dependent on conflicting transactions. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_conflict_trans_row_reject_count"> Ndb_conflict_trans_row_reject_count </a> </code> : Total number of rows realigned after being found in conflict by transactional conflict function. Includes Ndb_conflict_trans_row_conflict_count and any rows included in or dependent on conflicting transactions. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_data_node_neighbour"> ndb_data_node_neighbour </a> </code> : Specifies cluster data node "closest" to this MySQL Server, for transaction hinting and fully replicated tables. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_default_column_format"> ndb_default_column_format </a> </code> : Sets default row format and column format (FIXED or DYNAMIC) used for new NDB tables. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_deferred_constraints"> ndb_deferred_constraints </a> </code> : Specifies that constraint checks should be deferred (where these are supported). Not normally needed or used; for testing purposes only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_dbg_check_shares"> ndb_dbg_check_shares </a> </code> : Check for any lingering shares (debug builds only). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-schema-dist-timeout"> ndb-schema-dist-timeout </a> </code> : How long to wait before detecting timeout during schema distribution. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_distribution"> ndb_distribution </a> </code> : Default distribution for new tables in NDBCLUSTER (KEYHASH or LINHASH, default is KEYHASH). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_epoch_delete_delete_count"> Ndb_epoch_delete_delete_count </a> </code> : Number of delete-delete conflicts detected (delete operation is applied, but row does not exist). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_eventbuffer_free_percent"> ndb_eventbuffer_free_percent </a> </code> : Percentage of free memory that should be available in event buffer before resumption of buffering, after reaching limit set by ndb_eventbuffer_max_alloc. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_eventbuffer_max_alloc"> ndb_eventbuffer_max_alloc </a> </code> : Maximum memory that can be allocated for buffering events by NDB API. Defaults to 0 (no limit). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_execute_count"> Ndb_execute_count </a> </code> : Number of round trips to NDB kernel made by operations. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_extra_logging"> ndb_extra_logging </a> </code> : Controls logging of NDB Cluster schema, connection, and data distribution events in MySQL error log. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_force_send"> ndb_force_send </a> </code> : Forces sending of buffers to NDB immediately, without waiting for other threads. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_fully_replicated"> ndb_fully_replicated </a> </code> : Whether new NDB tables are fully replicated. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_index_stat_enable"> ndb_index_stat_enable </a> </code> : Use NDB index statistics in query optimization. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_index_stat_option"> ndb_index_stat_option </a> </code> : Comma-separated list of tunable options for NDB index statistics; list should contain no spaces. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_join_pushdown"> ndb_join_pushdown </a> </code> : Enables pushing down of joins to data nodes. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_last_commit_epoch_server"> Ndb_last_commit_epoch_server </a> </code> : Epoch most recently committed by NDB. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_last_commit_epoch_session"> Ndb_last_commit_epoch_session </a> </code> : Epoch most recently committed by this NDB client. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_apply_status"> ndb_log_apply_status </a> </code> : Whether or not MySQL server acting as replica logs mysql.ndb_apply_status updates received from its immediate source in its own binary log, using its own server ID. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_bin"> ndb_log_bin </a> </code> : Write updates to NDB tables in binary log. Effective only if binary logging is enabled with --log-bin. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_binlog_index"> ndb_log_binlog_index </a> </code> : Insert mapping between epochs and binary log positions into ndb_binlog_index table. Defaults to ON. Effective only if binary logging is enabled. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_cache_size"> ndb_log_cache_size </a> </code> : Set size of transaction cache used for recording NDB binary log. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_empty_epochs"> ndb_log_empty_epochs </a> </code> : When enabled, epochs in which there were no changes are written to ndb_apply_status and ndb_binlog_index tables, even when log_replica_updates or log_slave_updates is enabled. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_empty_update"> ndb_log_empty_update </a> </code> : When enabled, updates which produce no changes are written to ndb_apply_status and ndb_binlog_index tables, even when log_replica_updates or log_slave_updates is enabled. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_exclusive_reads"> ndb_log_exclusive_reads </a> </code> : Log primary key reads with exclusive locks; allow conflict resolution based on read conflicts. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_orig"> ndb_log_orig </a> </code> : Whether id and epoch of originating server are recorded in mysql.ndb_binlog_index table. Set using --ndb-log-orig option when starting mysqld. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_transaction_id"> ndb_log_transaction_id </a> </code> : Whether NDB transaction IDs are written into binary log (Read-only). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_transaction_compression"> ndb_log_transaction_compression </a> </code> : Whether to compress NDB binary log; can also be enabled on startup by enabling --binlog-transaction-compression option. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_transaction_compression_level_zstd"> ndb_log_transaction_compression_level_zstd </a> </code> : The ZSTD compression level to use when writing compressed transactions to the NDB binary log. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_metadata_check"> ndb_metadata_check </a> </code> : Enable auto-detection of NDB metadata changes with respect to MySQL data dictionary; enabled by default. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_metadata_check_interval"> ndb_metadata_check_interval </a> </code> : Interval in seconds to perform check for NDB metadata changes with respect to MySQL data dictionary. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_metadata_detected_count"> Ndb_metadata_detected_count </a> </code> : Number of times NDB metadata change monitor thread has detected changes. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_metadata_excluded_count"> Ndb_metadata_excluded_count </a> </code> : Number of NDB metadata objects that NDB binlog thread has failed to synchronize. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_metadata_sync"> ndb_metadata_sync </a> </code> : Triggers immediate synchronization of all changes between NDB dictionary and MySQL data dictionary; causes ndb_metadata_check and ndb_metadata_check_interval values to be ignored. Resets to false when synchronization is complete. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_metadata_synced_count"> Ndb_metadata_synced_count </a> </code> : Number of NDB metadata objects which have been synchronized. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_number_of_data_nodes"> Ndb_number_of_data_nodes </a> </code> : Number of data nodes in this NDB cluster; set only if server participates in cluster. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-optimization-delay"> ndb-optimization-delay </a> </code> : Number of milliseconds to wait between processing sets of rows by OPTIMIZE TABLE on NDB tables. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_optimized_node_selection"> ndb_optimized_node_selection </a> </code> : Determines how SQL node chooses cluster data node to use as transaction coordinator. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_pruned_scan_count"> Ndb_pruned_scan_count </a> </code> : Number of scans executed by NDB since cluster was last started where partition pruning could be used. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_pushed_queries_defined"> Ndb_pushed_queries_defined </a> </code> : Number of joins that API nodes have attempted to push down to data nodes. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_pushed_queries_dropped"> Ndb_pushed_queries_dropped </a> </code> : Number of joins that API nodes have tried to push down, but failed. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_pushed_queries_executed"> Ndb_pushed_queries_executed </a> </code> : Number of joins successfully pushed down and executed on data nodes. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_pushed_reads"> Ndb_pushed_reads </a> </code> : Number of reads executed on data nodes by pushed-down joins. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_read_backup"> ndb_read_backup </a> </code> : Enable read from any replica for all NDB tables; use NDB_TABLE=READ_BACKUP={0|1} with CREATE TABLE or ALTER TABLE to enable or disable for individual NDB tables. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_recv_thread_activation_threshold"> ndb_recv_thread_activation_threshold </a> </code> : Activation threshold when receive thread takes over polling of cluster connection (measured in concurrently active threads). </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_recv_thread_cpu_mask"> ndb_recv_thread_cpu_mask </a> </code> : CPU mask for locking receiver threads to specific CPUs; specified as hexadecimal. See documentation for details. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_replica_max_replicated_epoch"> Ndb_replica_max_replicated_epoch </a> </code> : Most recently committed NDB epoch on this replica. When this value is greater than or equal to Ndb_conflict_last_conflict_epoch, no conflicts have yet been detected. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_replica_batch_size"> ndb_replica_batch_size </a> </code> : Batch size in bytes for replica applier. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_report_thresh_binlog_epoch_slip"> ndb_report_thresh_binlog_epoch_slip </a> </code> : NDB 7.5 and later: Threshold for number of epochs completely buffered, but not yet consumed by binlog injector thread which when exceeded generates BUFFERED_EPOCHS_OVER_THRESHOLD event buffer status message; prior to NDB 7.5: Threshold for number of epochs to lag behind before reporting binary log status. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_report_thresh_binlog_mem_usage"> ndb_report_thresh_binlog_mem_usage </a> </code> : Threshold for percentage of free memory remaining before reporting binary log status. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_row_checksum"> ndb_row_checksum </a> </code> : When enabled, set row checksums; enabled by default. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_scan_count"> Ndb_scan_count </a> </code> : Total number of scans executed by NDB since cluster was last started. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_schema_dist_lock_wait_timeout"> ndb_schema_dist_lock_wait_timeout </a> </code> : Time during schema distribution to wait for lock before returning error. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_schema_dist_timeout"> ndb_schema_dist_timeout </a> </code> : Time to wait before detecting timeout during schema distribution. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_schema_dist_upgrade_allowed"> ndb_schema_dist_upgrade_allowed </a> </code> : Allow schema distribution table upgrade when connecting to NDB. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_show_foreign_key_mock_tables"> ndb_show_foreign_key_mock_tables </a> </code> : Show mock tables used to support foreign_key_checks=0. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_slave_conflict_role"> ndb_slave_conflict_role </a> </code> : Role for replica to play in conflict detection and resolution. Value is one of PRIMARY, SECONDARY, PASS, or NONE (default). Can be changed only when replication SQL thread is stopped. See documentation for further information. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_slave_max_replicated_epoch"> Ndb_slave_max_replicated_epoch </a> </code> : Most recently committed NDB epoch on this replica. When this value is greater than or equal to Ndb_conflict_last_conflict_epoch, no conflicts have yet been detected. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_system_name"> Ndb_system_name </a> </code> : Configured cluster system name; empty if server not connected to NDB. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_table_no_logging"> ndb_table_no_logging </a> </code> : NDB tables created when this setting is enabled are not checkpointed to disk (although table schema files are created). Setting in effect when table is created with or altered to use NDBCLUSTER persists for table's lifetime. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_table_temporary"> ndb_table_temporary </a> </code> : NDB tables are not persistent on disk: no schema files are created and tables are not logged. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#statvar_Ndb_trans_hint_count_session"> Ndb_trans_hint_count_session </a> </code> : Number of transactions using hints that have been started in this session. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_use_copying_alter_table"> ndb_use_copying_alter_table </a> </code> : Use copying ALTER TABLE operations in NDB Cluster. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_use_exact_count"> ndb_use_exact_count </a> </code> : Forces NDB to use a count of records during SELECT COUNT(*) query planning to speed up this type of query. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_use_transactions"> ndb_use_transactions </a> </code> : Set to OFF, to disable transaction support by NDB. Not recommended except in certain special cases; see documentation for details. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_version"> ndb_version </a> </code> : Shows build and NDB engine version as an integer. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_version_string"> ndb_version_string </a> </code> : Shows build information including NDB engine version in ndb-x.y.z format. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndbcluster"> ndbcluster </a> </code> : Enable NDB Cluster (if this version of MySQL supports it). Disabled by <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_skip-ndbcluster"> <code class="option"> --skip-ndbcluster </code> </a> . </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndbinfo"> ndbinfo </a> </code> : Enable ndbinfo plugin, if supported. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_database"> ndbinfo_database </a> </code> : Name used for NDB information database; read only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_max_bytes"> ndbinfo_max_bytes </a> </code> : Used for debugging only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_max_rows"> ndbinfo_max_rows </a> </code> : Used for debugging only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_offline"> ndbinfo_offline </a> </code> : Put ndbinfo database into offline mode, in which no rows are returned from tables or views. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_show_hidden"> ndbinfo_show_hidden </a> </code> : Whether to show ndbinfo internal base tables in mysql client; default is OFF. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_table_prefix"> ndbinfo_table_prefix </a> </code> : Prefix to use for naming ndbinfo internal base tables; read only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndbinfo_version"> ndbinfo_version </a> </code> : ndbinfo engine version; read only. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_replica_allow_batching"> replica_allow_batching </a> </code> : Turns update batching on and off for replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_server_id_bits"> server_id_bits </a> </code> : Number of least significant bits in server_id actually used for identifying server, permitting NDB API applications to store application data in most significant bits. server_id must be less than 2 to power of this value. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_skip-ndbcluster"> skip-ndbcluster </a> </code> : Disable NDB Cluster storage engine. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_slave_allow_batching"> slave_allow_batching </a> </code> : Turns update batching on and off for replica. </p> </li> <li class="listitem"> <p> <code class="literal"> <a class="link" href="mysql-cluster-options-variables.html#sysvar_transaction_allow_batching"> transaction_allow_batching </a> </code> : Allows batching of statements within one transaction. Disable AUTOCOMMIT to use. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-pre-filtering.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="performance-schema-pre-filtering"> </a> 29.4.3 Event Pre-Filtering </h3> </div> </div> </div> <p> Pre-filtering is done by the Performance Schema and has a global effect that applies to all users. Pre-filtering can be applied to either the producer or consumer stage of event processing: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> To configure pre-filtering at the producer stage, several tables can be used: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table"> <code class="literal"> setup_instruments </code> </a> indicates which instruments are available. An instrument disabled in this table produces no events regardless of the contents of the other production-related setup tables. An instrument enabled in this table is permitted to produce events, subject to the contents of the other tables. </p> </li> <li class="listitem"> <p> <a class="link" href="performance-schema-setup-objects-table.html" title="29.12.2.4 The setup_objects Table"> <code class="literal"> setup_objects </code> </a> controls whether the Performance Schema monitors particular table and stored program objects. </p> </li> <li class="listitem"> <p> <a class="link" href="performance-schema-threads-table.html" title="29.12.22.8 The threads Table"> <code class="literal"> threads </code> </a> indicates whether monitoring is enabled for each server thread. </p> </li> <li class="listitem"> <p> <a class="link" href="performance-schema-setup-actors-table.html" title="29.12.2.1 The setup_actors Table"> <code class="literal"> setup_actors </code> </a> determines the initial monitoring state for new foreground threads. </p> </li> </ul> </div> </li> <li class="listitem"> <p> To configure pre-filtering at the consumer stage, modify the <a class="link" href="performance-schema-setup-consumers-table.html" title="29.12.2.2 The setup_consumers Table"> <code class="literal"> setup_consumers </code> </a> table. This determines the destinations to which events are sent. <a class="link" href="performance-schema-setup-consumers-table.html" title="29.12.2.2 The setup_consumers Table"> <code class="literal"> setup_consumers </code> </a> also implicitly affects event production. If a given event is not sent to any destination (that is, it is never consumed), the Performance Schema does not produce it. </p> </li> </ul> </div> <p> Modifications to any of these tables affect monitoring immediately, with the exception that modifications to the <a class="link" href="performance-schema-setup-actors-table.html" title="29.12.2.1 The setup_actors Table"> <code class="literal"> setup_actors </code> </a> table affect only foreground threads created subsequent to the modification, not existing threads. </p> <p> When you change the monitoring configuration, the Performance Schema does not flush the history tables. Events already collected remain in the current-events and history tables until displaced by newer events. If you disable instruments, you might need to wait a while before events for them are displaced by newer events of interest. Alternatively, use <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> to empty the history tables. </p> <p> After making instrumentation changes, you might want to truncate the summary tables. Generally, the effect is to reset the summary columns to 0 or <code class="literal"> NULL </code> , not to remove rows. This enables you to clear collected values and restart aggregation. That might be useful, for example, after you have made a runtime configuration change. Exceptions to this truncation behavior are noted in individual summary table sections. </p> <p> The following sections describe how to use specific tables to control Performance Schema pre-filtering. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/create-user.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="create-user"> </a> 15.7.1.3 CREATE USER Statement </h4> </div> </div> </div> <a class="indexterm" name="idm46045174571200"> </a> <a class="indexterm" name="idm46045174570128"> </a> <a class="indexterm" name="idm46045174568640"> </a> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14368259"><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 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">user</em></span> <span class="token punctuation">[</span><em class="replaceable">auth_option</em><span class="token punctuation">]</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><em class="replaceable">auth_option</em><span class="token punctuation">]</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">DEFAULT</span> <span class="token keyword">ROLE</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 punctuation">[</span><span class="token keyword">REQUIRE</span> {<span class="token keyword">NONE</span> <span class="token operator">|</span> <em class="replaceable">tls_option</em> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token operator">AND</span><span class="token punctuation">]</span> <em class="replaceable">tls_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</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">WITH</span> <em class="replaceable">resource_option</em> <span class="token punctuation">[</span><em class="replaceable">resource_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">password_option</em> <span class="token operator">|</span> <em class="replaceable">lock_option</em><span class="token punctuation">]</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">COMMENT</span> <span class="token string">'<em class="replaceable">comment_string</em>'</span> <span class="token operator">|</span> <span class="token keyword">ATTRIBUTE</span> <span class="token string">'<em class="replaceable">json_object</em>'</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">user</em></span>: <span class="token punctuation">(</span>see Section <span class="token number">8.2</span><span class="token punctuation">.</span><span class="token number">4</span><span class="token punctuation">,</span> “Specifying <span class="token keyword">Account</span> <span class="token keyword">Names</span>”<span class="token punctuation">)</span> <em class="replaceable">auth_option</em>: { <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">2fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">2fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">2fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">2fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">2fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">2fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token punctuation">[</span><em class="replaceable">initial_auth_option</em><span class="token punctuation">]</span> } <em class="replaceable">2fa_auth_option</em>: { <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">3fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">3fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">3fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">3fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">3fa_auth_option</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token punctuation">[</span><span class="token operator">AND</span> <em class="replaceable">3fa_auth_option</em><span class="token punctuation">]</span> } <em class="replaceable">3fa_auth_option</em>: { <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">BY</span> <span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token operator">|</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> } <em class="replaceable">initial_auth_option</em>: { INITIAL AUTHENTICATION <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> {<span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token operator">|</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span>} <span class="token operator">|</span> INITIAL AUTHENTICATION <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> <em class="replaceable">auth_plugin</em> <span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span> } <em class="replaceable">tls_option</em>: { <span class="token keyword">SSL</span> <span class="token operator">|</span> <span class="token keyword">X509</span> <span class="token operator">|</span> <span class="token keyword">CIPHER</span> <span class="token string">'<em class="replaceable">cipher</em>'</span> <span class="token operator">|</span> <span class="token keyword">ISSUER</span> <span class="token string">'<em class="replaceable">issuer</em>'</span> <span class="token operator">|</span> <span class="token keyword">SUBJECT</span> <span class="token string">'<em class="replaceable">subject</em>'</span> } <em class="replaceable">resource_option</em>: { <span class="token keyword">MAX_QUERIES_PER_HOUR</span> <em class="replaceable">count</em> <span class="token operator">|</span> <span class="token keyword">MAX_UPDATES_PER_HOUR</span> <em class="replaceable">count</em> <span class="token operator">|</span> <span class="token keyword">MAX_CONNECTIONS_PER_HOUR</span> <em class="replaceable">count</em> <span class="token operator">|</span> <span class="token keyword">MAX_USER_CONNECTIONS</span> <em class="replaceable">count</em> } <em class="replaceable">password_option</em>: { <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <span class="token keyword">NEVER</span> <span class="token operator">|</span> <span class="token keyword">INTERVAL</span> <em class="replaceable">N</em> <span class="token keyword">DAY</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <em class="replaceable">N</em>} <span class="token operator">|</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <em class="replaceable">N</em> <span class="token keyword">DAY</span>} <span class="token operator">|</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <span class="token keyword">OPTIONAL</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">FAILED_LOGIN_ATTEMPTS</span> <em class="replaceable">N</em> <span class="token operator">|</span> <span class="token keyword">PASSWORD_LOCK_TIME</span> {<em class="replaceable">N</em> <span class="token operator">|</span> <span class="token keyword">UNBOUNDED</span>} } <em class="replaceable">lock_option</em>: { <span class="token keyword">ACCOUNT</span> <span class="token keyword">LOCK</span> <span class="token operator">|</span> <span class="token keyword">ACCOUNT</span> <span class="token keyword">UNLOCK</span> }</code></pre> </div> <p> The <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> statement creates new MySQL accounts. It enables authentication, role, SSL/TLS, resource-limit, password-management, comment, and attribute properties to be established for new accounts. It also controls whether accounts are initially locked or unlocked. </p> <p> To use <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE 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_insert"> <code class="literal"> INSERT </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="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE 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> These additional privilege considerations also apply: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The <a class="link" href="server-system-variables.html#sysvar_authentication_policy"> <code class="literal"> authentication_policy </code> </a> system variable places certain constraints on how the authentication-related clauses of <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> statements may be used; for details, see the description of that variable. These constraints do not apply if you have the <a class="link" href="privileges-provided.html#priv_authentication-policy-admin"> <code class="literal"> AUTHENTICATION_POLICY_ADMIN </code> </a> privilege. </p> </li> <li class="listitem"> <p> To create an account that uses passwordless authentication, you must have the <a class="link" href="privileges-provided.html#priv_passwordless-user-admin"> <code class="literal"> PASSWORDLESS_USER_ADMIN </code> </a> privilege. </p> </li> </ul> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> fails with an error if any account to be created is named as the <code class="literal"> DEFINER </code> attribute for any stored object. (That is, the statement fails if creating an account would cause the account to adopt a currently orphaned stored object.) 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. To perform the user-creation operation without either of these, drop the orphan objects, create the account and grant its privileges, and then re-create the dropped objects. 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> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> either succeeds for all named users or rolls back and has no effect if any error occurs. By default, an error occurs if you try to create a user that already exists. If the <code class="literal"> IF NOT EXISTS </code> clause is given, the statement produces a warning for each named user that already exists, rather than an error. </p> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> Under some circumstances, <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> may be recorded in server logs or on the client side in a history file such as <code class="filename"> ~/.mysql_history </code> , which means that cleartext passwords may be read by anyone having read access to that information. For information about the conditions under which this occurs for the server logs and how to control it, see <a class="xref" href="password-logging.html" title="8.1.2.3 Passwords and Logging"> Section 8.1.2.3, “Passwords and Logging” </a> . For similar information about client-side logging, see <a class="xref" href="mysql-logging.html" title="6.5.1.3 mysql Client Logging"> Section 6.5.1.3, “mysql Client Logging” </a> . </p> </div> <p> There are several aspects to the <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> statement, described under the following topics: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-overview" title="CREATE USER Overview"> CREATE USER Overview </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-authentication" title="CREATE USER Authentication Options"> CREATE USER Authentication Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-multifactor-authentication" title="CREATE USER Multifactor Authentication Options"> CREATE USER Multifactor Authentication Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-role" title="CREATE USER Role Options"> CREATE USER Role Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-tls" title="CREATE USER SSL/TLS Options"> CREATE USER SSL/TLS Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-resource-limits" title="CREATE USER Resource-Limit Options"> CREATE USER Resource-Limit Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-password-management" title="CREATE USER Password-Management Options"> CREATE USER Password-Management Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-comments-attributes" title="CREATE USER Comment and Attribute Options"> CREATE USER Comment and Attribute Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-account-locking" title="CREATE USER Account-Locking Options"> CREATE USER Account-Locking Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="create-user.html#create-user-binary-logging" title="CREATE USER Binary Logging"> CREATE USER Binary Logging </a> </p> </li> </ul> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-overview"> </a> CREATE USER Overview </h5> </div> </div> </div> <p> For each account, <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> creates a new row in the <code class="literal"> mysql.user </code> system table. The account row reflects the properties specified in the statement. Unspecified properties are set to their default values: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Authentication: The default authentication plugin (determined as described in <a class="xref" href="pluggable-authentication.html#pluggable-authentication-default-plugin" title="The Default Authentication Plugin"> The Default Authentication Plugin </a> ), and empty credentials </p> </li> <li class="listitem"> <p> Default role: <code class="literal"> NONE </code> </p> </li> <li class="listitem"> <p> SSL/TLS: <code class="literal"> NONE </code> </p> </li> <li class="listitem"> <p> Resource limits: Unlimited </p> </li> <li class="listitem"> <p> Password management: <code class="literal"> PASSWORD EXPIRE DEFAULT PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT </code> ; failed-login tracking and temporary account locking are disabled </p> </li> <li class="listitem"> <p> Account locking: <code class="literal"> ACCOUNT UNLOCK </code> </p> </li> </ul> </div> <p> An account when first created has no privileges and the default role <code class="literal"> NONE </code> . To assign privileges or roles to this account, use one or more <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement"> <code class="literal"> GRANT </code> </a> statements. </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="sa85234469"><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">'jeffrey'</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></code></pre> </div> <p> The host name part of the account name, if omitted, defaults to <code class="literal"> '%' </code> . You should be aware that, while MySQL 8.4 treats grants made to such a user as though they had been granted to <code class="literal"> ' <em class="replaceable"> <code> user </code> </em> '@'localhost' </code> , this behavior is deprecated, and thus subject to removal in a future version of MySQL. </p> <p> Each <em class="replaceable"> <code> user </code> </em> value naming an account may be followed by an optional <em class="replaceable"> <code> auth_option </code> </em> value that indicates how the account authenticates. These values enable account authentication plugins and credentials (for example, a password) to be specified. Each <em class="replaceable"> <code> auth_option </code> </em> value applies <span class="emphasis"> <em> only </em> </span> to the account named immediately preceding it. </p> <p> Following the <em class="replaceable"> <code> user </code> </em> specifications, the statement may include options for SSL/TLS, resource-limit, password-management, and locking properties. All such options are <span class="emphasis"> <em> global </em> </span> to the statement and apply to <span class="emphasis"> <em> all </em> </span> accounts named in the statement. </p> <p> Example: Create an account that uses the default authentication plugin and the given password. Mark the password expired so that the user must choose a new one at the first connection to the server: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38077291"><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">'jeffrey'</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">new_password</em>'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span><span class="token punctuation">;</span></code></pre> </div> <p> Example: Create an account that uses the <code class="literal"> caching_sha2_password </code> authentication plugin and the given password. Require that a new password be chosen every 180 days, and enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65383782"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> caching_sha2_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">new_password</em>'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">INTERVAL</span> <span class="token number">180</span> <span class="token keyword">DAY</span> <span class="token keyword">FAILED_LOGIN_ATTEMPTS</span> <span class="token number">3</span> <span class="token keyword">PASSWORD_LOCK_TIME</span> <span class="token number">2</span><span class="token punctuation">;</span></code></pre> </div> <p> Example: Create multiple accounts, specifying some per-account properties and some global properties: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60272985"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_native_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">new_password1</em>'</span><span class="token punctuation">,</span> <span class="token string">'jeanne'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> caching_sha2_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">new_password2</em>'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">X509</span> <span class="token keyword">WITH</span> <span class="token keyword">MAX_QUERIES_PER_HOUR</span> <span class="token number">60</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token number">5</span> <span class="token keyword">ACCOUNT</span> <span class="token keyword">LOCK</span><span class="token punctuation">;</span></code></pre> </div> <p> Each <em class="replaceable"> <code> auth_option </code> </em> value ( <code class="literal"> IDENTIFIED WITH ... BY </code> in this case) applies only to the account named immediately preceding it, so each account uses the immediately following authentication plugin and password. </p> <p> The remaining properties apply globally to all accounts named in the statement, so for both accounts: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Connections must be made using a valid X.509 certificate. </p> </li> <li class="listitem"> <p> Up to 60 queries per hour are permitted. </p> </li> <li class="listitem"> <p> Password changes cannot reuse any of the five most recent passwords. </p> </li> <li class="listitem"> <p> The account is locked initially, so effectively it is a placeholder and cannot be used until an administrator unlocks it. </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-authentication"> </a> CREATE USER Authentication Options </h5> </div> </div> </div> <p> An account name may be followed by an <em class="replaceable"> <code> auth_option </code> </em> authentication option that specifies the account authentication plugin, credentials, or both. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> MySQL 8.4 supports multifactor authentication (MFA), such that accounts can have up to three authentication methods. That is, accounts can use two-factor authentication (2FA) or three-factor authentication (3FA). The syntax and semantics of <em class="replaceable"> <code> auth_option </code> </em> remain unchanged, but <em class="replaceable"> <code> auth_option </code> </em> may be followed by specifications for additional authentication methods. This section describes <em class="replaceable"> <code> auth_option </code> </em> . For details about the optional MFA-related following clauses, see <a class="xref" href="create-user.html#create-user-multifactor-authentication" title="CREATE USER Multifactor Authentication Options"> CREATE USER Multifactor Authentication Options </a> . </p> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Clauses for random password generation apply only to accounts that use an authentication plugin that stores credentials internally to MySQL. For accounts that use a plugin that performs authentication against a credentials system that is external to MySQL, password management must be handled externally against that system as well. For more information about internal credentials storage, see <a class="xref" href="password-management.html" title="8.2.15 Password Management"> Section 8.2.15, “Password Management” </a> . </p> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <em class="replaceable"> <code> auth_plugin </code> </em> names an authentication plugin. The plugin name can be a quoted string literal or an unquoted name. Plugin names are stored in the <code class="literal"> plugin </code> column of the <code class="literal"> mysql.user </code> system table. </p> <p> For <em class="replaceable"> <code> auth_option </code> </em> syntax that does not specify an authentication plugin, the server assigns the default plugin, determined as described in <a class="xref" href="pluggable-authentication.html#pluggable-authentication-default-plugin" title="The Default Authentication Plugin"> The Default Authentication Plugin </a> . For descriptions of each plugin, see <a class="xref" href="authentication-plugins.html" title="8.4.1 Authentication Plugins"> Section 8.4.1, “Authentication Plugins” </a> . </p> </li> <li class="listitem"> <p> Credentials that are stored internally are stored in the <code class="literal"> mysql.user </code> system table. An <code class="literal"> ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> value or <code class="literal"> RANDOM PASSWORD </code> specifies account credentials, either as a cleartext (unencrypted) string or hashed in the format expected by the authentication plugin associated with the account, respectively: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> For syntax that uses <code class="literal"> BY ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> , the string is cleartext and is passed to the authentication plugin for possible hashing. The result returned by the plugin is stored in the <code class="literal"> mysql.user </code> table. A plugin may use the value as specified, in which case no hashing occurs. </p> </li> <li class="listitem"> <p> For syntax that uses <code class="literal"> BY RANDOM PASSWORD </code> , MySQL generates a random password and as cleartext and passes it to the authentication plugin for possible hashing. The result returned by the plugin is stored in the <code class="literal"> mysql.user </code> table. A plugin may use the value as specified, in which case no hashing occurs. </p> <p> Randomly generated passwords have the characteristics described in <a class="xref" href="password-management.html#random-password-generation" title="Random Password Generation"> Random Password Generation </a> . </p> </li> <li class="listitem"> <p> For syntax that uses <code class="literal"> AS ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> , the string is assumed to be already in the format the authentication plugin requires, and is stored as is in the <code class="literal"> mysql.user </code> table. If a plugin requires a hashed value, the value must be already hashed in a format appropriate for the plugin; otherwise, the value cannot be used by the plugin and correct authentication of client connections does not occur. </p> <p> A hashed string can be either a string literal or a hexadecimal value. The latter corresponds to the type of value displayed by <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> for password hashes containing unprintable characters when 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 is enabled. </p> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> Although we show <code class="literal"> ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> with quotation marks, a hexadecimal value used for this purpose must <span class="emphasis"> <em> not </em> </span> be quoted. </p> </div> </li> <li class="listitem"> <p> If an authentication plugin performs no hashing of the authentication string, the <code class="literal"> BY ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> and <code class="literal"> AS ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> clauses have the same effect: The authentication string is stored as is in the <code class="literal"> mysql.user </code> system table. </p> </li> </ul> </div> </li> </ul> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> auth_option </code> </em> syntaxes: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> IDENTIFIED BY ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> </p> <p> Sets the account authentication plugin to the default plugin, passes the cleartext <code class="literal"> ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> value to the plugin for possible hashing, and stores the result in the account row in the <code class="literal"> mysql.user </code> system table. </p> </li> <li class="listitem"> <p> <code class="literal"> IDENTIFIED BY RANDOM PASSWORD </code> </p> <p> Sets the account authentication plugin to the default plugin, generates a random password, passes the cleartext password value to the plugin for possible hashing, and stores the result in the account row in the <code class="literal"> mysql.user </code> system table. The statement also returns the cleartext password in a result set to make it available to the user or application executing the statement. For details about the result set and characteristics of randomly generated passwords, see <a class="xref" href="password-management.html#random-password-generation" title="Random Password Generation"> Random Password Generation </a> . </p> </li> <li class="listitem"> <p> <code class="literal"> IDENTIFIED WITH <em class="replaceable"> <code> auth_plugin </code> </em> </code> </p> <p> Sets the account authentication plugin to <em class="replaceable"> <code> auth_plugin </code> </em> , clears the credentials to the empty string, and stores the result in the account row in the <code class="literal"> mysql.user </code> system table. </p> </li> <li class="listitem"> <p> <code class="literal"> IDENTIFIED WITH <em class="replaceable"> <code> auth_plugin </code> </em> BY ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> </p> <p> Sets the account authentication plugin to <em class="replaceable"> <code> auth_plugin </code> </em> , passes the cleartext <code class="literal"> ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> value to the plugin for possible hashing, and stores the result in the account row in the <code class="literal"> mysql.user </code> system table. </p> </li> <li class="listitem"> <p> <code class="literal"> IDENTIFIED WITH <em class="replaceable"> <code> auth_plugin </code> </em> BY RANDOM PASSWORD </code> </p> <p> Sets the account authentication plugin to <em class="replaceable"> <code> auth_plugin </code> </em> , generates a random password, passes the cleartext password value to the plugin for possible hashing, and stores the result in the account row in the <code class="literal"> mysql.user </code> system table. The statement also returns the cleartext password in a result set to make it available to the user or application executing the statement. For details about the result set and characteristics of randomly generated passwords, see <a class="xref" href="password-management.html#random-password-generation" title="Random Password Generation"> Random Password Generation </a> . </p> </li> <li class="listitem"> <p> <code class="literal"> IDENTIFIED WITH <em class="replaceable"> <code> auth_plugin </code> </em> AS ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> </p> <p> Sets the account authentication plugin to <em class="replaceable"> <code> auth_plugin </code> </em> and stores the <code class="literal"> ' <em class="replaceable"> <code> auth_string </code> </em> ' </code> value as is in the <code class="literal"> mysql.user </code> account row. If the plugin requires a hashed string, the string is assumed to be already hashed in the format the plugin requires. </p> </li> </ul> </div> <p> Example: Specify the password as cleartext; the default plugin is used: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa28954059"><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">'jeffrey'</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></code></pre> </div> <p> Example: Specify the authentication plugin, along with a cleartext password value: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22124779"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_native_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">password</em>'</span><span class="token punctuation">;</span></code></pre> </div> <p> In each case, the password value stored in the account row is the cleartext value <code class="literal"> ' <em class="replaceable"> <code> password </code> </em> ' </code> after it has been hashed by the authentication plugin associated with the account. </p> <p> For additional information about setting passwords and authentication plugins, see <a class="xref" href="assigning-passwords.html" title="8.2.14 Assigning Account Passwords"> Section 8.2.14, “Assigning Account Passwords” </a> , and <a class="xref" href="pluggable-authentication.html" title="8.2.17 Pluggable Authentication"> Section 8.2.17, “Pluggable Authentication” </a> . </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-multifactor-authentication"> </a> CREATE USER Multifactor Authentication Options </h5> </div> </div> </div> <p> The <em class="replaceable"> <code> auth_option </code> </em> part of <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> defines an authentication method for one-factor/single-factor authentication (1FA/SFA). <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> also supports multifactor authentication (MFA), such that accounts can have up to three authentication methods. That is, accounts can use two-factor authentication (2FA) or three-factor authentication (3FA). </p> <p> The <a class="link" href="server-system-variables.html#sysvar_authentication_policy"> <code class="literal"> authentication_policy </code> </a> system variable defines constraints for <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> statements with multifactor authentication (MFA) clauses. For example, the <a class="link" href="server-system-variables.html#sysvar_authentication_policy"> <code class="literal"> authentication_policy </code> </a> setting controls the number of authentication factors that accounts may have, and for each factor, which authentication methods are permitted. See <a class="xref" href="multifactor-authentication.html#multifactor-authentication-policy" title="Configuring the Multifactor Authentication Policy"> Configuring the Multifactor Authentication Policy </a> . </p> <p> For information about factor-specific rules that determine the default authentication plugin for authentication clauses that name no plugin, see <a class="xref" href="pluggable-authentication.html#pluggable-authentication-default-plugin" title="The Default Authentication Plugin"> The Default Authentication Plugin </a> . </p> <p> Following <em class="replaceable"> <code> auth_option </code> </em> , there may appear different optional MFA clauses: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <em class="replaceable"> <code> 2fa_auth_option </code> </em> : Specifies a factor 2 authentication method. The following example defines <code class="literal"> caching_sha2_password </code> as the factor 1 authentication method, and <code class="literal"> authentication_ldap_sasl </code> as the factor 2 authentication method. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa6816655"><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">'u1'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> caching_sha2_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">sha2_password</em>'</span> <span class="token operator">AND</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> authentication_ldap_sasl <span class="token keyword">AS</span> <span class="token string">'uid=u1_ldap,ou=People,dc=example,dc=com'</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <em class="replaceable"> <code> 3fa_auth_option </code> </em> : Following <em class="replaceable"> <code> 2fa_auth_option </code> </em> , there may appear a <em class="replaceable"> <code> 3fa_auth_option </code> </em> clause to specify a factor 3 authentication method. The following example defines <code class="literal"> caching_sha2_password </code> as the factor 1 authentication method, <code class="literal"> authentication_ldap_sasl </code> as the factor 2 authentication method, and <code class="literal"> authentication_webauthn </code> as the factor 3 authentication method </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84948551"><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">'u1'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> caching_sha2_password <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">sha2_password</em>'</span> <span class="token operator">AND</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> authentication_ldap_sasl <span class="token keyword">AS</span> <span class="token string">'uid=u1_ldap,ou=People,dc=example,dc=com'</span> <span class="token operator">AND</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> authentication_webauthn<span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <em class="replaceable"> <code> initial_auth_option </code> </em> : Specifies an initial authentication method for configuring FIDO/FIDO2 passwordless authentication. As shown in the following, temporary authentication using either a generated random password or a user-specified <em class="replaceable"> <code> auth-string </code> </em> is required to enable WebAuthn passwordless authentication. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35471304"><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 keyword"><em class="replaceable">user</em></span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> authentication_webauthn INITIAL AUTHENTICATION <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> {<span class="token keyword">RANDOM</span> <span class="token keyword">PASSWORD</span> <span class="token operator">|</span> <span class="token string">'<em class="replaceable">auth_string</em>'</span>}<span class="token punctuation">;</span></code></pre> </div> <p> For information about configuring passwordless authentication using WebAuthn pluggable authentication, See <a class="xref" href="webauthn-pluggable-authentication.html#webauthn-pluggable-authentication-passwordless" title="WebAuthn Passwordless Authentication"> WebAuthn Passwordless Authentication </a> . </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-role"> </a> CREATE USER Role Options </h5> </div> </div> </div> <a class="indexterm" name="idm46045174340704"> </a> <p> The <code class="literal"> DEFAULT ROLE </code> clause 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> 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="sa31295286"><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">'joe'</span>@<span class="token string">'10.0.0.1'</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">ROLE</span> administrator<span class="token punctuation">,</span> developer<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 <code class="literal"> DEFAULT ROLE </code> clause permits a list of one or more comma-separated role names. These roles must exist at the time <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> is executed; otherwise the statement raises an error ( <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_user_does_not_exist" target="_top"> <code class="literal"> ER_USER_DOES_NOT_EXIST </code> </a> ), and the user is not created. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-tls"> </a> CREATE USER SSL/TLS Options </h5> </div> </div> </div> <a class="indexterm" name="idm46045174328368"> </a> <a class="indexterm" name="idm46045174326912"> </a> <a class="indexterm" name="idm46045174325424"> </a> <p> MySQL can check X.509 certificate attributes in addition to the usual authentication that is based on the user name and credentials. For background information on the use of SSL/TLS with MySQL, see <a class="xref" href="encrypted-connections.html" title="8.3 Using Encrypted Connections"> Section 8.3, “Using Encrypted Connections” </a> . </p> <p> To specify SSL/TLS-related options for a MySQL account, use a <code class="literal"> REQUIRE </code> clause that specifies one or more <em class="replaceable"> <code> tls_option </code> </em> values. </p> <p> Order of <code class="literal"> REQUIRE </code> options does not matter, but no option can be specified twice. The <code class="literal"> AND </code> keyword is optional between <code class="literal"> REQUIRE </code> options. </p> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> tls_option </code> </em> values: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> NONE </code> </p> <p> Indicates that all accounts named by the statement have no SSL or X.509 requirements. Unencrypted connections are permitted if the user name and password are valid. Encrypted connections can be used, at the client's option, if the client has the proper certificate and key files. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa52400298"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">NONE</span><span class="token punctuation">;</span></code></pre> </div> <p> Clients attempt to establish a secure connection by default. For clients that have <code class="literal"> REQUIRE NONE </code> , the connection attempt falls back to an unencrypted connection if a secure connection cannot be established. To require an encrypted connection, a client need specify only the <a class="link" href="connection-options.html#option_general_ssl-mode"> <code class="option"> --ssl-mode=REQUIRED </code> </a> option; the connection attempt fails if a secure connection cannot be established. </p> <p> <code class="literal"> NONE </code> is the default if no SSL-related <code class="literal"> REQUIRE </code> options are specified. </p> </li> <li class="listitem"> <p> <code class="literal"> SSL </code> </p> <p> Tells the server to permit only encrypted connections for all accounts named by the statement. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa65846461"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">SSL</span><span class="token punctuation">;</span></code></pre> </div> <p> Clients attempt to establish a secure connection by default. For accounts that have <code class="literal"> REQUIRE SSL </code> , the connection attempt fails if a secure connection cannot be established. </p> </li> <li class="listitem"> <p> <code class="literal"> X509 </code> </p> <p> For all accounts named by the statement, requires that clients present a valid certificate, but the exact certificate, issuer, and subject do not matter. The only requirement is that it should be possible to verify its signature with one of the CA certificates. Use of X.509 certificates always implies encryption, so the <code class="literal"> SSL </code> option is unnecessary in this case. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa9249583"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">X509</span><span class="token punctuation">;</span></code></pre> </div> <p> For accounts with <code class="literal"> REQUIRE X509 </code> , clients must specify the <a class="link" href="connection-options.html#option_general_ssl-key"> <code class="option"> --ssl-key </code> </a> and <a class="link" href="connection-options.html#option_general_ssl-cert"> <code class="option"> --ssl-cert </code> </a> options to connect. (It is recommended but not required that <a class="link" href="connection-options.html#option_general_ssl-ca"> <code class="option"> --ssl-ca </code> </a> also be specified so that the public certificate provided by the server can be verified.) This is true for <code class="literal"> ISSUER </code> and <code class="literal"> SUBJECT </code> as well because those <code class="literal"> REQUIRE </code> options imply the requirements of <code class="literal"> X509 </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> ISSUER ' <em class="replaceable"> <code> issuer </code> </em> ' </code> </p> <p> For all accounts named by the statement, requires that clients present a valid X.509 certificate issued by CA <code class="literal"> ' <em class="replaceable"> <code> issuer </code> </em> ' </code> . If a client presents a certificate that is valid but has a different issuer, the server rejects the connection. Use of X.509 certificates always implies encryption, so the <code class="literal"> SSL </code> option is unnecessary in this case. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51748374"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">ISSUER</span> <span class="token string">'/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL/CN=CA/emailAddress=ca@example.com'</span><span class="token punctuation">;</span></code></pre> </div> <p> Because <code class="literal"> ISSUER </code> implies the requirements of <code class="literal"> X509 </code> , clients must specify the <a class="link" href="connection-options.html#option_general_ssl-key"> <code class="option"> --ssl-key </code> </a> and <a class="link" href="connection-options.html#option_general_ssl-cert"> <code class="option"> --ssl-cert </code> </a> options to connect. (It is recommended but not required that <a class="link" href="connection-options.html#option_general_ssl-ca"> <code class="option"> --ssl-ca </code> </a> also be specified so that the public certificate provided by the server can be verified.) </p> </li> <li class="listitem"> <p> <code class="literal"> SUBJECT ' <em class="replaceable"> <code> subject </code> </em> ' </code> </p> <p> For all accounts named by the statement, requires that clients present a valid X.509 certificate containing the subject <em class="replaceable"> <code> subject </code> </em> . If a client presents a certificate that is valid but has a different subject, the server rejects the connection. Use of X.509 certificates always implies encryption, so the <code class="literal"> SSL </code> option is unnecessary in this case. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25236951"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">SUBJECT</span> <span class="token string">'/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL demo client certificate/ CN=client/emailAddress=client@example.com'</span><span class="token punctuation">;</span></code></pre> </div> <p> MySQL does a simple string comparison of the <code class="literal"> ' <em class="replaceable"> <code> subject </code> </em> ' </code> value to the value in the certificate, so lettercase and component ordering must be given exactly as present in the certificate. </p> <p> Because <code class="literal"> SUBJECT </code> implies the requirements of <code class="literal"> X509 </code> , clients must specify the <a class="link" href="connection-options.html#option_general_ssl-key"> <code class="option"> --ssl-key </code> </a> and <a class="link" href="connection-options.html#option_general_ssl-cert"> <code class="option"> --ssl-cert </code> </a> options to connect. (It is recommended but not required that <a class="link" href="connection-options.html#option_general_ssl-ca"> <code class="option"> --ssl-ca </code> </a> also be specified so that the public certificate provided by the server can be verified.) </p> </li> <li class="listitem"> <p> <code class="literal"> CIPHER ' <em class="replaceable"> <code> cipher </code> </em> ' </code> </p> <p> For all accounts named by the statement, requires a specific cipher method for encrypting connections. This option is needed to ensure that ciphers and key lengths of sufficient strength are used. Encryption can be weak if old algorithms using short encryption keys are used. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16588616"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CIPHER</span> <span class="token string">'EDH-RSA-DES-CBC3-SHA'</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> The <code class="literal"> SUBJECT </code> , <code class="literal"> ISSUER </code> , and <code class="literal"> CIPHER </code> options can be combined in the <code class="literal"> REQUIRE </code> clause: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa23820739"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">SUBJECT</span> <span class="token string">'/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL demo client certificate/ CN=client/emailAddress=client@example.com'</span> <span class="token operator">AND</span> <span class="token keyword">ISSUER</span> <span class="token string">'/C=SE/ST=Stockholm/L=Stockholm/ O=MySQL/CN=CA/emailAddress=ca@example.com'</span> <span class="token operator">AND</span> <span class="token keyword">CIPHER</span> <span class="token string">'EDH-RSA-DES-CBC3-SHA'</span><span class="token punctuation">;</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-resource-limits"> </a> CREATE USER Resource-Limit Options </h5> </div> </div> </div> <a class="indexterm" name="idm46045174260912"> </a> <a class="indexterm" name="idm46045174259424"> </a> <p> It is possible to place limits on use of server resources by an account, as discussed in <a class="xref" href="user-resources.html" title="8.2.21 Setting Account Resource Limits"> Section 8.2.21, “Setting Account Resource Limits” </a> . To do so, use a <code class="literal"> WITH </code> clause that specifies one or more <em class="replaceable"> <code> resource_option </code> </em> values. </p> <p> Order of <code class="literal"> WITH </code> options does not matter, except that if a given resource limit is specified multiple times, the last instance takes precedence. </p> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> resource_option </code> </em> values: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> MAX_QUERIES_PER_HOUR <em class="replaceable"> <code> count </code> </em> </code> , <code class="literal"> MAX_UPDATES_PER_HOUR <em class="replaceable"> <code> count </code> </em> </code> , <code class="literal"> MAX_CONNECTIONS_PER_HOUR <em class="replaceable"> <code> count </code> </em> </code> </p> <p> For all accounts named by the statement, these options restrict how many queries, updates, and connections to the server are permitted to each account during any given one-hour period. If <em class="replaceable"> <code> count </code> </em> is <code class="literal"> 0 </code> (the default), this means that there is no limitation for the account. </p> </li> <li class="listitem"> <p> <code class="literal"> MAX_USER_CONNECTIONS <em class="replaceable"> <code> count </code> </em> </code> </p> <p> For all accounts named by the statement, restricts the maximum number of simultaneous connections to the server by each account. A nonzero <em class="replaceable"> <code> count </code> </em> specifies the limit for the account explicitly. If <em class="replaceable"> <code> count </code> </em> is <code class="literal"> 0 </code> (the default), the server determines the number of simultaneous connections for the account from the global value of the <a class="link" href="server-system-variables.html#sysvar_max_user_connections"> <code class="literal"> max_user_connections </code> </a> system variable. If <a class="link" href="server-system-variables.html#sysvar_max_user_connections"> <code class="literal"> max_user_connections </code> </a> is also zero, there is no limit for the account. </p> </li> </ul> </div> <p> Example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43171150"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">WITH</span> <span class="token keyword">MAX_QUERIES_PER_HOUR</span> <span class="token number">500</span> <span class="token keyword">MAX_UPDATES_PER_HOUR</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-password-management"> </a> CREATE USER Password-Management Options </h5> </div> </div> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> supports several <em class="replaceable"> <code> password_option </code> </em> values for password management: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Password expiration options: You can expire an account password manually and establish its password expiration policy. Policy options do not expire the password. Instead, they determine how the server applies automatic expiration to the account based on password age, which is assessed from the date and time of the most recent account password change. </p> </li> <li class="listitem"> <p> Password reuse options: You can restrict password reuse based on number of password changes, time elapsed, or both. </p> </li> <li class="listitem"> <p> Password verification-required options: You can indicate whether attempts to change an account password must specify the current password, as verification that the user attempting to make the change actually knows the current password. </p> </li> <li class="listitem"> <p> Incorrect-password failed-login tracking options: You can cause the server to track failed login attempts and temporarily lock accounts for which too many consecutive incorrect passwords are given. The required number of failures and the lock time are configurable. </p> </li> </ul> </div> <p> This section describes the syntax for password-management options. For information about establishing policy for password management, see <a class="xref" href="password-management.html" title="8.2.15 Password Management"> Section 8.2.15, “Password Management” </a> . </p> <p> If multiple password-management options of a given type are specified, the last one takes precedence. For example, <code class="literal"> PASSWORD EXPIRE DEFAULT PASSWORD EXPIRE NEVER </code> is the same as <code class="literal"> PASSWORD EXPIRE NEVER </code> . </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Except for the options that pertain to failed-login tracking, password-management options apply only to accounts that use an authentication plugin that stores credentials internally to MySQL. For accounts that use a plugin that performs authentication against a credentials system that is external to MySQL, password management must be handled externally against that system as well. For more information about internal credentials storage, see <a class="xref" href="password-management.html" title="8.2.15 Password Management"> Section 8.2.15, “Password Management” </a> . </p> </div> <p> A client has an expired password if the account password was expired manually or the password age is considered greater than its permitted lifetime per the automatic expiration policy. In this case, the server either disconnects the client or restricts the operations permitted to it (see <a class="xref" href="expired-password-handling.html" title="8.2.16 Server Handling of Expired Passwords"> Section 8.2.16, “Server Handling of Expired Passwords” </a> ). Operations performed by a restricted client result in an error until the user establishes a new account password. </p> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> password_option </code> </em> values for controlling password expiration: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> PASSWORD EXPIRE </code> </p> <p> Immediately marks the password expired for all accounts named by the statement. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa9911708"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD EXPIRE DEFAULT </code> </p> <p> Sets all accounts named by the statement so that the global expiration policy applies, as specified by the <a class="link" href="server-system-variables.html#sysvar_default_password_lifetime"> <code class="literal"> default_password_lifetime </code> </a> system variable. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa34981790"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD EXPIRE NEVER </code> </p> <p> This expiration option overrides the global policy for all accounts named by the statement. For each, it disables password expiration so that the password never expires. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa24923100"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">NEVER</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD EXPIRE INTERVAL <em class="replaceable"> <code> N </code> </em> DAY </code> </p> <p> This expiration option overrides the global policy for all accounts named by the statement. For each, it sets the password lifetime to <em class="replaceable"> <code> N </code> </em> days. The following statement requires the password to be changed every 180 days: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa37135344"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">EXPIRE</span> <span class="token keyword">INTERVAL</span> <span class="token number">180</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> password_option </code> </em> values for controlling reuse of previous passwords based on required minimum number of password changes: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> PASSWORD HISTORY DEFAULT </code> </p> <p> Sets all accounts named by the statement so that the global policy about password history length applies, to prohibit reuse of passwords before the number of changes specified by the <a class="link" href="server-system-variables.html#sysvar_password_history"> <code class="literal"> password_history </code> </a> system variable. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa25053515"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD HISTORY <em class="replaceable"> <code> N </code> </em> </code> </p> <p> This history-length option overrides the global policy for all accounts named by the statement. For each, it sets the password history length to <em class="replaceable"> <code> N </code> </em> passwords, to prohibit reusing any of the <em class="replaceable"> <code> N </code> </em> most recently chosen passwords. The following statement prohibits reuse of any of the previous 6 passwords: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa41220754"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">HISTORY</span> <span class="token number">6</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> password_option </code> </em> values for controlling reuse of previous passwords based on time elapsed: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> PASSWORD REUSE INTERVAL DEFAULT </code> </p> <p> Sets all statements named by the account so that the global policy about time elapsed applies, to prohibit reuse of passwords newer than the number of days specified by the <a class="link" href="server-system-variables.html#sysvar_password_reuse_interval"> <code class="literal"> password_reuse_interval </code> </a> system variable. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa92596386"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD REUSE INTERVAL <em class="replaceable"> <code> N </code> </em> DAY </code> </p> <p> This time-elapsed option overrides the global policy for all accounts named by the statement. For each, it sets the password reuse interval to <em class="replaceable"> <code> N </code> </em> days, to prohibit reuse of passwords newer than that many days. The following statement prohibits password reuse for 360 days: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa47044444"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REUSE</span> <span class="token keyword">INTERVAL</span> <span class="token number">360</span> <span class="token keyword">DAY</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> password_option </code> </em> values for controlling whether attempts to change an account password must specify the current password, as verification that the user attempting to make the change actually knows the current password: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> PASSWORD REQUIRE CURRENT </code> </p> <p> This verification option overrides the global policy for all accounts named by the statement. For each, it requires that password changes specify the current password. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa34842966"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD REQUIRE CURRENT OPTIONAL </code> </p> <p> This verification option overrides the global policy for all accounts named by the statement. For each, it does not require that password changes specify the current password. (The current password may but need not be given.) </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa35095018"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token keyword">OPTIONAL</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD REQUIRE CURRENT DEFAULT </code> </p> <p> Sets all statements named by the account so that the global policy about password verification applies, as specified by the <a class="link" href="server-system-variables.html#sysvar_password_require_current"> <code class="literal"> password_require_current </code> </a> system variable. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa44415253"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">PASSWORD</span> <span class="token keyword">REQUIRE</span> <span class="token keyword">CURRENT</span> <span class="token keyword">DEFAULT</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> permits these <em class="replaceable"> <code> password_option </code> </em> values for controlling failed-login tracking: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> FAILED_LOGIN_ATTEMPTS <em class="replaceable"> <code> N </code> </em> </code> </p> <p> Whether to track account login attempts that specify an incorrect password. <em class="replaceable"> <code> N </code> </em> must be a number from 0 to 32767. A value of 0 disables failed-login tracking. Values greater than 0 indicate how many consecutive password failures cause temporary account locking (if <code class="literal"> PASSWORD_LOCK_TIME </code> is also nonzero). </p> </li> <li class="listitem"> <p> <code class="literal"> PASSWORD_LOCK_TIME { <em class="replaceable"> <code> N </code> </em> | UNBOUNDED} </code> </p> <p> How long to lock the account after too many consecutive login attempts provide an incorrect password. <em class="replaceable"> <code> N </code> </em> must be a number from 0 to 32767, or <code class="literal"> UNBOUNDED </code> . A value of 0 disables temporary account locking. Values greater than 0 indicate how long to lock the account in days. A value of <code class="literal"> UNBOUNDED </code> causes the account locking duration to be unbounded; once locked, the account remains in a locked state until unlocked. For information about the conditions under which unlocking occurs, see <a class="xref" href="password-management.html#failed-login-tracking" title="Failed-Login Tracking and Temporary Account Locking"> Failed-Login Tracking and Temporary Account Locking </a> . </p> </li> </ul> </div> <p> For failed-login tracking and temporary locking to occur, an account's <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> and <code class="literal"> PASSWORD_LOCK_TIME </code> options both must be nonzero. The following statement creates an account that remains locked for two days after four consecutive password failures: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa76009571"><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">'jeffrey'</span>@<span class="token string">'localhost'</span> <span class="token keyword">FAILED_LOGIN_ATTEMPTS</span> <span class="token number">4</span> <span class="token keyword">PASSWORD_LOCK_TIME</span> <span class="token number">2</span><span class="token punctuation">;</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-comments-attributes"> </a> CREATE USER Comment and Attribute Options </h5> </div> </div> </div> <a class="indexterm" name="idm46045174154720"> </a> <a class="indexterm" name="idm46045174153232"> </a> <p> You can also include an optional comment or attribute when creating a user, as described here: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <span class="bold"> <strong> User comment </strong> </span> </p> <p> To set a user comment, add <code class="literal"> COMMENT ' <em class="replaceable"> <code> user_comment </code> </em> ' </code> to the <code class="literal"> CREATE USER </code> statement, where <em class="replaceable"> <code> user_comment </code> </em> is the text of the user comment. </p> <p> Example (omitting any other options): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa47931729"><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">'jon'</span>@<span class="token string">'localhost'</span> <span class="token keyword">COMMENT</span> <span class="token string">'Some information about Jon'</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <span class="bold"> <strong> User attribute </strong> </span> </p> <p> A user attribute is a JSON object made up of one or more key-value pairs, and is set by including <code class="literal"> ATTRIBUTE ' <em class="replaceable"> <code> json_object </code> </em> ' </code> as part of <code class="literal"> CREATE USER </code> . <em class="replaceable"> <code> json_object </code> </em> must be a valid JSON object. </p> <p> Example (omitting any other options): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40889631"><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">'jim'</span>@<span class="token string">'localhost'</span> <span class="token keyword">ATTRIBUTE</span> <span class="token string">'{"fname": "James", "lname": "Scott", "phone": "123-456-7890"}'</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> User comments and user attributes are stored together in the <code class="literal"> ATTRIBUTE </code> column of the Information Schema <a class="link" href="information-schema-user-attributes-table.html" title="28.3.45 The INFORMATION_SCHEMA USER_ATTRIBUTES Table"> <code class="literal"> USER_ATTRIBUTES </code> </a> table. This query displays the row in this table inserted by the statement just shown for creating the user <code class="literal"> jim@localhost </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69297191"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>USER_ATTRIBUTES <span class="token prompt"> -&gt;</span> <span class="token keyword">WHERE</span> <span class="token keyword">USER</span> <span class="token operator">=</span> <span class="token string">'jim'</span> <span class="token operator">AND</span> <span class="token keyword">HOST</span> <span class="token operator">=</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> USER<span class="token punctuation">:</span> jim HOST<span class="token punctuation">:</span> localhost ATTRIBUTE<span class="token punctuation">:</span> {"fname"<span class="token punctuation">:</span> "James", "lname"<span class="token punctuation">:</span> "Scott", "phone"<span class="token punctuation">:</span> "123-456-7890"} </span><span class="token output">1 row in set (0.00 sec)</span></code></pre> </div> <p> The <code class="literal"> COMMENT </code> option in actuality provides a shortcut for setting a user attribute whose only element has <code class="literal"> comment </code> as its key and whose value is the argument supplied for the option. You can see this by executing the statement <code class="literal"> CREATE USER 'jon'@'localhost' COMMENT 'Some information about Jon' </code> , and observing the row which it inserts into the <a class="link" href="information-schema-user-attributes-table.html" title="28.3.45 The INFORMATION_SCHEMA USER_ATTRIBUTES Table"> <code class="literal"> USER_ATTRIBUTES </code> </a> table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44230922"><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">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'jon'</span>@<span class="token string">'localhost'</span> <span class="token keyword">COMMENT</span> <span class="token string">'Some information about Jon'</span><span class="token punctuation">;</span> <span class="token output">Query OK, 0 rows affected (0.06 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>USER_ATTRIBUTES <span class="token prompt"> -&gt;</span> <span class="token keyword">WHERE</span> <span class="token keyword">USER</span> <span class="token operator">=</span> <span class="token string">'jon'</span> <span class="token operator">AND</span> <span class="token keyword">HOST</span> <span class="token operator">=</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> USER <span class="token punctuation">|</span> HOST <span class="token punctuation">|</span> ATTRIBUTE <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> jon <span class="token punctuation">|</span> localhost <span class="token punctuation">|</span> {"comment": "Some information about Jon"} <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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">1 row in set (0.00 sec)</span></code></pre> </div> <p> You cannot use <code class="literal"> COMMENT </code> and <code class="literal"> ATTRIBUTE </code> together in the same <code class="literal"> CREATE USER </code> statement; attempting to do so causes a syntax error. To set a user comment concurrently with setting a user attribute, use <code class="literal"> ATTRIBUTE </code> and include in its argument a value with a <code class="literal"> comment </code> key, like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24248100"><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">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'bill'</span>@<span class="token string">'localhost'</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">ATTRIBUTE</span> <span class="token string">'{"fname":"William", "lname":"Schmidt", -&gt; "comment":"Website developer"}'</span><span class="token punctuation">;</span> <span class="token output">Query OK, 0 rows affected (0.16 sec)</span></code></pre> </div> <p> Since the content of the <code class="literal"> ATTRIBUTE </code> row is a JSON object, you can employ any appropriate MySQL JSON functions or operators to manipulate it, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89391717"><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">SELECT</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">USER</span> <span class="token keyword">AS</span> <span class="token keyword">User</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">HOST</span> <span class="token keyword">AS</span> <span class="token keyword">Host</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token function">CONCAT</span><span class="token punctuation">(</span><span class="token keyword">ATTRIBUTE</span><span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.fname"</span><span class="token punctuation">,</span><span class="token string">" "</span><span class="token punctuation">,</span><span class="token keyword">ATTRIBUTE</span><span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.lname"</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'Full Name'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">ATTRIBUTE</span><span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.comment"</span> <span class="token keyword">AS</span> <span class="token keyword">Comment</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>USER_ATTRIBUTES <span class="token prompt"> -&gt;</span> <span class="token keyword">WHERE</span> <span class="token keyword">USER</span><span class="token operator">=</span><span class="token string">'bill'</span> <span class="token operator">AND</span> <span class="token keyword">HOST</span><span class="token operator">=</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span> <span class="token output"><span class="token punctuation">|</span> User <span class="token punctuation">|</span> Host <span class="token punctuation">|</span> Full Name <span class="token punctuation">|</span> Comment <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span> <span class="token output"><span class="token punctuation">|</span> bill <span class="token punctuation">|</span> localhost <span class="token punctuation">|</span> William Schmidt <span class="token punctuation">|</span> Website developer <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span> <span class="token output">1 row in set (0.00 sec)</span></code></pre> </div> <p> To set or to make changes in the user comment or user attribute for an existing user, you can use a <code class="literal"> COMMENT </code> or <code class="literal"> ATTRIBUTE </code> option with an <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement"> <code class="literal"> ALTER USER </code> </a> statement. </p> <p> Because the user comment and user attribute are stored together internally in a single <a class="link" href="json.html" title="13.5 The JSON Data Type"> <code class="literal"> JSON </code> </a> column, this sets an upper limit on their maximum combined size; see <a class="xref" href="storage-requirements.html#data-types-storage-reqs-json" title="JSON Storage Requirements"> JSON Storage Requirements </a> , for more information. </p> <p> See also the description of the Information Schema <a class="link" href="information-schema-user-attributes-table.html" title="28.3.45 The INFORMATION_SCHEMA USER_ATTRIBUTES Table"> <code class="literal"> USER_ATTRIBUTES </code> </a> table for more information and examples. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-account-locking"> </a> CREATE USER Account-Locking Options </h5> </div> </div> </div> <a class="indexterm" name="idm46045174103360"> </a> <p> MySQL supports account locking and unlocking using the <code class="literal"> ACCOUNT LOCK </code> and <code class="literal"> ACCOUNT UNLOCK </code> options, which specify the locking state for an account. For additional discussion, see <a class="xref" href="account-locking.html" title="8.2.20 Account Locking"> Section 8.2.20, “Account Locking” </a> . </p> <p> If multiple account-locking options are specified, the last one takes precedence. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="create-user-binary-logging"> </a> CREATE USER Binary Logging </h5> </div> </div> </div> <a class="indexterm" name="idm46045174097376"> </a> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> 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 users. If the <code class="literal"> IF NOT EXISTS </code> clause is given, this includes even users that already exist and were not created. </p> <p> The statement written to the binary log specifies an authentication plugin for each user, determined as follows: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The plugin named in the original statement, if one was specified. </p> </li> <li class="listitem"> <p> Otherwise, the default authentication plugin. In particular, if a user <code class="literal"> u1 </code> already exists and uses a nondefault authentication plugin, the statement written to the binary log for <code class="literal"> CREATE USER IF NOT EXISTS u1 </code> names the default authentication plugin. (If the statement written to the binary log must specify a nondefault authentication plugin for a user, include it in the original statement.) </p> </li> </ul> </div> <p> If the server adds the default authentication plugin for any nonexisting users in the statement written to the binary log, it writes a warning to the error log naming those users. </p> <p> If the original statement specifies the <code class="literal"> FAILED_LOGIN_ATTEMPTS </code> or <code class="literal"> PASSWORD_LOCK_TIME </code> option, the statement written to the binary log includes the option. </p> <p> <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement"> <code class="literal"> CREATE USER </code> </a> statements with clauses that support multifactor authentication (MFA) are written to the binary log. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> CREATE USER ... IDENTIFIED WITH .. INITIAL AUTHENTICATION IDENTIFIED WITH ... </code> statements are written to the binary log as <code class="literal"> CREATE USER .. IDENTIFIED WITH .. INITIAL AUTHENTICATION IDENTIFIED WITH .. AS ' <em class="replaceable"> <code> password-hash </code> </em> ' </code> , where the <em class="replaceable"> <code> password-hash </code> </em> is the user-specified <em class="replaceable"> <code> auth-string </code> </em> or the random password generated by server when the <code class="literal"> RANDOM PASSWORD </code> clause is specified. </p> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/file-permissions.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="file-permissions"> </a> B.3.3.1 Problems with File Permissions </h4> </div> </div> </div> <a class="indexterm" name="idm46045054131008"> </a> <a class="indexterm" name="idm46045054129552"> </a> <a class="indexterm" name="idm46045054128064"> </a> <a class="indexterm" name="idm46045054126576"> </a> <a class="indexterm" name="idm46045054125488"> </a> <p> If you have problems with file permissions, the <code class="literal"> UMASK </code> or <code class="literal"> UMASK_DIR </code> environment variable might be set incorrectly when <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> starts. For example, <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> might issue the following error message when you create a table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa5454200"><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-none">ERROR: Can't find file: 'path/with/<em class="replaceable">file_name</em>' (Errcode: 13)</code></pre> </div> <p> The default <code class="literal"> UMASK </code> and <code class="literal"> UMASK_DIR </code> values are <code class="literal"> 0640 </code> and <code class="literal"> 0750 </code> , respectively. <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> assumes that the value for <code class="literal"> UMASK </code> or <code class="literal"> UMASK_DIR </code> is in octal if it starts with a zero. For example, setting <code class="literal"> UMASK=0600 </code> is equivalent to <code class="literal"> UMASK=384 </code> because 0600 octal is 384 decimal. </p> <p> Assuming that you start <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> using <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script"> <span class="command"> <strong> mysqld_safe </strong> </span> </a> , change the default <code class="literal"> UMASK </code> value as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa58372211"><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">UMASK<span class="token attr-value"><span class="token punctuation">=</span>384</span> <span class="token comment" spellcheck="true"># = 600 in octal</span> export UMASK mysqld_safe &amp;</code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> An exception applies for the error log file if you start <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> using <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script"> <span class="command"> <strong> mysqld_safe </strong> </span> </a> , which does not respect <code class="literal"> UMASK </code> : <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script"> <span class="command"> <strong> mysqld_safe </strong> </span> </a> may create the error log file if it does not exist prior to starting <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> , and <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script"> <span class="command"> <strong> mysqld_safe </strong> </span> </a> uses a umask set to a strict value of <code class="literal"> 0137 </code> . If this is unsuitable, create the error file manually with the desired access mode prior to executing <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script"> <span class="command"> <strong> mysqld_safe </strong> </span> </a> . </p> </div> <a class="indexterm" name="idm46045054095904"> </a> <a class="indexterm" name="idm46045054094816"> </a> <p> By default, <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> creates database directories with an access permission value of <code class="literal"> 0750 </code> . To modify this behavior, set the <code class="literal"> UMASK_DIR </code> variable. If you set its value, new directories are created with the combined <code class="literal"> UMASK </code> and <code class="literal"> UMASK_DIR </code> values. For example, to give group access to all new directories, start <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script"> <span class="command"> <strong> mysqld_safe </strong> </span> </a> as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa64823857"><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">UMASK_DIR<span class="token attr-value"><span class="token punctuation">=</span>504</span> <span class="token comment" spellcheck="true"># = 770 in octal</span> export UMASK_DIR mysqld_safe &amp;</code></pre> </div> <p> For additional details, see <a class="xref" href="environment-variables.html" title="6.9 Environment Variables"> Section 6.9, “Environment Variables” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/commands-out-of-sync.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="commands-out-of-sync"> </a> B.3.2.12 Commands out of sync </h4> </div> </div> </div> <a class="indexterm" name="idm46045054234720"> </a> <p> If you get <code class="literal"> Commands out of sync; you can't run this command now </code> in your client code, you are calling client functions in the wrong order. </p> <p> This can happen, for example, if you are using <a class="ulink" href="/doc/c-api/8.4/en/mysql-use-result.html" target="_top"> <code class="literal"> mysql_use_result() </code> </a> and try to execute a new query before you have called <a class="ulink" href="/doc/c-api/8.4/en/mysql-free-result.html" target="_top"> <code class="literal"> mysql_free_result() </code> </a> . It can also happen if you try to execute two queries that return data without calling <a class="ulink" href="/doc/c-api/8.4/en/mysql-use-result.html" target="_top"> <code class="literal"> mysql_use_result() </code> </a> or <a class="ulink" href="/doc/c-api/8.4/en/mysql-store-result.html" target="_top"> <code class="literal"> mysql_store_result() </code> </a> in between. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-rbr-safe-unsafe.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-rbr-safe-unsafe"> </a> 19.2.1.3 Determination of Safe and Unsafe Statements in Binary Logging </h4> </div> </div> </div> <a class="indexterm" name="idm46045138307408"> </a> <a class="indexterm" name="idm46045138305952"> </a> <a class="indexterm" name="idm46045138304448"> </a> <p> The <span class="quote"> “ <span class="quote"> safeness </span> ” </span> of a statement in MySQL replication refers to whether the statement and its effects can be replicated correctly using statement-based format. If this is true of the statement, we refer to the statement as <span class="firstterm"> safe </span> ; otherwise, we refer to it as <span class="firstterm"> unsafe </span> . </p> <p> In general, a statement is safe if it deterministic, and unsafe if it is not. However, certain nondeterministic functions are <span class="emphasis"> <em> not </em> </span> considered unsafe (see <a class="xref" href="replication-rbr-safe-unsafe.html#replication-rbr-safe-unsafe-not" title="Nondeterministic functions not considered unsafe"> Nondeterministic functions not considered unsafe </a> , later in this section). In addition, statements using results from floating-point math functions—which are hardware-dependent—are always considered unsafe (see <a class="xref" href="replication-features-floatvalues.html" title="19.5.1.12 Replication and Floating-Point Values"> Section 19.5.1.12, “Replication and Floating-Point Values” </a> ). </p> <p> <b> Handling of safe and unsafe statements. </b> A statement is treated differently depending on whether the statement is considered safe, and with respect to the binary logging format (that is, the current value of <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> ). </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> When using row-based logging, no distinction is made in the treatment of safe and unsafe statements. </p> </li> <li class="listitem"> <p> When using mixed-format logging, statements flagged as unsafe are logged using the row-based format; statements regarded as safe are logged using the statement-based format. </p> </li> <li class="listitem"> <p> When using statement-based logging, statements flagged as being unsafe generate a warning to this effect. Safe statements are logged normally. </p> </li> </ul> </div> <p> Each statement flagged as unsafe generates a warning. If a large number of such statements were executed on the source, this could lead to excessively large error log files. To prevent this, MySQL has a warning suppression mechanism. Whenever the 50 most recent <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_binlog_unsafe_statement" target="_top"> <code class="literal"> ER_BINLOG_UNSAFE_STATEMENT </code> </a> warnings have been generated more than 50 times in any 50-second period, warning suppression is enabled. When activated, this causes such warnings not to be written to the error log; instead, for each 50 warnings of this type, a note <code class="literal"> The last warning was repeated <em class="replaceable"> <code> N </code> </em> times in last <em class="replaceable"> <code> S </code> </em> seconds </code> is written to the error log. This continues as long as the 50 most recent such warnings were issued in 50 seconds or less; once the rate has decreased below this threshold, the warnings are once again logged normally. Warning suppression has no effect on how the safety of statements for statement-based logging is determined, nor on how warnings are sent to the client. MySQL clients still receive one warning for each such statement. </p> <p> For more information, see <a class="xref" href="replication-formats.html" title="19.2.1 Replication Formats"> Section 19.2.1, “Replication Formats” </a> . </p> <p> <b> Statements considered unsafe. </b> <a class="indexterm" name="idm46045138284880"> </a> Statements with the following characteristics are considered unsafe: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <b> Statements containing system functions that may return a different value on the replica. </b> These functions include <a class="link" href="information-functions.html#function_found-rows"> <code class="literal"> FOUND_ROWS() </code> </a> , <a class="link" href="locking-functions.html#function_get-lock"> <code class="literal"> GET_LOCK() </code> </a> , <a class="link" href="locking-functions.html#function_is-free-lock"> <code class="literal"> IS_FREE_LOCK() </code> </a> , <a class="link" href="locking-functions.html#function_is-used-lock"> <code class="literal"> IS_USED_LOCK() </code> </a> , <a class="link" href="string-functions.html#function_load-file"> <code class="literal"> LOAD_FILE() </code> </a> , <a class="link" href="mathematical-functions.html#function_rand"> <code class="literal"> RAND() </code> </a> , <a class="link" href="locking-functions.html#function_release-lock"> <code class="literal"> RELEASE_LOCK() </code> </a> , <a class="link" href="information-functions.html#function_row-count"> <code class="literal"> ROW_COUNT() </code> </a> , <a class="link" href="information-functions.html#function_session-user"> <code class="literal"> SESSION_USER() </code> </a> , <a class="link" href="miscellaneous-functions.html#function_sleep"> <code class="literal"> SLEEP() </code> </a> , <a class="link" href="replication-functions-synchronization.html#function_source-pos-wait"> <code class="literal"> SOURCE_POS_WAIT() </code> </a> , <a class="link" href="date-and-time-functions.html#function_sysdate"> <code class="literal"> SYSDATE() </code> </a> , <a class="link" href="information-functions.html#function_system-user"> <code class="literal"> SYSTEM_USER() </code> </a> , <a class="link" href="information-functions.html#function_user"> <code class="literal"> USER() </code> </a> , <a class="link" href="miscellaneous-functions.html#function_uuid"> <code class="literal"> UUID() </code> </a> , and <a class="link" href="miscellaneous-functions.html#function_uuid-short"> <code class="literal"> UUID_SHORT() </code> </a> . </p> <p> <a name="replication-rbr-safe-unsafe-not"> </a> <b> Nondeterministic functions not considered unsafe. </b> Although these functions are not deterministic, they are treated as safe for purposes of logging and replication: <a class="link" href="information-functions.html#function_connection-id"> <code class="literal"> CONNECTION_ID() </code> </a> , <a class="link" href="date-and-time-functions.html#function_curdate"> <code class="literal"> CURDATE() </code> </a> , <a class="link" href="date-and-time-functions.html#function_current-date"> <code class="literal"> CURRENT_DATE() </code> </a> , <a class="link" href="date-and-time-functions.html#function_current-time"> <code class="literal"> CURRENT_TIME() </code> </a> , <a class="link" href="date-and-time-functions.html#function_current-timestamp"> <code class="literal"> CURRENT_TIMESTAMP() </code> </a> , <a class="link" href="date-and-time-functions.html#function_curtime"> <code class="literal"> CURTIME() </code> </a> , <a class="link" href="information-functions.html#function_last-insert-id"> <code class="literal"> LAST_INSERT_ID() </code> </a> , <a class="link" href="date-and-time-functions.html#function_localtime"> <code class="literal"> LOCALTIME() </code> </a> , <a class="link" href="date-and-time-functions.html#function_localtimestamp"> <code class="literal"> LOCALTIMESTAMP() </code> </a> , <a class="link" href="date-and-time-functions.html#function_now"> <code class="literal"> NOW() </code> </a> , <a class="link" href="date-and-time-functions.html#function_unix-timestamp"> <code class="literal"> UNIX_TIMESTAMP() </code> </a> , <a class="link" href="date-and-time-functions.html#function_utc-date"> <code class="literal"> UTC_DATE() </code> </a> , <a class="link" href="date-and-time-functions.html#function_utc-time"> <code class="literal"> UTC_TIME() </code> </a> , and <a class="link" href="date-and-time-functions.html#function_utc-timestamp"> <code class="literal"> UTC_TIMESTAMP() </code> </a> . </p> <p> For more information, see <a class="xref" href="replication-features-functions.html" title="19.5.1.14 Replication and System Functions"> Section 19.5.1.14, “Replication and System Functions” </a> . </p> </li> <li class="listitem"> <p> <b> References to system variables. </b> Most system variables are not replicated correctly using the statement-based format. See <a class="xref" href="replication-features-variables.html" title="19.5.1.39 Replication and Variables"> Section 19.5.1.39, “Replication and Variables” </a> . For exceptions, see <a class="xref" href="binary-log-mixed.html" title="7.4.4.3 Mixed Binary Logging Format"> Section 7.4.4.3, “Mixed Binary Logging Format” </a> . </p> </li> <li class="listitem"> <p> <b> Loadable Functions. </b> Since we have no control over what a loadable function does, we must assume that it is executing unsafe statements. </p> </li> <li class="listitem"> <p> <b> Fulltext plugin. </b> This plugin may behave differently on different MySQL servers; therefore, statements depending on it could have different results. For this reason, all statements relying on the fulltext plugin are treated as unsafe in MySQL. </p> </li> <li class="listitem"> <p> <b> Trigger or stored program updates a table having an AUTO_INCREMENT column. </b> This is unsafe because the order in which the rows are updated may differ on the source and the replica. </p> <p> In addition, an <a class="link" href="insert.html" title="15.2.7 INSERT Statement"> <code class="literal"> INSERT </code> </a> into a table that has a composite primary key containing an <code class="literal"> AUTO_INCREMENT </code> column that is not the first column of this composite key is unsafe. </p> <p> For more information, see <a class="xref" href="replication-features-auto-increment.html" title="19.5.1.1 Replication and AUTO_INCREMENT"> Section 19.5.1.1, “Replication and AUTO_INCREMENT” </a> . </p> </li> <li class="listitem"> <p> <b> INSERT ... ON DUPLICATE KEY UPDATE statements on tables with multiple primary or unique keys. </b> When executed against a table that contains more than one primary or unique key, this statement is considered unsafe, being sensitive to the order in which the storage engine checks the keys, which is not deterministic, and on which the choice of rows updated by the MySQL Server depends. </p> <p> An <a class="link" href="insert-on-duplicate.html" title="15.2.7.2 INSERT ... ON DUPLICATE KEY UPDATE Statement"> <code class="literal"> INSERT ... ON DUPLICATE KEY UPDATE </code> </a> statement against a table having more than one unique or primary key is marked as unsafe for statement-based replication. (Bug #11765650, Bug #58637) </p> </li> <li class="listitem"> <p> <b> Updates using LIMIT. </b> The order in which rows are retrieved is not specified, and is therefore considered unsafe. See <a class="xref" href="replication-features-limit.html" title="19.5.1.18 Replication and LIMIT"> Section 19.5.1.18, “Replication and LIMIT” </a> . </p> </li> <li class="listitem"> <p> <b> Accesses or references log tables. </b> The contents of the system log table may differ between source and replica. </p> </li> <li class="listitem"> <p> <b> Nontransactional operations after transactional operations. </b> Within a transaction, allowing any nontransactional reads or writes to execute after any transactional reads or writes is considered unsafe. </p> <p> For more information, see <a class="xref" href="replication-features-transactions.html" title="19.5.1.35 Replication and Transactions"> Section 19.5.1.35, “Replication and Transactions” </a> . </p> </li> <li class="listitem"> <p> <b> Accesses or references self-logging tables. </b> All reads and writes to self-logging tables are considered unsafe. Within a transaction, any statement following a read or write to self-logging tables is also considered unsafe. </p> </li> <li class="listitem"> <p> <b> LOAD DATA statements. </b> <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> is treated as unsafe and when <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=MIXED </code> </a> the statement is logged in row-based format. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=STATEMENT </code> </a> <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement"> <code class="literal"> LOAD DATA </code> </a> does not generate a warning, unlike other unsafe statements. </p> </li> <li class="listitem"> <p> <b> XA transactions. </b> If two XA transactions committed in parallel on the source are being prepared on the replica in the inverse order, locking dependencies can occur with statement-based replication that cannot be safely resolved, and it is possible for replication to fail with deadlock on the replica. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=STATEMENT </code> </a> is set, DML statements inside XA transactions are flagged as being unsafe and generate a warning. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=MIXED </code> </a> or <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format=ROW </code> </a> is set, DML statements inside XA transactions are logged using row-based replication, and the potential issue is not present. </p> </li> <li class="listitem"> <p> <b> <code class="literal"> DEFAULT </code> clause that refers to a nondeterministic function. </b> If an expression default value refers to a nondeterministic function, any statement that causes the expression to be evaluated is unsafe for statement-based replication. This includes 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> , and <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> . Unlike most other unsafe statements, this category of statement cannot be replicated safely in row-based format. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is set to <code class="literal"> STATEMENT </code> , the statement is logged and executed but a warning message is written to the error log. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is set to <code class="literal"> MIXED </code> or <code class="literal"> ROW </code> , the statement is not executed and an error message is written to the error log. For more information on the handling of explicit defaults, see <a class="xref" href="data-type-defaults.html#data-type-defaults-explicit" title="Explicit Default Handling"> Explicit Default Handling </a> . </p> </li> </ul> </div> <p> For additional information, see <a class="xref" href="replication-features.html" title="19.5.1 Replication Features and Issues"> Section 19.5.1, “Replication Features and Issues” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/data-masking-components.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="data-masking-components"> </a> 8.5.2 MySQL Enterprise Data Masking and De-Identification Components </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="data-masking-components-installation.html"> 8.5.2.1 MySQL Enterprise Data Masking and De-Identification Component Installation </a> </span> </dt> <dt> <span class="section"> <a href="data-masking-component-usage.html"> 8.5.2.2 Using MySQL Enterprise Data Masking and De-Identification Components </a> </span> </dt> <dt> <span class="section"> <a href="data-masking-component-function-reference.html"> 8.5.2.3 MySQL Enterprise Data Masking and De-Identification Component Function Reference </a> </span> </dt> <dt> <span class="section"> <a href="data-masking-component-functions.html"> 8.5.2.4 MySQL Enterprise Data Masking and De-Identification Component Function Descriptions </a> </span> </dt> <dt> <span class="section"> <a href="data-masking-component-variables.html"> 8.5.2.5 MySQL Enterprise Data Masking and De-Identification Component Variables </a> </span> </dt> </dl> </div> <p> MySQL Enterprise Data Masking and De-Identification implements these elements: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A table for persistent storage of dictionaries and terms. </p> </li> <li class="listitem"> <p> A component named <code class="literal"> component_masking </code> that implements masking functionality and exposes it as service interface for developers. </p> <p> Developers who wish to incorporate the same service functions used by <code class="literal"> component_masking </code> should consult the <code class="filename"> internal\components\masking\component_masking.h </code> file in a MySQL source distribution or https://dev.mysql.com/doc/dev/mysql-server/latest. </p> </li> <li class="listitem"> <p> A component named <code class="literal"> component_masking_functions </code> that provides loadable functions. </p> <p> The set of loadable functions enables an SQL-level API for performing masking and de-identification operations. Some of the functions require the <a class="link" href="privileges-provided.html#priv_masking-dictionaries-admin"> <code class="literal"> MASKING_DICTIONARIES_ADMIN </code> </a> dynamic privilege. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/expressions.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="expressions"> </a> 11.5 Expressions </h2> </div> </div> </div> <a class="indexterm" name="idm46045218613088"> </a> <p> This section lists the grammar rules that expressions must follow in MySQL and provides additional information about the types of terms that may appear in expressions. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="expressions.html#expression-syntax" title="Expression Syntax"> Expression Syntax </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="expressions.html#expression-term-notes" title="Expression Term Notes"> Expression Term Notes </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="expressions.html#temporal-intervals" title="Temporal Intervals"> Temporal Intervals </a> </p> </li> </ul> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="expression-syntax"> </a> Expression Syntax </h3> </div> </div> </div> <p> The following grammar rules define expression syntax in MySQL. The grammar shown here is based on that given in the <code class="filename"> sql/sql_yacc.yy </code> file of MySQL source distributions. For additional information about some of the expression terms, see <a class="xref" href="expressions.html#expression-term-notes" title="Expression Term Notes"> Expression Term Notes </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22441447"><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"><em class="replaceable">expr</em>: <em class="replaceable">expr</em> <span class="token operator">OR</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <em class="replaceable">expr</em> <span class="token operator">||</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <em class="replaceable">expr</em> <span class="token keyword">XOR</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <em class="replaceable">expr</em> <span class="token operator">AND</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <em class="replaceable">expr</em> <span class="token operator">&amp;&amp;</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <span class="token operator">NOT</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <span class="token operator">!</span> <em class="replaceable">expr</em> <span class="token operator">|</span> <em class="replaceable">boolean_primary</em> <span class="token operator">IS</span> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> {<span class="token boolean">TRUE</span> <span class="token operator">|</span> <span class="token boolean">FALSE</span> <span class="token operator">|</span> <span class="token keyword">UNKNOWN</span>} <span class="token operator">|</span> <em class="replaceable">boolean_primary</em> <em class="replaceable">boolean_primary</em>: <em class="replaceable">boolean_primary</em> <span class="token operator">IS</span> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token boolean">NULL</span> <span class="token operator">|</span> <em class="replaceable">boolean_primary</em> <span class="token operator">&lt;=&gt;</span> <em class="replaceable">predicate</em> <span class="token operator">|</span> <em class="replaceable">boolean_primary</em> <em class="replaceable">comparison_operator</em> <em class="replaceable">predicate</em> <span class="token operator">|</span> <em class="replaceable">boolean_primary</em> <em class="replaceable">comparison_operator</em> {<span class="token keyword">ALL</span> <span class="token operator">|</span> <span class="token keyword">ANY</span>} <span class="token punctuation">(</span><em class="replaceable">subquery</em><span class="token punctuation">)</span> <span class="token operator">|</span> <em class="replaceable">predicate</em> <em class="replaceable">comparison_operator</em>: <span class="token operator">=</span> <span class="token operator">|</span> <span class="token operator">&gt;=</span> <span class="token operator">|</span> <span class="token operator">&gt;</span> <span class="token operator">|</span> <span class="token operator">&lt;=</span> <span class="token operator">|</span> <span class="token operator">&lt;</span> <span class="token operator">|</span> <span class="token operator">&lt;&gt;</span> <span class="token operator">|</span> <span class="token operator">!=</span> <em class="replaceable">predicate</em>: <em class="replaceable">bit_expr</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">IN</span> <span class="token punctuation">(</span><em class="replaceable">subquery</em><span class="token punctuation">)</span> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">IN</span> <span class="token punctuation">(</span><em class="replaceable">expr</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">expr</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token operator">BETWEEN</span> <em class="replaceable">bit_expr</em> <span class="token operator">AND</span> <em class="replaceable">predicate</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token keyword">SOUNDS</span> <span class="token operator">LIKE</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token operator">LIKE</span> <em class="replaceable">simple_expr</em> <span class="token punctuation">[</span><span class="token keyword">ESCAPE</span> <em class="replaceable">simple_expr</em><span class="token punctuation">]</span> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token operator">REGEXP</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <em class="replaceable">bit_expr</em>: <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">&amp;</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">&lt;&lt;</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">&gt;&gt;</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">+</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">-</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">*</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">/</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">DIV</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">MOD</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">%</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">^</span> <em class="replaceable">bit_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">+</span> <em class="replaceable">interval_expr</em> <span class="token operator">|</span> <em class="replaceable">bit_expr</em> <span class="token operator">-</span> <em class="replaceable">interval_expr</em> <span class="token operator">|</span> <em class="replaceable">simple_expr</em> <em class="replaceable">simple_expr</em>: <em class="replaceable">literal</em> <span class="token operator">|</span> <em class="replaceable">identifier</em> <span class="token operator">|</span> <em class="replaceable">function_call</em> <span class="token operator">|</span> <em class="replaceable">simple_expr</em> <span class="token keyword">COLLATE</span> <em class="replaceable">collation_name</em> <span class="token operator">|</span> <em class="replaceable">param_marker</em> <span class="token operator">|</span> <em class="replaceable">variable</em> <span class="token operator">|</span> <em class="replaceable">simple_expr</em> <span class="token operator">||</span> <em class="replaceable">simple_expr</em> <span class="token operator">|</span> <span class="token operator">+</span> <em class="replaceable">simple_expr</em> <span class="token operator">|</span> <span class="token operator">-</span> <em class="replaceable">simple_expr</em> <span class="token operator">|</span> <span class="token operator">~</span> <em class="replaceable">simple_expr</em> <span class="token operator">|</span> <span class="token operator">!</span> <em class="replaceable">simple_expr</em> <span class="token operator">|</span> <span class="token datatype">BINARY</span> <em class="replaceable">simple_expr</em> <span class="token operator">|</span> <span class="token punctuation">(</span><em class="replaceable">expr</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">expr</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token keyword">ROW</span> <span class="token punctuation">(</span><em class="replaceable">expr</em><span class="token punctuation">,</span> <em class="replaceable">expr</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">expr</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token punctuation">(</span><em class="replaceable">subquery</em><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">(</span><em class="replaceable">subquery</em><span class="token punctuation">)</span> <span class="token operator">|</span> {<em class="replaceable">identifier</em> <em class="replaceable">expr</em>} <span class="token operator">|</span> <em class="replaceable">match_expr</em> <span class="token operator">|</span> <em class="replaceable">case_expr</em> <span class="token operator">|</span> <em class="replaceable">interval_expr</em></code></pre> </div> <p> For operator precedence, see <a class="xref" href="operator-precedence.html" title="14.4.1 Operator Precedence"> Section 14.4.1, “Operator Precedence” </a> . The precedence and meaning of some operators depends on the SQL mode: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> By default, <a class="link" href="logical-operators.html#operator_or"> <code class="literal"> || </code> </a> is a logical <a class="link" href="logical-operators.html#operator_or"> <code class="literal"> OR </code> </a> operator. With <a class="link" href="sql-mode.html#sqlmode_pipes_as_concat"> <code class="literal"> PIPES_AS_CONCAT </code> </a> enabled, <a class="link" href="logical-operators.html#operator_or"> <code class="literal"> || </code> </a> is string concatenation, with a precedence between <a class="link" href="bit-functions.html#operator_bitwise-xor"> <code class="literal"> ^ </code> </a> and the unary operators. </p> </li> <li class="listitem"> <p> By default, <a class="link" href="logical-operators.html#operator_not"> <code class="literal"> ! </code> </a> has a higher precedence than <code class="literal"> NOT </code> . With <a class="link" href="sql-mode.html#sqlmode_high_not_precedence"> <code class="literal"> HIGH_NOT_PRECEDENCE </code> </a> enabled, <a class="link" href="logical-operators.html#operator_not"> <code class="literal"> ! </code> </a> and <code class="literal"> NOT </code> have the same precedence. </p> </li> </ul> </div> <p> See <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes"> Section 7.1.11, “Server SQL Modes” </a> . </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="expression-term-notes"> </a> Expression Term Notes </h3> </div> </div> </div> <p> For literal value syntax, see <a class="xref" href="literals.html" title="11.1 Literal Values"> Section 11.1, “Literal Values” </a> . </p> <p> For identifier syntax, see <a class="xref" href="identifiers.html" title="11.2 Schema Object Names"> Section 11.2, “Schema Object Names” </a> . </p> <p> Variables can be user variables, system variables, or stored program local variables or parameters: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> User variables: <a class="xref" href="user-variables.html" title="11.4 User-Defined Variables"> Section 11.4, “User-Defined Variables” </a> </p> </li> <li class="listitem"> <p> System variables: <a class="xref" href="using-system-variables.html" title="7.1.9 Using System Variables"> Section 7.1.9, “Using System Variables” </a> </p> </li> <li class="listitem"> <p> Stored program local variables: <a class="xref" href="declare-local-variable.html" title="15.6.4.1 Local Variable DECLARE Statement"> Section 15.6.4.1, “Local Variable DECLARE Statement” </a> </p> </li> <li class="listitem"> <p> Stored program parameters: <a class="xref" href="create-procedure.html" title="15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements"> Section 15.1.17, “CREATE PROCEDURE and CREATE FUNCTION Statements” </a> </p> </li> </ul> </div> <p> <em class="replaceable"> <code> param_marker </code> </em> is <code class="literal"> ? </code> as used in prepared statements for placeholders. See <a class="xref" href="prepare.html" title="15.5.1 PREPARE Statement"> Section 15.5.1, “PREPARE Statement” </a> . </p> <p> <code class="literal"> ( <em class="replaceable"> <code> subquery </code> </em> ) </code> indicates a subquery that returns a single value; that is, a scalar subquery. See <a class="xref" href="scalar-subqueries.html" title="15.2.15.1 The Subquery as Scalar Operand"> Section 15.2.15.1, “The Subquery as Scalar Operand” </a> . </p> <p> <code class="literal"> { <em class="replaceable"> <code> identifier </code> </em> <em class="replaceable"> <code> expr </code> </em> } </code> is ODBC escape syntax and is accepted for ODBC compatibility. The value is <em class="replaceable"> <code> expr </code> </em> . The <code class="literal"> { </code> and <code class="literal"> } </code> curly braces in the syntax should be written literally; they are not metasyntax as used elsewhere in syntax descriptions. </p> <p> <em class="replaceable"> <code> match_expr </code> </em> indicates a <a class="link" href="fulltext-search.html#function_match"> <code class="literal"> MATCH </code> </a> expression. See <a class="xref" href="fulltext-search.html" title="14.9 Full-Text Search Functions"> Section 14.9, “Full-Text Search Functions” </a> . </p> <p> <em class="replaceable"> <code> case_expr </code> </em> indicates a <a class="link" href="flow-control-functions.html#operator_case"> <code class="literal"> CASE </code> </a> expression. See <a class="xref" href="flow-control-functions.html" title="14.5 Flow Control Functions"> Section 14.5, “Flow Control Functions” </a> . </p> <p> <em class="replaceable"> <code> interval_expr </code> </em> represents a temporal interval. See <a class="xref" href="expressions.html#temporal-intervals" title="Temporal Intervals"> Temporal Intervals </a> . </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="temporal-intervals"> </a> Temporal Intervals </h3> </div> </div> </div> <a class="indexterm" name="idm46045218514928"> </a> <a class="indexterm" name="idm46045218513424"> </a> <a class="indexterm" name="idm46045218512336"> </a> <p> <em class="replaceable"> <code> interval_expr </code> </em> in expressions represents a temporal interval. Intervals have this syntax: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa67918453"><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">INTERVAL</span> <em class="replaceable">expr</em> <em class="replaceable">unit</em></code></pre> </div> <p> <em class="replaceable"> <code> expr </code> </em> represents a quantity. <em class="replaceable"> <code> unit </code> </em> represents the unit for interpreting the quantity; it is a specifier such as <code class="literal"> HOUR </code> , <code class="literal"> DAY </code> , or <code class="literal"> WEEK </code> . The <code class="literal"> INTERVAL </code> keyword and the <em class="replaceable"> <code> unit </code> </em> specifier are not case-sensitive. </p> <p> The following table shows the expected form of the <em class="replaceable"> <code> expr </code> </em> argument for each <em class="replaceable"> <code> unit </code> </em> value. </p> <div class="table"> <a name="temporal-interval-arguments"> </a> <p class="title"> <b> Table 11.2 Temporal Interval Expression and Unit Arguments </b> </p> <div class="table-contents"> <table summary="unit values and the expected expr argument for each unit value."> <colgroup> <col style="width: 50%"/> <col style="width: 50%"/> </colgroup> <thead> <tr> <th> <em class="replaceable"> <code> unit </code> </em> Value </th> <th> Expected <em class="replaceable"> <code> expr </code> </em> Format </th> </tr> </thead> <tbody> <tr> <td> <code class="literal"> MICROSECOND </code> </td> <td> <code class="literal"> MICROSECONDS </code> </td> </tr> <tr> <td> <code class="literal"> SECOND </code> </td> <td> <code class="literal"> SECONDS </code> </td> </tr> <tr> <td> <code class="literal"> MINUTE </code> </td> <td> <code class="literal"> MINUTES </code> </td> </tr> <tr> <td> <code class="literal"> HOUR </code> </td> <td> <code class="literal"> HOURS </code> </td> </tr> <tr> <td> <code class="literal"> DAY </code> </td> <td> <code class="literal"> DAYS </code> </td> </tr> <tr> <td> <code class="literal"> WEEK </code> </td> <td> <code class="literal"> WEEKS </code> </td> </tr> <tr> <td> <code class="literal"> MONTH </code> </td> <td> <code class="literal"> MONTHS </code> </td> </tr> <tr> <td> <code class="literal"> QUARTER </code> </td> <td> <code class="literal"> QUARTERS </code> </td> </tr> <tr> <td> <code class="literal"> YEAR </code> </td> <td> <code class="literal"> YEARS </code> </td> </tr> <tr> <td> <code class="literal"> SECOND_MICROSECOND </code> </td> <td> <code class="literal"> 'SECONDS.MICROSECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> MINUTE_MICROSECOND </code> </td> <td> <code class="literal"> 'MINUTES:SECONDS.MICROSECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> MINUTE_SECOND </code> </td> <td> <code class="literal"> 'MINUTES:SECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> HOUR_MICROSECOND </code> </td> <td> <code class="literal"> 'HOURS:MINUTES:SECONDS.MICROSECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> HOUR_SECOND </code> </td> <td> <code class="literal"> 'HOURS:MINUTES:SECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> HOUR_MINUTE </code> </td> <td> <code class="literal"> 'HOURS:MINUTES' </code> </td> </tr> <tr> <td> <code class="literal"> DAY_MICROSECOND </code> </td> <td> <code class="literal"> 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> DAY_SECOND </code> </td> <td> <code class="literal"> 'DAYS HOURS:MINUTES:SECONDS' </code> </td> </tr> <tr> <td> <code class="literal"> DAY_MINUTE </code> </td> <td> <code class="literal"> 'DAYS HOURS:MINUTES' </code> </td> </tr> <tr> <td> <code class="literal"> DAY_HOUR </code> </td> <td> <code class="literal"> 'DAYS HOURS' </code> </td> </tr> <tr> <td> <code class="literal"> YEAR_MONTH </code> </td> <td> <code class="literal"> 'YEARS-MONTHS' </code> </td> </tr> </tbody> </table> </div> <div class="table-contents"> <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 681px;"> <thead> <tr> <th style="width: 340.141px;"> <em class="replaceable"> <code> unit </code> </em> Value </th> <th style="width: 340.141px;"> Expected <em class="replaceable"> <code> expr </code> </em> Format </th> </tr> </thead> </table> </div> </div> <br class="table-break"/> <p> MySQL permits any punctuation delimiter in the <em class="replaceable"> <code> expr </code> </em> format. Those shown in the table are the suggested delimiters. </p> <p> Temporal intervals are used for certain functions, such as <a class="link" href="date-and-time-functions.html#function_date-add"> <code class="literal"> DATE_ADD() </code> </a> and <a class="link" href="date-and-time-functions.html#function_date-sub"> <code class="literal"> DATE_SUB() </code> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa98324662"><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">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2018-05-01'</span><span class="token punctuation">,</span><span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2018-05-02'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'2018-05-01'</span><span class="token punctuation">,</span><span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token datatype">YEAR</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2017-05-01'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2020-12-31 23:59:59'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">SECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2021-01-01 00:00:00'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2018-12-31 23:59:59'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2019-01-01 23:59:59'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2100-12-31 23:59:59'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token string">'1:1'</span> <span class="token keyword">MINUTE_SECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2101-01-01 00:01:00'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'2025-01-01 00:00:00'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token string">'1 1:1:1'</span> <span class="token keyword">DAY_SECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2024-12-30 22:58:59'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'1900-01-01 00:00:00'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token string">'-1 10'</span> <span class="token keyword">DAY_HOUR</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'1899-12-30 14:00:00'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_SUB</span><span class="token punctuation">(</span><span class="token string">'1998-01-02'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">31</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'1997-12-02'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'1992-12-31 23:59:59.000002'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token string">'1.999999'</span> <span class="token keyword">SECOND_MICROSECOND</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'1993-01-01 00:00:01.000001'</span></code></pre> </div> <p> Temporal arithmetic also can be performed in expressions using <code class="literal"> INTERVAL </code> together with the <a class="link" href="arithmetic-functions.html#operator_plus"> <code class="literal"> + </code> </a> or <a class="link" href="arithmetic-functions.html#operator_minus"> <code class="literal"> - </code> </a> operator: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53990518"><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 datatype">date</span> <span class="token operator">+</span> <span class="token keyword">INTERVAL</span> <em class="replaceable">expr</em> <em class="replaceable">unit</em> <span class="token datatype">date</span> <span class="token operator">-</span> <span class="token keyword">INTERVAL</span> <em class="replaceable">expr</em> <em class="replaceable">unit</em></code></pre> </div> <p> <code class="literal"> INTERVAL <em class="replaceable"> <code> expr </code> </em> <em class="replaceable"> <code> unit </code> </em> </code> is permitted on either side of the <a class="link" href="arithmetic-functions.html#operator_plus"> <code class="literal"> + </code> </a> operator if the expression on the other side is a date or datetime value. For the <a class="link" href="arithmetic-functions.html#operator_minus"> <code class="literal"> - </code> </a> operator, <code class="literal"> INTERVAL <em class="replaceable"> <code> expr </code> </em> <em class="replaceable"> <code> unit </code> </em> </code> is permitted only on the right side, because it makes no sense to subtract a date or datetime value from an interval. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85998782"><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">SELECT</span> <span class="token string">'2018-12-31 23:59:59'</span> <span class="token operator">+</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">SECOND</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2019-01-01 00:00:00'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span> <span class="token operator">+</span> <span class="token string">'2018-12-31'</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2019-01-01'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'2025-01-01'</span> <span class="token operator">-</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">SECOND</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2024-12-31 23:59:59'</span></code></pre> </div> <p> The <a class="link" href="date-and-time-functions.html#function_extract"> <code class="literal"> EXTRACT() </code> </a> function uses the same kinds of <em class="replaceable"> <code> unit </code> </em> specifiers as <a class="link" href="date-and-time-functions.html#function_date-add"> <code class="literal"> DATE_ADD() </code> </a> or <a class="link" href="date-and-time-functions.html#function_date-sub"> <code class="literal"> DATE_SUB() </code> </a> , but extracts parts from the date rather than performing date arithmetic: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86685915"><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">SELECT</span> <span class="token function">EXTRACT</span><span class="token punctuation">(</span><span class="token datatype">YEAR</span> <span class="token keyword">FROM</span> <span class="token string">'2019-07-02'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">2019</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">EXTRACT</span><span class="token punctuation">(</span><span class="token keyword">YEAR_MONTH</span> <span class="token keyword">FROM</span> <span class="token string">'2019-07-02 01:02:03'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">201907</span></code></pre> </div> <p> Temporal intervals can be used in <a class="link" href="create-event.html" title="15.1.13 CREATE EVENT Statement"> <code class="literal"> CREATE EVENT </code> </a> statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66032978"><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">EVENT</span> myevent <span class="token keyword">ON</span> <span class="token keyword">SCHEDULE</span> <span class="token keyword">AT</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token operator">+</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">HOUR</span> <span class="token keyword">DO</span> <span class="token keyword">UPDATE</span> myschema<span class="token punctuation">.</span>mytable <span class="token keyword">SET</span> mycol <span class="token operator">=</span> mycol <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span></code></pre> </div> <p> If you specify an interval value that is too short (does not include all the interval parts that would be expected from the <em class="replaceable"> <code> unit </code> </em> keyword), MySQL assumes that you have left out the leftmost parts of the interval value. For example, if you specify a <em class="replaceable"> <code> unit </code> </em> of <code class="literal"> DAY_SECOND </code> , the value of <em class="replaceable"> <code> expr </code> </em> is expected to have days, hours, minutes, and seconds parts. If you specify a value like <code class="literal"> '1:10' </code> , MySQL assumes that the days and hours parts are missing and the value represents minutes and seconds. In other words, <code class="literal"> '1:10' DAY_SECOND </code> is interpreted in such a way that it is equivalent to <code class="literal"> '1:10' MINUTE_SECOND </code> . This is analogous to the way that MySQL interprets <a class="link" href="time.html" title="13.2.3 The TIME Type"> <code class="literal"> TIME </code> </a> values as representing elapsed time rather than as a time of day. </p> <p> <em class="replaceable"> <code> expr </code> </em> is treated as a string, so be careful if you specify a nonstring value with <code class="literal"> INTERVAL </code> . For example, with an interval specifier of <code class="literal"> HOUR_MINUTE </code> , '6/4' is treated as 6 hours, four minutes, whereas <code class="literal"> 6/4 </code> evaluates to <code class="literal"> 1.5000 </code> and is treated as 1 hour, 5000 minutes: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60546875"><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">SELECT</span> <span class="token string">'6/4'</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token operator">/</span><span class="token number">4</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">1.5000</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2019-01-01'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token string">'6/4'</span> <span class="token keyword">HOUR_MINUTE</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2019-01-01 06:04:00'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2019-01-01'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">6</span><span class="token operator">/</span><span class="token number">4</span> <span class="token keyword">HOUR_MINUTE</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2019-01-04 12:20:00'</span></code></pre> </div> <p> To ensure interpretation of the interval value as you expect, a <a class="link" href="cast-functions.html#function_cast"> <code class="literal"> CAST() </code> </a> operation may be used. To treat <code class="literal"> 6/4 </code> as 1 hour, 5 minutes, cast it to a <a class="link" href="fixed-point-types.html" title="13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC"> <code class="literal"> DECIMAL </code> </a> value with a single fractional digit: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29285044"><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">SELECT</span> <span class="token function">CAST</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token operator">/</span><span class="token number">4</span> <span class="token keyword">AS</span> <span class="token datatype">DECIMAL</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token number">1.5</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'1970-01-01 12:00:00'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">INTERVAL</span> <span class="token function">CAST</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token operator">/</span><span class="token number">4</span> <span class="token keyword">AS</span> <span class="token datatype">DECIMAL</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">HOUR_MINUTE</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'1970-01-01 13:05:00'</span></code></pre> </div> <p> If you add to or subtract from a date value something that contains a time part, the result is automatically converted to a datetime value: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47125288"><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">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2023-01-01'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2023-01-02'</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2023-01-01'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">HOUR</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2023-01-01 01:00:00'</span></code></pre> </div> <p> If you add <code class="literal"> MONTH </code> , <code class="literal"> YEAR_MONTH </code> , or <code class="literal"> YEAR </code> and the resulting date has a day that is larger than the maximum day for the new month, the day is adjusted to the maximum days in the new month: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51841626"><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">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2019-01-30'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">MONTH</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token string">'2019-02-28'</span></code></pre> </div> <p> Date arithmetic operations require complete dates and do not work with incomplete dates such as <code class="literal"> '2016-07-00' </code> or badly malformed dates: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46201224"><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">SELECT</span> <span class="token function">DATE_ADD</span><span class="token punctuation">(</span><span class="token string">'2016-07-00'</span><span class="token punctuation">,</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">DAY</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token boolean">NULL</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'2005-03-32'</span> <span class="token operator">+</span> <span class="token keyword">INTERVAL</span> <span class="token number">1</span> <span class="token keyword">MONTH</span><span class="token punctuation">;</span> <span class="token prompt"> -&gt;</span> <span class="token boolean">NULL</span></code></pre> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/charset-collation-compatibility.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="charset-collation-compatibility"> </a> 12.8.3 Character Set and Collation Compatibility </h3> </div> </div> </div> <p> Each character set has one or more collations, but each collation is associated with one and only one character set. Therefore, the following statement causes an error message because the <code class="literal"> latin2_bin </code> collation is not legal with the <code class="literal"> latin1 </code> character set: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24755424"><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">SELECT</span> _latin1 <span class="token string">'x'</span> <span class="token keyword">COLLATE</span> latin2_bin<span class="token punctuation">;</span> <span class="token output">ERROR 1253 (42000)<span class="token punctuation">:</span> COLLATION 'latin2_bin' is not valid for CHARACTER SET 'latin1'</span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/sys-host-summary-by-statement-latency.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="sys-host-summary-by-statement-latency"> </a> 30.4.3.5 The host_summary_by_statement_latency and x$host_summary_by_statement_latency Views </h4> </div> </div> </div> <a class="indexterm" name="idm46045063264112"> </a> <a class="indexterm" name="idm46045063262656"> </a> <a class="indexterm" name="idm46045063261152"> </a> <a class="indexterm" name="idm46045063259632"> </a> <p> These views summarize overall statement statistics, grouped by host. By default, rows are sorted by descending total latency. </p> <p> The <a class="link" href="sys-host-summary-by-statement-latency.html" title="30.4.3.5 The host_summary_by_statement_latency and x$host_summary_by_statement_latency Views"> <code class="literal"> host_summary_by_statement_latency </code> </a> and <a class="link" href="sys-host-summary-by-statement-latency.html" title="30.4.3.5 The host_summary_by_statement_latency and x$host_summary_by_statement_latency Views"> <code class="literal"> x$host_summary_by_statement_latency </code> </a> views have these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> host </code> </p> <p> The host from which the client connected. Rows for which the <code class="literal"> HOST </code> column in the underlying Performance Schema table is <code class="literal"> NULL </code> are assumed to be for background threads and are reported with a host name of <code class="literal"> background </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> total </code> </p> <p> The total number of statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> total_latency </code> </p> <p> The total wait time of timed statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> max_latency </code> </p> <p> The maximum single wait time of timed statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> lock_latency </code> </p> <p> The total time waiting for locks by timed statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> cpu_latency </code> </p> <p> The time spent on CPU for the current thread. </p> </li> <li class="listitem"> <p> <code class="literal"> rows_sent </code> </p> <p> The total number of rows returned by statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> rows_examined </code> </p> <p> The total number of rows read from storage engines by statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> rows_affected </code> </p> <p> The total number of rows affected by statements for the host. </p> </li> <li class="listitem"> <p> <code class="literal"> full_scans </code> </p> <p> The total number of full table scans by statements for the host. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/version-tokens.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="version-tokens"> </a> 7.6.6 Version Tokens </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="version-tokens-elements.html"> 7.6.6.1 Version Tokens Elements </a> </span> </dt> <dt> <span class="section"> <a href="version-tokens-installation.html"> 7.6.6.2 Installing or Uninstalling Version Tokens </a> </span> </dt> <dt> <span class="section"> <a href="version-tokens-usage.html"> 7.6.6.3 Using Version Tokens </a> </span> </dt> <dt> <span class="section"> <a href="version-tokens-reference.html"> 7.6.6.4 Version Tokens Reference </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045256131136"> </a> <p> MySQL includes Version Tokens, a feature that enables creation of and synchronization around server tokens that applications can use to prevent accessing incorrect or out-of-date data. </p> <p> The Version Tokens interface has these characteristics: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Version tokens are pairs consisting of a name that serves as a key or identifier, plus a value. </p> </li> <li class="listitem"> <p> Version tokens can be locked. An application can use token locks to indicate to other cooperating applications that tokens are in use and should not be modified. </p> </li> <li class="listitem"> <p> Version token lists are established per server (for example, to specify the server assignment or operational state). In addition, an application that communicates with a server can register its own list of tokens that indicate the state it requires the server to be in. An SQL statement sent by the application to a server not in the required state produces an error. This is a signal to the application that it should seek a different server in the required state to receive the SQL statement. </p> </li> </ul> </div> <p> The following sections describe the elements of Version Tokens, discuss how to install and use it, and provide reference information for its elements. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/innodb-locking-transaction-model.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="innodb-locking-transaction-model"> </a> 17.7 InnoDB Locking and Transaction Model </h2> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="innodb-locking.html"> 17.7.1 InnoDB Locking </a> </span> </dt> <dt> <span class="section"> <a href="innodb-transaction-model.html"> 17.7.2 InnoDB Transaction Model </a> </span> </dt> <dt> <span class="section"> <a href="innodb-locks-set.html"> 17.7.3 Locks Set by Different SQL Statements in InnoDB </a> </span> </dt> <dt> <span class="section"> <a href="innodb-next-key-locking.html"> 17.7.4 Phantom Rows </a> </span> </dt> <dt> <span class="section"> <a href="innodb-deadlocks.html"> 17.7.5 Deadlocks in InnoDB </a> </span> </dt> <dt> <span class="section"> <a href="innodb-transaction-scheduling.html"> 17.7.6 Transaction Scheduling </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045164619200"> </a> <a class="indexterm" name="idm46045164617808"> </a> <a class="indexterm" name="idm46045164616416"> </a> <a class="indexterm" name="idm46045164615408"> </a> <p> To implement a large-scale, busy, or highly reliable database application, to port substantial code from a different database system, or to tune MySQL performance, it is important to understand <code class="literal"> InnoDB </code> locking and the <code class="literal"> InnoDB </code> transaction model. </p> <p> This section discusses several topics related to <code class="literal"> InnoDB </code> locking and the <code class="literal"> InnoDB </code> transaction model with which you should be familiar. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="innodb-locking.html" title="17.7.1 InnoDB Locking"> Section 17.7.1, “InnoDB Locking” </a> describes lock types used by <code class="literal"> InnoDB </code> . </p> </li> <li class="listitem"> <p> <a class="xref" href="innodb-transaction-model.html" title="17.7.2 InnoDB Transaction Model"> Section 17.7.2, “InnoDB Transaction Model” </a> describes transaction isolation levels and the locking strategies used by each. It also discusses the use of <a class="link" href="server-system-variables.html#sysvar_autocommit"> <code class="literal"> autocommit </code> </a> , consistent non-locking reads, and locking reads. </p> </li> <li class="listitem"> <p> <a class="xref" href="innodb-locks-set.html" title="17.7.3 Locks Set by Different SQL Statements in InnoDB"> Section 17.7.3, “Locks Set by Different SQL Statements in InnoDB” </a> discusses specific types of locks set in <code class="literal"> InnoDB </code> for various statements. </p> </li> <li class="listitem"> <p> <a class="xref" href="innodb-next-key-locking.html" title="17.7.4 Phantom Rows"> Section 17.7.4, “Phantom Rows” </a> describes how <code class="literal"> InnoDB </code> uses next-key locking to avoid phantom rows. </p> </li> <li class="listitem"> <p> <a class="xref" href="innodb-deadlocks.html" title="17.7.5 Deadlocks in InnoDB"> Section 17.7.5, “Deadlocks in InnoDB” </a> provides a deadlock example, discusses deadlock detection, and provides tips for minimizing and handling deadlocks in <code class="literal"> InnoDB </code> . </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-options-binary-log.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-options-binary-log"> </a> 19.1.6.4 Binary Logging Options and Variables </h4> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="replication-options-binary-log.html#replication-optvars-binlog" title="Startup Options Used with Binary Logging"> Startup Options Used with Binary Logging </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="replication-options-binary-log.html#replication-sysvars-binlog" title="System Variables Used with Binary Logging"> System Variables Used with Binary Logging </a> </p> </li> </ul> </div> <p> You can use the <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> options and system variables that are described in this section to affect the operation of the binary log as well as to control which statements are written to the binary log. For additional information about the binary log, see <a class="xref" href="binary-log.html" title="7.4.4 The Binary Log"> Section 7.4.4, “The Binary Log” </a> . For additional information about using MySQL server options and system variables, see <a class="xref" href="server-options.html" title="7.1.7 Server Command Options"> Section 7.1.7, “Server Command Options” </a> , and <a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables"> Section 7.1.8, “Server System Variables” </a> . </p> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="replication-optvars-binlog"> </a> Startup Options Used with Binary Logging </h5> </div> </div> </div> <p> The following list describes startup options for enabling and configuring the binary log. System variables used with binary logging are discussed later in this section. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a name="option_mysqld_binlog-row-event-max-size"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-row-event-max-size"> <code class="option"> --binlog-row-event-max-size= <em class="replaceable"> <code> N </code> </em> </code> </a> </p> <a class="indexterm" name="idm46045140972496"> </a> <a class="indexterm" name="idm46045140970992"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog-row-event-max-size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-row-event-max-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_event_max_size"> binlog_row_event_max_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 8192 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 256 </code> </td> </tr> <tr> <th> Maximum Value (64-bit platforms) </th> <td> <code class="literal"> 18446744073709551615 </code> </td> </tr> <tr> <th> Maximum Value (32-bit platforms) </th> <td> <code class="literal"> 4294967295 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> </tbody> </table> </div> <p> When row-based binary logging is used, this setting is a soft limit on the maximum size of a row-based binary log event, in bytes. Where possible, rows stored in the binary log are grouped into events with a size not exceeding the value of this setting. If an event cannot be split, the maximum size can be exceeded. The value must be (or else gets rounded down to) a multiple of 256. The default is 8192 bytes. </p> </li> <li class="listitem"> <p> <a name="option_mysqld_log-bin"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin[= <em class="replaceable"> <code> base_name </code> </em> ] </code> </a> </p> <a class="indexterm" name="idm46045140936496"> </a> <a class="indexterm" name="idm46045140935008"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log-bin"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-bin=file_name </code> </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <p> Specifies the base name to use for binary log files. With binary logging enabled, the server logs all statements that change data to the binary log, which is used for backup and replication. The binary log is a sequence of files with a base name and numeric extension. The <code class="option"> --log-bin </code> option value is the base name for the log sequence. The server creates binary log files in sequence by adding a numeric suffix to the base name. </p> <p> If you do not supply the <code class="option"> --log-bin </code> option, MySQL uses <code class="filename"> binlog </code> as the default base name for the binary log files. For compatibility with earlier releases, if you supply the <code class="option"> --log-bin </code> option with no string or with an empty string, the base name defaults to <code class="filename"> <em class="replaceable"> <code> host_name </code> </em> -bin </code> , using the name of the host machine. </p> <p> The default location for binary log files is the data directory. You can use the <code class="option"> --log-bin </code> option to specify an alternative location, by adding a leading absolute path name to the base name to specify a different directory. When the server reads an entry from the binary log index file, which tracks the binary log files that have been used, it checks whether the entry contains a relative path. If it does, the relative part of the path is replaced with the absolute path set using the <code class="option"> --log-bin </code> option. An absolute path recorded in the binary log index file remains unchanged; in such a case, the index file must be edited manually to enable a new path or paths to be used. The binary log file base name and any specified path are available as the <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_basename"> <code class="literal"> log_bin_basename </code> </a> system variable. </p> <p> In MySQL 8.4, binary logging is enabled by default, whether or not you specify the <code class="option"> --log-bin </code> option. The exception is if you use <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> to initialize the data directory manually by invoking it with the <code class="option"> --initialize </code> or <code class="option"> --initialize-insecure </code> option, when binary logging is disabled by default. It is possible to enable binary logging in this case by specifying the <code class="option"> --log-bin </code> option. When binary logging is enabled, the <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> system variable, which shows the status of binary logging on the server, is set to ON. </p> <p> To disable binary logging, you can specify the <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --skip-log-bin </code> </a> or <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --disable-log-bin </code> </a> option at startup. If either of these options is specified and <code class="option"> --log-bin </code> is also specified, the option specified later takes precedence. When binary logging is disabled, the <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> system variable is set to OFF. </p> <p> When GTIDs are in use on the server, if you disable binary logging when restarting the server after an abnormal shutdown, some GTIDs are likely to be lost, causing replication to fail. In a normal shutdown, the set of GTIDs from the current binary log file is saved in the <code class="literal"> mysql.gtid_executed </code> table. Following an abnormal shutdown where this did not happen, during recovery the GTIDs are added to the table from the binary log file, provided that binary logging is still enabled. If binary logging is disabled for the server restart, the server cannot access the binary log file to recover the GTIDs, so replication cannot be started. Binary logging can be disabled safely after a normal shutdown. </p> <p> The <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="option"> --log-replica-updates </code> </a> and <a class="link" href="replication-options-replica.html#sysvar_replica_preserve_commit_order"> <code class="option"> --replica-preserve-commit-order </code> </a> options require binary logging. If you disable binary logging, either omit these options, or specify <code class="option"> --log-replica-updates=OFF </code> and <code class="option"> --skip-replica-preserve-commit-order </code> . MySQL disables these options by default when <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --skip-log-bin </code> </a> or <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --disable-log-bin </code> </a> is specified. If you specify <code class="option"> --log-replica-updates </code> or <code class="option"> --replica-preserve-commit-order </code> together with <code class="option"> --skip-log-bin </code> or <code class="option"> --disable-log-bin </code> , a warning or error message is issued. </p> <p> The server can be started with the default server ID when binary logging is enabled, but an informational message is issued if you do not specify a server ID explicitly by setting the <a class="link" href="replication-options.html#sysvar_server_id"> <code class="literal"> server_id </code> </a> system variable. For servers that are used in a replication topology, you must specify a unique nonzero server ID for each server. </p> <p> For information on the format and management of the binary log, see <a class="xref" href="binary-log.html" title="7.4.4 The Binary Log"> Section 7.4.4, “The Binary Log” </a> . </p> </li> <li class="listitem"> <p> <a name="option_mysqld_log-bin-index"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin-index"> <code class="option"> --log-bin-index[= <em class="replaceable"> <code> file_name </code> </em> ] </code> </a> </p> <a class="indexterm" name="idm46045140893200"> </a> <a class="indexterm" name="idm46045140891712"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log-bin-index"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-bin-index=file_name </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_index"> log_bin_index </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <p> The name for the binary log index file, which contains the names of the binary log files. By default, it has the same location and base name as the value specified for the binary log files using the <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin </code> </a> option, plus the extension <code class="filename"> .index </code> . If you do not specify <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin </code> </a> , the default binary log index file name is <code class="filename"> binlog.index </code> . If you specify <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin </code> </a> option with no string or an empty string, the default binary log index file name is <code class="filename"> <em class="replaceable"> <code> host_name </code> </em> -bin.index </code> , using the name of the host machine. </p> <p> For information on the format and management of the binary log, see <a class="xref" href="binary-log.html" title="7.4.4 The Binary Log"> Section 7.4.4, “The Binary Log” </a> . </p> </li> </ul> </div> <p> <b> Statement selection options. </b> The options in the following list affect which statements are written to the binary log, and thus sent by a replication source server to its replicas. There are also options for replicas that control which statements received from the source should be executed or ignored. For details, see <a class="xref" href="replication-options-replica.html" title="19.1.6.3 Replica Server Options and Variables"> Section 19.1.6.3, “Replica Server Options and Variables” </a> . </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a name="option_mysqld_binlog-do-db"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db= <em class="replaceable"> <code> db_name </code> </em> </code> </a> </p> <a class="indexterm" name="idm46045140859856"> </a> <a class="indexterm" name="idm46045140858368"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog-do-db"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-do-db=name </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <p> This option affects binary logging in a manner similar to the way that <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db"> <code class="option"> --replicate-do-db </code> </a> affects replication. </p> <p> The effects of this option depend on whether the statement-based or row-based logging format is in use, in the same way that the effects of <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db"> <code class="option"> --replicate-do-db </code> </a> depend on whether statement-based or row-based replication is in use. You should keep in mind that the format used to log a given statement may not necessarily be the same as that indicated by the value of <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> . For example, DDL statements such as <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> and <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> are always logged as statements, without regard to the logging format in effect, so the following statement-based rules for <code class="option"> --binlog-do-db </code> always apply in determining whether or not the statement is logged. </p> <p> <b> Statement-based logging. </b> Only those statements are written to the binary log where the default database (that is, the one selected by <a class="link" href="use.html" title="15.8.4 USE Statement"> <code class="literal"> USE </code> </a> ) is <em class="replaceable"> <code> db_name </code> </em> . To specify more than one database, use this option multiple times, once for each database; however, doing so does <span class="emphasis"> <em> not </em> </span> cause cross-database statements such as <code class="literal"> UPDATE <em class="replaceable"> <code> some_db.some_table </code> </em> SET foo='bar' </code> to be logged while a different database (or no database) is selected. </p> <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Warning </div> <p> To specify multiple databases you <span class="emphasis"> <em> must </em> </span> use multiple instances of this option. Because database names can contain commas, the list is treated as the name of a single database if you supply a comma-separated list. </p> </div> <p> An example of what does not work as you might expect when using statement-based logging: If the server is started with <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db=sales </code> </a> and you issue the following statements, the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement is <span class="emphasis"> <em> not </em> </span> logged: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96905284"><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">USE</span> prices<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> sales<span class="token punctuation">.</span>january <span class="token keyword">SET</span> amount<span class="token operator">=</span>amount<span class="token operator">+</span><span class="token number">1000</span><span class="token punctuation">;</span></code></pre> </div> <p> The main reason for this <span class="quote"> “ <span class="quote"> just check the default database </span> ” </span> behavior is that it is difficult from the statement alone to know whether it should be replicated (for example, if you are using multiple-table <a class="link" href="delete.html" title="15.2.2 DELETE Statement"> <code class="literal"> DELETE </code> </a> statements or multiple-table <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statements that act across multiple databases). It is also faster to check only the default database rather than all databases if there is no need. </p> <p> Another case which may not be self-evident occurs when a given database is replicated even though it was not specified when setting the option. If the server is started with <code class="option"> --binlog-do-db=sales </code> , the following <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement is logged even though <code class="literal"> prices </code> was not included when setting <code class="option"> --binlog-do-db </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa19129214"><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">USE</span> sales<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> prices<span class="token punctuation">.</span>discounts <span class="token keyword">SET</span> percentage <span class="token operator">=</span> percentage <span class="token operator">+</span> <span class="token number">10</span><span class="token punctuation">;</span></code></pre> </div> <p> Because <code class="literal"> sales </code> is the default database when the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement is issued, the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> is logged. </p> <p> <b> Row-based logging. </b> Logging is restricted to database <em class="replaceable"> <code> db_name </code> </em> . Only changes to tables belonging to <em class="replaceable"> <code> db_name </code> </em> are logged; the default database has no effect on this. Suppose that the server is started with <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db=sales </code> </a> and row-based logging is in effect, and then the following statements are executed: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa27066417"><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">USE</span> prices<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> sales<span class="token punctuation">.</span>february <span class="token keyword">SET</span> amount<span class="token operator">=</span>amount<span class="token operator">+</span><span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> <p> The changes to the <code class="literal"> february </code> table in the <code class="literal"> sales </code> database are logged in accordance with the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement; this occurs whether or not the <a class="link" href="use.html" title="15.8.4 USE Statement"> <code class="literal"> USE </code> </a> statement was issued. However, when using the row-based logging format and <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db=sales </code> </a> , changes made by the following <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> are not logged: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35599520"><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">USE</span> prices<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> prices<span class="token punctuation">.</span>march <span class="token keyword">SET</span> amount<span class="token operator">=</span>amount<span class="token number">-25</span><span class="token punctuation">;</span></code></pre> </div> <p> Even if the <code class="literal"> USE prices </code> statement were changed to <code class="literal"> USE sales </code> , the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement's effects would still not be written to the binary log. </p> <p> Another important difference in <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db </code> </a> handling for statement-based logging as opposed to the row-based logging occurs with regard to statements that refer to multiple databases. Suppose that the server is started with <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db=db1 </code> </a> , and the following statements are executed: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65042111"><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">USE</span> db1<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> db1<span class="token punctuation">.</span>table1<span class="token punctuation">,</span> db2<span class="token punctuation">.</span>table2 <span class="token keyword">SET</span> db1<span class="token punctuation">.</span>table1<span class="token punctuation">.</span>col1 <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">,</span> db2<span class="token punctuation">.</span>table2<span class="token punctuation">.</span>col2 <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span></code></pre> </div> <p> If you are using statement-based logging, the updates to both tables are written to the binary log. However, when using the row-based format, only the changes to <code class="literal"> table1 </code> are logged; <code class="literal"> table2 </code> is in a different database, so it is not changed by the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> . Now suppose that, instead of the <code class="literal"> USE db1 </code> statement, a <code class="literal"> USE db4 </code> statement had been used: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa95586039"><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">USE</span> db4<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> db1<span class="token punctuation">.</span>table1<span class="token punctuation">,</span> db2<span class="token punctuation">.</span>table2 <span class="token keyword">SET</span> db1<span class="token punctuation">.</span>table1<span class="token punctuation">.</span>col1 <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">,</span> db2<span class="token punctuation">.</span>table2<span class="token punctuation">.</span>col2 <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span></code></pre> </div> <p> In this case, the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement is not written to the binary log when using statement-based logging. However, when using row-based logging, the change to <code class="literal"> table1 </code> is logged, but not that to <code class="literal"> table2 </code> —in other words, only changes to tables in the database named by <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db </code> </a> are logged, and the choice of default database has no effect on this behavior. </p> </li> <li class="listitem"> <p> <a name="option_mysqld_binlog-ignore-db"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db"> <code class="option"> --binlog-ignore-db= <em class="replaceable"> <code> db_name </code> </em> </code> </a> </p> <a class="indexterm" name="idm46045140787312"> </a> <a class="indexterm" name="idm46045140785824"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog-ignore-db"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-ignore-db=name </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> </tbody> </table> </div> <p> This option affects binary logging in a manner similar to the way that <a class="link" href="replication-options-replica.html#option_mysqld_replicate-ignore-db"> <code class="option"> --replicate-ignore-db </code> </a> affects replication. </p> <p> The effects of this option depend on whether the statement-based or row-based logging format is in use, in the same way that the effects of <a class="link" href="replication-options-replica.html#option_mysqld_replicate-ignore-db"> <code class="option"> --replicate-ignore-db </code> </a> depend on whether statement-based or row-based replication is in use. You should keep in mind that the format used to log a given statement may not necessarily be the same as that indicated by the value of <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> . For example, DDL statements such as <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> and <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> are always logged as statements, without regard to the logging format in effect, so the following statement-based rules for <code class="option"> --binlog-ignore-db </code> always apply in determining whether or not the statement is logged. </p> <p> <b> Statement-based logging. </b> Tells the server to not log any statement where the default database (that is, the one selected by <a class="link" href="use.html" title="15.8.4 USE Statement"> <code class="literal"> USE </code> </a> ) is <em class="replaceable"> <code> db_name </code> </em> . </p> <p> When there is no default database, no <code class="option"> --binlog-ignore-db </code> options are applied, and such statements are always logged. (Bug #11829838, Bug #60188) </p> <p> <b> Row-based format. </b> Tells the server not to log updates to any tables in the database <em class="replaceable"> <code> db_name </code> </em> . The current database has no effect. </p> <p> When using statement-based logging, the following example does not work as you might expect. Suppose that the server is started with <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db"> <code class="option"> --binlog-ignore-db=sales </code> </a> and you issue the following statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa67112553"><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">USE</span> prices<span class="token punctuation">;</span> <span class="token keyword">UPDATE</span> sales<span class="token punctuation">.</span>january <span class="token keyword">SET</span> amount<span class="token operator">=</span>amount<span class="token operator">+</span><span class="token number">1000</span><span class="token punctuation">;</span></code></pre> </div> <p> The <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement <span class="emphasis"> <em> is </em> </span> logged in such a case because <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db"> <code class="option"> --binlog-ignore-db </code> </a> applies only to the default database (determined by the <a class="link" href="use.html" title="15.8.4 USE Statement"> <code class="literal"> USE </code> </a> statement). Because the <code class="literal"> sales </code> database was specified explicitly in the statement, the statement has not been filtered. However, when using row-based logging, the <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement's effects are <span class="emphasis"> <em> not </em> </span> written to the binary log, which means that no changes to the <code class="literal"> sales.january </code> table are logged; in this instance, <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db"> <code class="option"> --binlog-ignore-db=sales </code> </a> causes <span class="emphasis"> <em> all </em> </span> changes made to tables in the source's copy of the <code class="literal"> sales </code> database to be ignored for purposes of binary logging. </p> <p> To specify more than one database to ignore, use this option multiple times, once for each database. Because database names can contain commas, the list is treated as the name of a single database if you supply a comma-separated list. </p> <p> You should not use this option if you are using cross-database updates and you do not want these updates to be logged. </p> </li> </ul> </div> <p> <a name="replication-optvars-binlog-checksums"> </a> <b> Checksum options. </b> MySQL supports reading and writing of binary log checksums. These are enabled using the two options listed here: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a name="option_mysqld_binlog-checksum"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-checksum"> <code class="option"> --binlog-checksum={NONE|CRC32} </code> </a> </p> <a class="indexterm" name="idm46045140745104"> </a> <a class="indexterm" name="idm46045140743616"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog-checksum"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-checksum=type </code> </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> CRC32 </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> NONE </code> </p> <p class="valid-value"> <code class="literal"> CRC32 </code> </p> </td> </tr> </tbody> </table> </div> <p> Enabling this option causes the source to write checksums for events written to the binary log. Set to <code class="literal"> NONE </code> to disable, or the name of the algorithm to be used for generating checksums; currently, only CRC32 checksums are supported, and CRC32 is the default. You cannot change the setting for this option within a transaction. </p> </li> </ul> </div> <p> To control reading of checksums by the replica (from the relay log), use the <a class="link" href="replication-options-replica.html#sysvar_replica_sql_verify_checksum"> <code class="option"> --replica-sql-verify-checksum </code> </a> option. </p> <p> <b> Testing and debugging options. </b> The following binary log options are used in replication testing and debugging. They are not intended for use in normal operations. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a name="option_mysqld_max-binlog-dump-events"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_max-binlog-dump-events"> <code class="option"> --max-binlog-dump-events= <em class="replaceable"> <code> N </code> </em> </code> </a> </p> <a class="indexterm" name="idm46045140720368"> </a> <a class="indexterm" name="idm46045140718864"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for max-binlog-dump-events"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --max-binlog-dump-events=# </code> </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 0 </code> </td> </tr> </tbody> </table> </div> <p> This option is used internally by the MySQL test suite for replication testing and debugging. </p> </li> <li class="listitem"> <p> <a name="option_mysqld_sporadic-binlog-dump-fail"> </a> <a class="link" href="replication-options-binary-log.html#option_mysqld_sporadic-binlog-dump-fail"> <code class="option"> --sporadic-binlog-dump-fail </code> </a> </p> <a class="indexterm" name="idm46045140704624"> </a> <a class="indexterm" name="idm46045140703120"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for sporadic-binlog-dump-fail"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --sporadic-binlog-dump-fail[={OFF|ON}] </code> </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> This option is used internally by the MySQL test suite for replication testing and debugging. </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="replication-sysvars-binlog"> </a> System Variables Used with Binary Logging </h5> </div> </div> </div> <p> The following list describes system variables for controlling binary logging. They can be set at server startup and some of them can be changed at runtime using <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> <code class="literal"> SET </code> </a> . Server options used to control binary logging are listed earlier in this section. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a name="sysvar_binlog_cache_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_cache_size"> <code class="literal"> binlog_cache_size </code> </a> </p> <a class="indexterm" name="idm46045140685056"> </a> <a class="indexterm" name="idm46045140684016"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_cache_size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-cache-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_cache_size"> binlog_cache_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 32768 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 4096 </code> </td> </tr> <tr> <th> Maximum Value (64-bit platforms) </th> <td> <code class="literal"> 18446744073709547520 </code> </td> </tr> <tr> <th> Maximum Value (32-bit platforms) </th> <td> <code class="literal"> 4294963200 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> <tr> <th> <a class="link" href="server-system-variables.html#system-variables-block-size" title="Note"> Block Size </a> </th> <td> <code class="literal"> 4096 </code> </td> </tr> </tbody> </table> </div> <p> The size of the memory buffer to hold changes to the binary log during a transaction. </p> <p> When binary logging is enabled on the server (with the <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> system variable set to ON), a binary log cache is allocated for each client if the server supports any transactional storage engines. If the data for the transaction exceeds the space in the memory buffer, the excess data is stored in a temporary file. When binary log encryption is active on the server, the memory buffer is not encrypted, but any temporary file used to hold the binary log cache is encrypted. After each transaction is committed, the binary log cache is reset by clearing the memory buffer and truncating the temporary file if used. </p> <p> If you often use large transactions, you can increase this cache size to get better performance by reducing or eliminating the need to write to temporary files. The <a class="link" href="server-status-variables.html#statvar_Binlog_cache_use"> <code class="literal"> Binlog_cache_use </code> </a> and <a class="link" href="server-status-variables.html#statvar_Binlog_cache_disk_use"> <code class="literal"> Binlog_cache_disk_use </code> </a> status variables can be useful for tuning the size of this variable. See <a class="xref" href="binary-log.html" title="7.4.4 The Binary Log"> Section 7.4.4, “The Binary Log” </a> . </p> <p> <code class="literal"> binlog_cache_size </code> sets the size for the transaction cache only; the size of the statement cache is governed by the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_stmt_cache_size"> <code class="literal"> binlog_stmt_cache_size </code> </a> system variable. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_checksum"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_checksum"> <code class="literal"> binlog_checksum </code> </a> </p> <a class="indexterm" name="idm46045140637648"> </a> <a class="indexterm" name="idm46045140636560"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_checksum"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-checksum=type </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_checksum"> binlog_checksum </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> String </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> CRC32 </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> NONE </code> </p> <p class="valid-value"> <code class="literal"> CRC32 </code> </p> </td> </tr> </tbody> </table> </div> <p> When enabled, this variable causes the source to write a checksum for each event in the binary log. <code class="literal"> binlog_checksum </code> supports the values <code class="literal"> NONE </code> (which disables checksums) and <code class="literal"> CRC32 </code> . The default is <code class="literal"> CRC32 </code> . When <code class="literal"> binlog_checksum </code> is disabled (value <code class="literal"> NONE </code> ), the server verifies that it is writing only complete events to the binary log by writing and checking the event length (rather than a checksum) for each event. </p> <p> Setting this variable on the source to a value unrecognized by the replica causes the replica to set its own <code class="literal"> binlog_checksum </code> value to <code class="literal"> NONE </code> , and to stop replication with an error. If backward compatibility with older replicas is a concern, you may want to set the value explicitly to <code class="literal"> NONE </code> . </p> <p> Group Replication in MySQL 8.4 supports checksums, so group members may use the default setting. </p> <p> Changing the value of <code class="literal"> binlog_checksum </code> causes the binary log to be rotated, because checksums must be written for an entire binary log file, and never for only part of one. You cannot change the value of <code class="literal"> binlog_checksum </code> within a transaction. </p> <p> When binary log transaction compression is enabled using the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression"> <code class="literal"> binlog_transaction_compression </code> </a> system variable, checksums are not written for individual events in a compressed transaction payload. Instead a checksum is written for the GTID event, and a checksum for the compressed <code class="literal"> Transaction_payload_event </code> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_direct_non_transactional_updates"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_direct_non_transactional_updates"> <code class="literal"> binlog_direct_non_transactional_updates </code> </a> </p> <a class="indexterm" name="idm46045140595200"> </a> <a class="indexterm" name="idm46045140594160"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_direct_non_transactional_updates"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-direct-non-transactional-updates[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_direct_non_transactional_updates"> binlog_direct_non_transactional_updates </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> Due to concurrency issues, a replica can become inconsistent when a transaction contains updates to both transactional and nontransactional tables. MySQL tries to preserve causality among these statements by writing nontransactional statements to the transaction cache, which is flushed upon commit. However, problems arise when modifications done to nontransactional tables on behalf of a transaction become immediately visible to other connections because these changes may not be written immediately into the binary log. </p> <p> The <a class="link" href="replication-options-binary-log.html#sysvar_binlog_direct_non_transactional_updates"> <code class="literal"> binlog_direct_non_transactional_updates </code> </a> variable offers one possible workaround to this issue. By default, this variable is disabled. Enabling <a class="link" href="replication-options-binary-log.html#sysvar_binlog_direct_non_transactional_updates"> <code class="literal"> binlog_direct_non_transactional_updates </code> </a> causes updates to nontransactional tables to be written directly to the binary log, rather than to the transaction cache. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> <span class="emphasis"> <em> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_direct_non_transactional_updates"> <code class="literal"> binlog_direct_non_transactional_updates </code> </a> works only for statements that are replicated using the statement-based binary logging format </em> </span> ; that is, it works only when the value of <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is <code class="literal"> STATEMENT </code> , or when <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is <code class="literal"> MIXED </code> and a given statement is being replicated using the statement-based format. This variable has no effect when the binary log format is <code class="literal"> ROW </code> , or when <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is set to <code class="literal"> MIXED </code> and a given statement is replicated using the row-based format. </p> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> Before enabling this variable, you must make certain that there are no dependencies between transactional and nontransactional tables; an example of such a dependency would be the statement <code class="literal"> INSERT INTO myisam_table SELECT * FROM innodb_table </code> . Otherwise, such statements are likely to cause the replica to diverge from the source. </p> </div> <p> This variable has no effect when the binary log format is <code class="literal"> ROW </code> or <code class="literal"> MIXED </code> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_encryption"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_encryption"> <code class="literal"> binlog_encryption </code> </a> </p> <a class="indexterm" name="idm46045140551520"> </a> <a class="indexterm" name="idm46045140550480"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_encryption"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-encryption[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_encryption"> binlog_encryption </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> Enables encryption for binary log files and relay log files on this server. <code class="literal"> OFF </code> is the default. <code class="literal"> ON </code> sets encryption on for binary log files and relay log files. Binary logging does not need to be enabled on the server to enable encryption, so you can encrypt the relay log files on a replica that has no binary log. To use encryption, a keyring plugin must be installed and configured to supply MySQL Server's keyring service. For instructions to do this, see <a class="xref" href="keyring.html" title="8.4.4 The MySQL Keyring"> Section 8.4.4, “The MySQL Keyring” </a> . Any supported keyring plugin can be used to store binary log encryption keys. </p> <p> When you first start the server with binary log encryption enabled, a new binary log encryption key is generated before the binary log and relay logs are initialized. This key is used to encrypt a file password for each binary log file (if the server has binary logging enabled) and relay log file (if the server has replication channels), and further keys generated from the file passwords are used to encrypt the data in the files. Relay log files are encrypted for all channels, including Group Replication applier channels and new channels that are created after encryption is activated. The binary log index file and relay log index file are never encrypted. </p> <p> If you activate encryption while the server is running, a new binary log encryption key is generated at that time. The exception is if encryption was active previously on the server and was then disabled, in which case the binary log encryption key that was in use before is used again. The binary log file and relay log files are rotated immediately, and file passwords for the new files and all subsequent binary log files and relay log files are encrypted using this binary log encryption key. Existing binary log files and relay log files still present on the server are not automatically encrypted, but you can purge them if they are no longer needed. </p> <p> If you deactivate encryption by changing the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_encryption"> <code class="literal"> binlog_encryption </code> </a> system variable to <code class="literal"> OFF </code> , the binary log file and relay log files are rotated immediately and all subsequent logging is unencrypted. Previously encrypted files are not automatically decrypted, but the server is still able to read them. The <code class="literal"> BINLOG_ENCRYPTION_ADMIN </code> privilege (or the deprecated <a class="link" href="privileges-provided.html#priv_super"> <code class="literal"> SUPER </code> </a> privilege) is required to activate or deactivate encryption while the server is running. Group Replication applier channels are not included in the relay log rotation request, so unencrypted logging for these channels does not start until their logs are rotated in normal use. </p> <p> For more information on binary log file and relay log file encryption, see <a class="xref" href="replication-binlog-encryption.html" title="19.3.2 Encrypting Binary Log Files and Relay Log Files"> Section 19.3.2, “Encrypting Binary Log Files and Relay Log Files” </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_error_action"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_error_action"> <code class="literal"> binlog_error_action </code> </a> </p> <a class="indexterm" name="idm46045140514608"> </a> <a class="indexterm" name="idm46045140513568"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_error_action"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-error-action[=value] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_error_action"> binlog_error_action </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Enumeration </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ABORT_SERVER </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> IGNORE_ERROR </code> </p> <p class="valid-value"> <code class="literal"> ABORT_SERVER </code> </p> </td> </tr> </tbody> </table> </div> <p> Controls what happens when the server encounters an error such as not being able to write to, flush or synchronize the binary log, which can cause the source's binary log to become inconsistent and replicas to lose synchronization. </p> <p> This variable defaults to <code class="literal"> ABORT_SERVER </code> , which makes the server halt logging and shut down whenever it encounters such an error with the binary log. On restart, recovery proceeds as in the case of an unexpected server halt (see <a class="xref" href="replication-solutions-unexpected-replica-halt.html" title="19.4.2 Handling an Unexpected Halt of a Replica"> Section 19.4.2, “Handling an Unexpected Halt of a Replica” </a> ). </p> <p> When <code class="literal"> binlog_error_action </code> is set to <code class="literal"> IGNORE_ERROR </code> , if the server encounters such an error it continues the ongoing transaction, logs the error then halts logging, and continues performing updates. To resume binary logging <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> must be enabled again, which requires a server restart. This setting provides backward compatibility with older versions of MySQL. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_expire_logs_seconds"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds"> <code class="literal"> binlog_expire_logs_seconds </code> </a> </p> <a class="indexterm" name="idm46045140479408"> </a> <a class="indexterm" name="idm46045140478320"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_expire_logs_seconds"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-expire-logs-seconds=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds"> binlog_expire_logs_seconds </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 2592000 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 4294967295 </code> </td> </tr> <tr> <th> Unit </th> <td> seconds </td> </tr> </tbody> </table> </div> <p> Sets the binary log expiration period in seconds. After their expiration period ends, binary log files can be automatically removed. Possible removals happen at startup and when the binary log is flushed. Log flushing occurs as indicated in <a class="xref" href="server-logs.html" title="7.4 MySQL Server Logs"> Section 7.4, “MySQL Server Logs” </a> . </p> <p> The default binary log expiration period is 2592000 seconds, which equals 30 days (30*24*60*60 seconds). </p> <p> Automatic purging of the binary log can be disabled by setting the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_expire_logs_auto_purge"> <code class="literal"> binlog_expire_logs_auto_purge </code> </a> system variable to <code class="literal"> OFF </code> . This takes precedence over any setting for <code class="literal"> binlog_expire_logs_seconds </code> . </p> <p> To remove binary log files manually, use the <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> <code class="literal"> PURGE BINARY LOGS </code> </a> statement. See <a class="xref" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> Section 15.4.1.1, “PURGE BINARY LOGS Statement” </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_expire_logs_auto_purge"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_expire_logs_auto_purge"> <code class="literal"> binlog_expire_logs_auto_purge </code> </a> </p> <a class="indexterm" name="idm46045140439696"> </a> <a class="indexterm" name="idm46045140438592"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_expire_logs_auto_purge"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-expire-logs-auto-purge={ON|OFF} </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_expire_logs_auto_purge"> binlog_expire_logs_auto_purge </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ON </code> </td> </tr> </tbody> </table> </div> <p> Enables or disables automatic purging of binary log files. Setting this variable to <code class="literal"> ON </code> (the default) enables automatic purging; setting it to <code class="literal"> OFF </code> disables automatic purging. The interval to wait before purging is controlled by <a class="link" href="replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds"> <code class="literal"> binlog_expire_logs_seconds </code> </a> . </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Even if <code class="literal"> binlog_expire_logs_auto_purge </code> is <code class="literal"> ON </code> , setting <code class="literal"> binlog_expire_logs_seconds </code> to <code class="literal"> 0 </code> stops automatic purging from taking place. </p> </div> <p> This variable has no effect on <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> <code class="literal"> PURGE BINARY LOGS </code> </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_format"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> </p> <a class="indexterm" name="idm46045140405824"> </a> <a class="indexterm" name="idm46045140404736"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_format"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-format=format </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> binlog_format </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Enumeration </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ROW </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> MIXED </code> </p> <p class="valid-value"> <code class="literal"> STATEMENT </code> </p> <p class="valid-value"> <code class="literal"> ROW </code> </p> </td> </tr> </tbody> </table> </div> <p> This system variable sets the binary logging format, and can be any one of <code class="literal"> STATEMENT </code> , <code class="literal"> ROW </code> , or <code class="literal"> MIXED </code> . (See <a class="xref" href="replication-formats.html" title="19.2.1 Replication Formats"> Section 19.2.1, “Replication Formats” </a> .) The setting takes effect when binary logging is enabled on the server, which is the case when the <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> system variable is set to <code class="literal"> ON </code> . In MySQL 8.4, binary logging is enabled by default, and by default uses the row-based format. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> <code class="literal"> binlog_format </code> is deprecated, and subject to removal in a future version of MySQL. This implies that support for logging formats other than row-based is also subject to removal in a future release. Thus, only row-based logging should be employed for any new MySQL Replication setups. </p> </div> <p> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> can be set at startup or at runtime, except that under some conditions, changing this variable at runtime is not possible or causes replication to fail, as described later. </p> <p> The default is <code class="literal"> ROW </code> . <span class="emphasis"> <em> Exception </em> </span> : In NDB Cluster, the default is <code class="literal"> MIXED </code> ; statement-based replication is not supported for NDB Cluster. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> The rules governing when changes to this variable take effect and how long the effect lasts are the same as for other MySQL server system variables. For more information, see <a class="xref" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> Section 15.7.6.1, “SET Syntax for Variable Assignment” </a> . </p> <p> When <code class="literal"> MIXED </code> is specified, statement-based replication is used, except for cases where only row-based replication is guaranteed to lead to proper results. For example, this happens when statements contain loadable functions or the <a class="link" href="miscellaneous-functions.html#function_uuid"> <code class="literal"> UUID() </code> </a> function. </p> <p> For details of how stored programs (stored procedures and functions, triggers, and events) are handled when each binary logging format is set, see <a class="xref" href="stored-programs-logging.html" title="27.7 Stored Program Binary Logging"> Section 27.7, “Stored Program Binary Logging” </a> . </p> <p> There are exceptions when you cannot switch the replication format at runtime: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> The replication format cannot be changed from within a stored function or a trigger. </p> </li> <li class="listitem"> <p> If a session has open temporary tables, the replication format cannot be changed for the session ( <code class="literal"> SET @@SESSION.binlog_format </code> ). </p> </li> <li class="listitem"> <p> If any replication channel has open temporary tables, the replication format cannot be changed globally ( <code class="literal"> SET @@GLOBAL.binlog_format </code> or <code class="literal"> SET @@PERSIST.binlog_format </code> ). </p> </li> <li class="listitem"> <p> If any replication channel applier thread is currently running, the replication format cannot be changed globally ( <code class="literal"> SET @@GLOBAL.binlog_format </code> or <code class="literal"> SET @@PERSIST.binlog_format </code> ). </p> </li> </ul> </div> <p> Trying to switch the replication format in any of these cases (or attempting to set the current replication format) results in an error. You can, however, use <code class="literal"> PERSIST_ONLY </code> ( <code class="literal"> SET @@PERSIST_ONLY.binlog_format </code> ) to change the replication format at any time, because this action does not modify the runtime global system variable value, and takes effect only after a server restart. </p> <p> Switching the replication format at runtime is not recommended when any temporary tables exist, because temporary tables are logged only when using statement-based replication, whereas with row-based replication and mixed replication, they are not logged. </p> <p> Changing the logging format on a replication source server does not cause a replica to change its logging format to match. Switching the replication format while replication is ongoing can cause issues if a replica has binary logging enabled, and the change results in the replica using <code class="literal"> STATEMENT </code> format logging while the source is using <code class="literal"> ROW </code> or <code class="literal"> MIXED </code> format logging. A replica is not able to convert binary log entries received in <code class="literal"> ROW </code> logging format to <code class="literal"> STATEMENT </code> format for use in its own binary log, so this situation can cause replication to fail. For more information, see <a class="xref" href="binary-log-setting.html" title="7.4.4.2 Setting The Binary Log Format"> Section 7.4.4.2, “Setting The Binary Log Format” </a> . </p> <p> The binary log format affects the behavior of the following server options: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db"> <code class="option"> --replicate-do-db </code> </a> </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-replica.html#option_mysqld_replicate-ignore-db"> <code class="option"> --replicate-ignore-db </code> </a> </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db"> <code class="option"> --binlog-do-db </code> </a> </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db"> <code class="option"> --binlog-ignore-db </code> </a> </p> </li> </ul> </div> <p> These effects are discussed in detail in the descriptions of the individual options. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_group_commit_sync_delay"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> </p> <a class="indexterm" name="idm46045140331024"> </a> <a class="indexterm" name="idm46045140329936"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_group_commit_sync_delay"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-group-commit-sync-delay=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> binlog_group_commit_sync_delay </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 1000000 </code> </td> </tr> <tr> <th> Unit </th> <td> microseconds </td> </tr> </tbody> </table> </div> <p> Controls how many microseconds the binary log commit waits before synchronizing the binary log file to disk. By default <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> is set to 0, meaning that there is no delay. Setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> to a microsecond delay enables more transactions to be synchronized together to disk at once, reducing the overall time to commit a group of transactions because the larger groups require fewer time units per group. </p> <p> When <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog=0 </code> </a> or <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog=1 </code> </a> is set, the delay specified by <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> is applied for every binary log commit group before synchronization (or in the case of <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog=0 </code> </a> , before proceeding). When <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog </code> </a> is set to a value <span class="emphasis"> <em> n </em> </span> greater than 1, the delay is applied after every <span class="emphasis"> <em> n </em> </span> binary log commit groups. </p> <p> Setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> can increase the number of parallel committing transactions on any server that has (or might have after a failover) a replica, and therefore can increase parallel execution on the replicas. To benefit from this effect, the replica servers must have <a class="link" href="replication-options-replica.html#sysvar_replica_parallel_type"> <code class="literal"> replica_parallel_type=LOGICAL_CLOCK </code> </a> set. It is important to take into account both source and replica throughput when you are setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> . </p> <p> Setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> can also reduce the number of <code class="literal"> fsync() </code> calls to the binary log on any server (source or replica) that has a binary log. </p> <p> Note that setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> increases the latency of transactions on the server, which might affect client applications. Also, on highly concurrent workloads, it is possible for the delay to increase contention and therefore reduce throughput. Typically, the benefits of setting a delay outweigh the drawbacks, but tuning should always be carried out to determine the optimal setting. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_group_commit_sync_no_delay_count"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_no_delay_count"> <code class="literal"> binlog_group_commit_sync_no_delay_count </code> </a> </p> <a class="indexterm" name="idm46045140278208"> </a> <a class="indexterm" name="idm46045140277120"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_group_commit_sync_no_delay_count"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-group-commit-sync-no-delay-count=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_no_delay_count"> binlog_group_commit_sync_no_delay_count </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 100000 </code> </td> </tr> </tbody> </table> </div> <p> The maximum number of transactions to wait for before aborting the current delay as specified by <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> . If <a class="link" href="replication-options-binary-log.html#sysvar_binlog_group_commit_sync_delay"> <code class="literal"> binlog_group_commit_sync_delay </code> </a> is set to 0, then this option has no effect. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_max_flush_queue_time"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_max_flush_queue_time"> <code class="literal"> binlog_max_flush_queue_time </code> </a> </p> <a class="indexterm" name="idm46045140244960"> </a> <a class="indexterm" name="idm46045140243856"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_max_flush_queue_time"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-max-flush-queue-time=# </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_max_flush_queue_time"> binlog_max_flush_queue_time </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 100000 </code> </td> </tr> <tr> <th> Unit </th> <td> microseconds </td> </tr> </tbody> </table> </div> <p> <code class="literal"> binlog_max_flush_queue_time </code> is deprecated, and is marked for eventual removal in a future MySQL release. Formerly, this system variable controlled the time in microseconds to continue reading transactions from the flush queue before proceeding with group commit. It no longer has any effect. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_order_commits"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_order_commits"> <code class="literal"> binlog_order_commits </code> </a> </p> <a class="indexterm" name="idm46045140209296"> </a> <a class="indexterm" name="idm46045140208256"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_order_commits"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-order-commits[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_order_commits"> binlog_order_commits </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ON </code> </td> </tr> </tbody> </table> </div> <p> When this variable is enabled on a replication source server (which is the default), transaction commit instructions issued to storage engines are serialized on a single thread, so that transactions are always committed in the same order as they are written to the binary log. Disabling this variable permits transaction commit instructions to be issued using multiple threads. Used in combination with binary log group commit, this prevents the commit rate of a single transaction being a bottleneck to throughput, and might therefore produce a performance improvement. </p> <p> Transactions are written to the binary log at the point when all the storage engines involved have confirmed that the transaction is prepared to commit. The binary log group commit logic then commits a group of transactions after their binary log write has taken place. When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_order_commits"> <code class="literal"> binlog_order_commits </code> </a> is disabled, because multiple threads are used for this process, transactions in a commit group might be committed in a different order from their order in the binary log. (Transactions from a single client always commit in chronological order.) In many cases this does not matter, as operations carried out in separate transactions should produce consistent results, and if that is not the case, a single transaction ought to be used instead. </p> <p> If you want to ensure that the transaction history on the source and on a multithreaded replica remains identical, set <a class="link" href="replication-options-replica.html#sysvar_replica_preserve_commit_order"> <code class="literal"> replica_preserve_commit_order=1 </code> </a> on the replica. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_rotate_encryption_master_key_at_startup"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_rotate_encryption_master_key_at_startup"> <code class="literal"> binlog_rotate_encryption_master_key_at_startup </code> </a> </p> <a class="indexterm" name="idm46045140177856"> </a> <a class="indexterm" name="idm46045140176736"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_rotate_encryption_master_key_at_startup"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-rotate-encryption-master-key-at-startup[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_rotate_encryption_master_key_at_startup"> binlog_rotate_encryption_master_key_at_startup </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> Specifies whether or not the binary log master key is rotated at server startup. The binary log master key is the binary log encryption key that is used to encrypt file passwords for the binary log files and relay log files on the server. When a server is started for the first time with binary log encryption enabled ( <a class="link" href="replication-options-binary-log.html#sysvar_binlog_encryption"> <code class="literal"> binlog_encryption=ON </code> </a> ), a new binary log encryption key is generated and used as the binary log master key. If the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_rotate_encryption_master_key_at_startup"> <code class="literal"> binlog_rotate_encryption_master_key_at_startup </code> </a> system variable is also set to <code class="literal"> ON </code> , whenever the server is restarted, a further binary log encryption key is generated and used as the binary log master key for all subsequent binary log files and relay log files. If the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_rotate_encryption_master_key_at_startup"> <code class="literal"> binlog_rotate_encryption_master_key_at_startup </code> </a> system variable is set to <code class="literal"> OFF </code> , which is the default, the existing binary log master key is used again after the server restarts. For more information on binary log encryption keys and the binary log master key, see <a class="xref" href="replication-binlog-encryption.html" title="19.3.2 Encrypting Binary Log Files and Relay Log Files"> Section 19.3.2, “Encrypting Binary Log Files and Relay Log Files” </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_row_event_max_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_event_max_size"> <code class="literal"> binlog_row_event_max_size </code> </a> </p> <a class="indexterm" name="idm46045140145120"> </a> <a class="indexterm" name="idm46045140144016"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog-row-event-max-size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-row-event-max-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_event_max_size"> binlog_row_event_max_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 8192 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 256 </code> </td> </tr> <tr> <th> Maximum Value (64-bit platforms) </th> <td> <code class="literal"> 18446744073709551615 </code> </td> </tr> <tr> <th> Maximum Value (32-bit platforms) </th> <td> <code class="literal"> 4294967295 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> </tbody> </table> </div> <p> When row-based binary logging is used, this setting is a soft limit on the maximum size of a row-based binary log event, in bytes. Where possible, rows stored in the binary log are grouped into events with a size not exceeding the value of this setting. If an event cannot be split, the maximum size can be exceeded. The default is 8192 bytes. </p> <p> This global system variable is read-only and can be set only at server startup. Its value can therefore only be modified by using the <code class="literal"> PERSIST_ONLY </code> keyword or the <code class="literal"> @@persist_only </code> qualifier with the <a class="link" href="set.html" title="13.3.6 The SET Type"> <code class="literal"> SET </code> </a> statement. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_row_image"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_image"> <code class="literal"> binlog_row_image </code> </a> </p> <a class="indexterm" name="idm46045140106528"> </a> <a class="indexterm" name="idm46045140105440"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_row_image"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-row-image=image_type </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_image"> binlog_row_image </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Enumeration </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> full </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> full </code> (Log all columns) </p> <p class="valid-value"> <code class="literal"> minimal </code> (Log only changed columns, and columns needed to identify rows) </p> <p class="valid-value"> <code class="literal"> noblob </code> (Log all columns, except for unneeded BLOB and TEXT columns) </p> </td> </tr> </tbody> </table> </div> <p> For MySQL row-based replication, this variable determines how row images are written to the binary log. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> In MySQL row-based replication, each row change event contains two images, a <span class="quote"> “ <span class="quote"> before </span> ” </span> image whose columns are matched against when searching for the row to be updated, and an <span class="quote"> “ <span class="quote"> after </span> ” </span> image containing the changes. Normally, MySQL logs full rows (that is, all columns) for both the before and after images. However, it is not strictly necessary to include every column in both images, and we can often save disk, memory, and network usage by logging only those columns which are actually required. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> When deleting a row, only the before image is logged, since there are no changed values to propagate following the deletion. When inserting a row, only the after image is logged, since there is no existing row to be matched. Only when updating a row are both the before and after images required, and both written to the binary log. </p> </div> <p> For the before image, it is necessary only that the minimum set of columns required to uniquely identify rows is logged. If the table containing the row has a primary key, then only the primary key column or columns are written to the binary log. Otherwise, if the table has a unique key all of whose columns are <code class="literal"> NOT NULL </code> , then only the columns in the unique key need be logged. (If the table has neither a primary key nor a unique key without any <code class="literal"> NULL </code> columns, then all columns must be used in the before image, and logged.) In the after image, it is necessary to log only the columns which have actually changed. </p> <p> You can cause the server to log full or minimal rows using the <code class="literal"> binlog_row_image </code> system variable. This variable actually takes one of three possible values, as shown in the following list: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <code class="literal"> full </code> : Log all columns in both the before image and the after image. </p> </li> <li class="listitem"> <p> <code class="literal"> minimal </code> : Log only those columns in the before image that are required to identify the row to be changed; log only those columns in the after image where a value was specified by the SQL statement, or generated by auto-increment. </p> </li> <li class="listitem"> <p> <code class="literal"> noblob </code> : Log all columns (same as <code class="literal"> full </code> ), except for <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> and <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> columns that are not required to identify rows, or that have not changed. </p> </li> </ul> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> This variable is not supported by NDB Cluster; setting it has no effect on the logging of <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables. </p> </div> <p> The default value is <code class="literal"> full </code> . </p> <p> When using <code class="literal"> minimal </code> or <code class="literal"> noblob </code> , deletes and updates are guaranteed to work correctly for a given table if and only if the following conditions are true for both the source and destination tables: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> All columns must be present and in the same order; each column must use the same data type as its counterpart in the other table. </p> </li> <li class="listitem"> <p> The tables must have identical primary key definitions. </p> </li> </ul> </div> <p> (In other words, the tables must be identical with the possible exception of indexes that are not part of the tables' primary keys.) </p> <p> If these conditions are not met, it is possible that the primary key column values in the destination table may prove insufficient to provide a unique match for a delete or update. In this event, no warning or error is issued; the source and replica silently diverge, thus breaking consistency. </p> <p> Setting this variable has no effect when the binary logging format is <code class="literal"> STATEMENT </code> . When <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is <code class="literal"> MIXED </code> , the setting for <code class="literal"> binlog_row_image </code> is applied to changes that are logged using row-based format, but this setting has no effect on changes logged as statements. </p> <p> Setting <code class="literal"> binlog_row_image </code> on either the global or session level does not cause an implicit commit; this means that this variable can be changed while a transaction is in progress without affecting the transaction. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_row_metadata"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_metadata"> <code class="literal"> binlog_row_metadata </code> </a> </p> <a class="indexterm" name="idm46045140044288"> </a> <a class="indexterm" name="idm46045140043248"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_row_metadata"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-row-metadata=metadata_type </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_metadata"> binlog_row_metadata </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Enumeration </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> MINIMAL </code> </td> </tr> <tr> <th> Valid Values </th> <td> <p class="valid-value"> <code class="literal"> FULL </code> (All metadata is included) </p> <p class="valid-value"> <code class="literal"> MINIMAL </code> (Limit included metadata) </p> </td> </tr> </tbody> </table> </div> <p> Configures the amount of table metadata added to the binary log when using row-based logging. When set to <code class="literal"> MINIMAL </code> , the default, only metadata related to <code class="literal"> SIGNED </code> flags, column character set and geometry types are logged. When set to <code class="literal"> FULL </code> complete metadata for tables is logged, such as column name, <a class="link" href="enum.html" title="13.3.5 The ENUM Type"> <code class="literal"> ENUM </code> </a> or <code class="literal"> SET </code> string values, <code class="literal"> PRIMARY KEY </code> information, and so on. </p> <p> The extended metadata serves the following purposes: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Replicas use the metadata to transfer data when its table structure is different from the source's. </p> </li> <li class="listitem"> <p> External software can use the metadata to decode row events and store the data into external databases, such as a data warehouse. </p> </li> </ul> </div> </li> <li class="listitem"> <p> <a name="sysvar_binlog_row_value_options"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_value_options"> <code class="literal"> binlog_row_value_options </code> </a> </p> <a class="indexterm" name="idm46045140006704"> </a> <a class="indexterm" name="idm46045140005600"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_row_value_options"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-row-value-options=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_value_options"> binlog_row_value_options </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Set </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> </code> </td> </tr> <tr> <th> Valid Values </th> <td> <code class="literal"> PARTIAL_JSON </code> </td> </tr> </tbody> </table> </div> <p> When set to <code class="literal"> PARTIAL_JSON </code> , this enables use of a space-efficient binary log format for updates that modify only a small portion of a JSON document, which causes row-based replication to write only the modified parts of the JSON document to the after-image for the update in the binary log, rather than writing the full document (see <a class="xref" href="json.html#json-partial-updates" title="Partial Updates of JSON Values"> Partial Updates of JSON Values </a> ). This works for an <a class="link" href="update.html" title="15.2.17 UPDATE Statement"> <code class="literal"> UPDATE </code> </a> statement which modifies a JSON column using any sequence of <a class="link" href="json-modification-functions.html#function_json-set"> <code class="literal"> JSON_SET() </code> </a> , <a class="link" href="json-modification-functions.html#function_json-replace"> <code class="literal"> JSON_REPLACE() </code> </a> , and <a class="link" href="json-modification-functions.html#function_json-remove"> <code class="literal"> JSON_REMOVE() </code> </a> . If the server is unable to generate a partial update, the full document is used instead. </p> <p> The default value is an empty string, which disables use of the format. To unset <code class="literal"> binlog_row_value_options </code> and revert to writing the full JSON document, set its value to the empty string. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> <code class="literal"> binlog_row_value_options=PARTIAL_JSON </code> takes effect only when binary logging is enabled and <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="literal"> binlog_format </code> </a> is set to <code class="literal"> ROW </code> or <code class="literal"> MIXED </code> . Statement-based replication <span class="emphasis"> <em> always </em> </span> logs only the modified parts of the JSON document, regardless of any value set for <code class="literal"> binlog_row_value_options </code> . To maximize the amount of space saved, use <a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_image"> <code class="literal"> binlog_row_image=NOBLOB </code> </a> or <code class="literal"> binlog_row_image=MINIMAL </code> together with this option. <code class="literal"> binlog_row_image=FULL </code> saves less space than either of these, since the full JSON document is stored in the before-image, and the partial update is stored only in the after-image. </p> <p> <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files"> <span class="command"> <strong> mysqlbinlog </strong> </span> </a> output includes partial JSON updates in the form of events encoded as base-64 strings using <a class="link" href="binlog.html" title="15.7.8.1 BINLOG Statement"> <code class="literal"> BINLOG </code> </a> statements. If the <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_verbose"> <code class="option"> --verbose </code> </a> option is specified, <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files"> <span class="command"> <strong> mysqlbinlog </strong> </span> </a> displays the partial JSON updates as readable JSON using pseudo-SQL statements. </p> <p> MySQL Replication generates an error if a modification cannot be applied to the JSON document on the replica. This includes a failure to find the path. Be aware that, even with this and other safety checks, if a JSON document on a replica has diverged from that on the source and a partial update is applied, it remains theoretically possible to produce a valid but unexpected JSON document on the replica. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_rows_query_log_events"> </a> <code class="literal"> binlog_rows_query_log_events </code> </p> <a class="indexterm" name="idm46045139954656"> </a> <a class="indexterm" name="idm46045139953552"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_rows_query_log_events"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-rows-query-log-events[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_rows_query_log_events"> binlog_rows_query_log_events </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> This system variable affects row-based logging only. When enabled, it causes the server to write informational log events such as row query log events into its binary log. This information can be used for debugging and related purposes, such as obtaining the original query issued on the source when it cannot be reconstructed from the row updates. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> These informational events are normally ignored by MySQL programs reading the binary log and so cause no issues when replicating or restoring from backup. To view them, increase the verbosity level by using mysqlbinlog's <a class="link" href="mysqlbinlog.html#option_mysqlbinlog_verbose"> <code class="option"> --verbose </code> </a> option twice, either as <code class="option"> -vv </code> or <code class="option"> --verbose --verbose </code> . </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_stmt_cache_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_stmt_cache_size"> <code class="literal"> binlog_stmt_cache_size </code> </a> </p> <a class="indexterm" name="idm46045139924608"> </a> <a class="indexterm" name="idm46045139923568"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_stmt_cache_size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-stmt-cache-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_stmt_cache_size"> binlog_stmt_cache_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 32768 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 4096 </code> </td> </tr> <tr> <th> Maximum Value (64-bit platforms) </th> <td> <code class="literal"> 18446744073709547520 </code> </td> </tr> <tr> <th> Maximum Value (32-bit platforms) </th> <td> <code class="literal"> 4294963200 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> <tr> <th> <a class="link" href="server-system-variables.html#system-variables-block-size" title="Note"> Block Size </a> </th> <td> <code class="literal"> 4096 </code> </td> </tr> </tbody> </table> </div> <p> The size of the memory buffer for the binary log to hold nontransactional statements issued during a transaction. </p> <p> When binary logging is enabled on the server (with the <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> system variable set to ON), separate binary log transaction and statement caches are allocated for each client if the server supports any transactional storage engines. If the data for the nontransactional statements used in the transaction exceeds the space in the memory buffer, the excess data is stored in a temporary file. When binary log encryption is active on the server, the memory buffer is not encrypted, but any temporary file used to hold the binary log cache is encrypted. After each transaction is committed, the binary log statement cache is reset by clearing the memory buffer and truncating the temporary file if used. </p> <p> If you often use large nontransactional statements during transactions, you can increase this cache size to get better performance by reducing or eliminating the need to write to temporary files. The <a class="link" href="server-status-variables.html#statvar_Binlog_stmt_cache_use"> <code class="literal"> Binlog_stmt_cache_use </code> </a> and <a class="link" href="server-status-variables.html#statvar_Binlog_stmt_cache_disk_use"> <code class="literal"> Binlog_stmt_cache_disk_use </code> </a> status variables can be useful for tuning the size of this variable. See <a class="xref" href="binary-log.html" title="7.4.4 The Binary Log"> Section 7.4.4, “The Binary Log” </a> . </p> <p> The <a class="link" href="replication-options-binary-log.html#sysvar_binlog_cache_size"> <code class="literal"> binlog_cache_size </code> </a> system variable sets the size for the transaction cache. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_transaction_compression"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression"> <code class="literal"> binlog_transaction_compression </code> </a> </p> <a class="indexterm" name="idm46045139877504"> </a> <a class="indexterm" name="idm46045139876400"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_transaction_compression"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-transaction-compression[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression"> binlog_transaction_compression </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> Enables compression for transactions that are written to binary log files on this server. <code class="literal"> OFF </code> is the default. Use the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression_level_zstd"> <code class="literal"> binlog_transaction_compression_level_zstd </code> </a> system variable to set the level for the <code class="literal"> zstd </code> algorithm that is used for compression. </p> <p> Setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression"> <code class="literal"> binlog_transaction_compression </code> </a> has no immediate effect but rather applies to all subsequent <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement"> <code class="literal"> START REPLICA </code> </a> statements. </p> <p> When binary log transaction compression is enabled, transaction payloads are compressed and then written to the binary log file as a single event ( <code class="literal"> Transaction_payload_event </code> ). Compressed transaction payloads remain in a compressed state while they are sent in the replication stream to replicas, other Group Replication group members, or clients such as <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files"> <span class="command"> <strong> mysqlbinlog </strong> </span> </a> , and are written to the relay log still in their compressed state. Binary log transaction compression therefore saves storage space both on the originator of the transaction and on the recipient (and for their backups), and saves network bandwidth when the transactions are sent between server instances. </p> <p> For <code class="literal"> binlog_transaction_compression=ON </code> to have a direct effect, binary logging must be enabled on the server. When a MySQL 8.4 server instance has no binary log, it can receive, handle, and display compressed transaction payloads regardless of its value for <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression"> <code class="literal"> binlog_transaction_compression </code> </a> . Compressed transaction payloads received by such server instances are written in their compressed state to the relay log, so they benefit indirectly from compression carried out by other servers in the replication topology. </p> <p> This system variable cannot be changed within the context of a transaction. Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> For more information on binary log transaction compression, including details of what events are and are not compressed, and changes in behavior when transaction compression is in use, see <a class="xref" href="binary-log-transaction-compression.html" title="7.4.4.5 Binary Log Transaction Compression"> Section 7.4.4.5, “Binary Log Transaction Compression” </a> . </p> <p> You can use the <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_transaction_compression"> <code class="literal"> ndb_log_transaction_compression </code> </a> system variable to enable this feature for <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> . In addition, setting <code class="option"> --binlog-transaction-compression=ON </code> on the command line or in a <code class="filename"> my.cnf </code> file causes <code class="literal"> ndb_log_transaction_compression </code> to be enabled on server startup. See the description of the variable for further information. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_transaction_compression_level_zstd"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression_level_zstd"> <code class="literal"> binlog_transaction_compression_level_zstd </code> </a> </p> <a class="indexterm" name="idm46045139831872"> </a> <a class="indexterm" name="idm46045139830752"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_transaction_compression_level_zstd"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-transaction-compression-level-zstd=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression_level_zstd"> binlog_transaction_compression_level_zstd </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global, Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 3 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 1 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 22 </code> </td> </tr> </tbody> </table> </div> <p> Sets the compression level for binary log transaction compression on this server, which is enabled by the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression"> <code class="literal"> binlog_transaction_compression </code> </a> system variable. The value is an integer that determines the compression effort, from 1 (the lowest effort) to 22 (the highest effort). If you do not specify this system variable, the compression level is set to 3. </p> <p> Setting <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_compression_level_zstd"> <code class="literal"> binlog_transaction_compression_level_zstd </code> </a> has no immediate effect but rather applies to all subsequent <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement"> <code class="literal"> START REPLICA </code> </a> statements. </p> <p> As the compression level increases, the data compression ratio increases, which reduces the storage space and network bandwidth required for the transaction payload. However, the effort required for data compression also increases, taking time and CPU and memory resources on the originating server. Increases in the compression effort do not have a linear relationship to increases in the data compression ratio. </p> <p> This system variable cannot be changed within the context of a transaction. Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> This variable has no effect on logging of transactions on <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables; use <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_transaction_compression_level_zstd"> <code class="literal"> ndb_log_transaction_compression_level_zstd </code> </a> instead. </p> </li> <li class="listitem"> <p> <a name="sysvar_binlog_transaction_dependency_history_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_dependency_history_size"> <code class="literal"> binlog_transaction_dependency_history_size </code> </a> </p> <a class="indexterm" name="idm46045139791152"> </a> <a class="indexterm" name="idm46045139790032"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for binlog_transaction_dependency_history_size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --binlog-transaction-dependency-history-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_binlog_transaction_dependency_history_size"> binlog_transaction_dependency_history_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 25000 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 1 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 1000000 </code> </td> </tr> </tbody> </table> </div> <p> Sets an upper limit on the number of row hashes which are kept in memory and used for looking up the transaction that last modified a given row. Once this number of hashes has been reached, the history is purged. </p> </li> <li class="listitem"> <p> <a name="sysvar_log_bin"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> </p> <a class="indexterm" name="idm46045139760352"> </a> <a class="indexterm" name="idm46045139759280"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log_bin"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> log_bin </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> </tbody> </table> </div> <p> Shows the status of binary logging on the server, either enabled ( <code class="literal"> ON </code> ) or disabled ( <code class="literal"> OFF </code> ). With binary logging enabled, the server logs all statements that change data to the binary log, which is used for backup and replication. <code class="literal"> ON </code> means that the binary log is available, <code class="literal"> OFF </code> means that it is not in use. The <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin </code> </a> option can be used to specify a base name and location for the binary log. </p> <p> In earlier MySQL versions, binary logging was disabled by default, and was enabled if you specified the <code class="option"> --log-bin </code> option. Binary logging is enabled by default, with the <code class="literal"> log_bin </code> system variable set to <code class="literal"> ON </code> , whether or not you specify the <code class="option"> --log-bin </code> option. The exception is if you use <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> to initialize the data directory manually by invoking it with the <code class="option"> --initialize </code> or <code class="option"> --initialize-insecure </code> option, when binary logging is disabled by default. It is possible to enable binary logging in this case by specifying the <code class="option"> --log-bin </code> option. </p> <p> If the <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --skip-log-bin </code> </a> or <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --disable-log-bin </code> </a> option is specified at startup, binary logging is disabled, with the <code class="literal"> log_bin </code> system variable set to <code class="literal"> OFF </code> . If either of these options is specified and <code class="option"> --log-bin </code> is also specified, the option specified later takes precedence. </p> <p> For information on the format and management of the binary log, see <a class="xref" href="binary-log.html" title="7.4.4 The Binary Log"> Section 7.4.4, “The Binary Log” </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_log_bin_basename"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_basename"> <code class="literal"> log_bin_basename </code> </a> </p> <a class="indexterm" name="idm46045139724320"> </a> <a class="indexterm" name="idm46045139723232"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log_bin_basename"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_basename"> log_bin_basename </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <p> Holds the base name and path for the binary log files, which can be set with the <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin </code> </a> server option. The maximum variable length is 256. In MySQL 8.4, if the <code class="option"> --log-bin </code> option is not supplied, the default base name is <code class="filename"> binlog </code> . For compatibility with MySQL 5.7, if the <code class="option"> --log-bin </code> option is supplied with no string or with an empty string, the default base name is <code class="filename"> <em class="replaceable"> <code> host_name </code> </em> -bin </code> , using the name of the host machine. The default location is the data directory. </p> </li> <li class="listitem"> <p> <a name="sysvar_log_bin_index"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_index"> <code class="literal"> log_bin_index </code> </a> </p> <a class="indexterm" name="idm46045139699168"> </a> <a class="indexterm" name="idm46045139698080"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log-bin-index"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-bin-index=file_name </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_index"> log_bin_index </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> File name </td> </tr> </tbody> </table> </div> <p> Holds the base name and path for the binary log index file, which can be set with the <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin-index"> <code class="option"> --log-bin-index </code> </a> server option. The maximum variable length is 256. </p> </li> <li class="listitem"> <p> <a name="sysvar_log_bin_trust_function_creators"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_trust_function_creators"> <code class="literal"> log_bin_trust_function_creators </code> </a> </p> <a class="indexterm" name="idm46045139674896"> </a> <a class="indexterm" name="idm46045139673792"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log_bin_trust_function_creators"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-bin-trust-function-creators[={OFF|ON}] </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_bin_trust_function_creators"> log_bin_trust_function_creators </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> This variable applies when binary logging is enabled. It controls whether stored function creators can be trusted not to create stored functions that may cause unsafe events to be written to the binary log. If set to 0 (the default), users are not permitted to create or alter stored functions unless they have the <a class="link" href="privileges-provided.html#priv_super"> <code class="literal"> SUPER </code> </a> privilege in addition to the <a class="link" href="privileges-provided.html#priv_create-routine"> <code class="literal"> CREATE ROUTINE </code> </a> or <a class="link" href="privileges-provided.html#priv_alter-routine"> <code class="literal"> ALTER ROUTINE </code> </a> privilege. A setting of 0 also enforces the restriction that a function must be declared with the <code class="literal"> DETERMINISTIC </code> characteristic, or with the <code class="literal"> READS SQL DATA </code> or <code class="literal"> NO SQL </code> characteristic. If the variable is set to 1, MySQL does not enforce these restrictions on stored function creation. This variable also applies to trigger creation. See <a class="xref" href="stored-programs-logging.html" title="27.7 Stored Program Binary Logging"> Section 27.7, “Stored Program Binary Logging” </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_log_replica_updates"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> log_replica_updates </code> </a> </p> <a class="indexterm" name="idm46045139639920"> </a> <a class="indexterm" name="idm46045139638880"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log_replica_updates"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-replica-updates[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> log_replica_updates </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ON </code> </td> </tr> </tbody> </table> </div> <p> <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> log_replica_updates </code> </a> specifies whether updates received by a replica server from a replication source server should be logged to the replica's own binary log. </p> <p> Enabling this variable causes the replica to write the updates that are received from a source and performed by the replication SQL thread to the replica's own binary log. Binary logging, which is controlled by the <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --log-bin </code> </a> option and is enabled by default, must also be enabled on the replica for updates to be logged. See <a class="xref" href="replication-options.html" title="19.1.6 Replication and Binary Logging Options and Variables"> Section 19.1.6, “Replication and Binary Logging Options and Variables” </a> . <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> log_replica_updates </code> </a> is enabled by default, unless you specify <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin"> <code class="option"> --skip-log-bin </code> </a> to disable binary logging, in which case MySQL also disables replica update logging by default. If you need to disable replica update logging when binary logging is enabled, specify <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="option"> --log-replica-updates=OFF </code> </a> at replica server startup. </p> <p> Enabling <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> log_replica_updates </code> </a> enables replication servers to be chained. For example, you might want to set up replication servers using this arrangement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa99277481"><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-none">A -&gt; B -&gt; C</code></pre> </div> <p> Here, <code class="literal"> A </code> serves as the source for the replica <code class="literal"> B </code> , and <code class="literal"> B </code> serves as the source for the replica <code class="literal"> C </code> . For this to work, <code class="literal"> B </code> must be both a source <span class="emphasis"> <em> and </em> </span> a replica. With binary logging enabled and <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> log_replica_updates </code> </a> enabled, which are the default settings, updates received from <code class="literal"> A </code> are logged by <code class="literal"> B </code> to its binary log, and can therefore be passed on to <code class="literal"> C </code> . </p> </li> <li class="listitem"> <p> <a name="sysvar_log_slave_updates"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_slave_updates"> <code class="literal"> log_slave_updates </code> </a> </p> <a class="indexterm" name="idm46045139596240"> </a> <a class="indexterm" name="idm46045139595200"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log_slave_updates"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-slave-updates[={OFF|ON}] </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_slave_updates"> log_slave_updates </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> No </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ON </code> </td> </tr> </tbody> </table> </div> <p> Deprecated alias for <a class="link" href="replication-options-binary-log.html#sysvar_log_replica_updates"> <code class="literal"> log_replica_updates </code> </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_log_statements_unsafe_for_binlog"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_log_statements_unsafe_for_binlog"> <code class="literal"> log_statements_unsafe_for_binlog </code> </a> </p> <a class="indexterm" name="idm46045139567360"> </a> <a class="indexterm" name="idm46045139566256"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for log_statements_unsafe_for_binlog"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --log-statements-unsafe-for-binlog[={OFF|ON}] </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_log_statements_unsafe_for_binlog"> log_statements_unsafe_for_binlog </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ON </code> </td> </tr> </tbody> </table> </div> <p> If error 1592 is encountered, controls whether the generated warnings are added to the error log or not. </p> </li> <li class="listitem"> <p> <a name="sysvar_master_verify_checksum"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_master_verify_checksum"> <code class="literal"> master_verify_checksum </code> </a> </p> <a class="indexterm" name="idm46045139539552"> </a> <a class="indexterm" name="idm46045139538512"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for master_verify_checksum"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --master-verify-checksum[={OFF|ON}] </code> </td> </tr> <tr> <th> Deprecated </th> <td> Yes </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_master_verify_checksum"> master_verify_checksum </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> Deprecated alias for <a class="link" href="replication-options-binary-log.html#sysvar_source_verify_checksum"> <code class="literal"> source_verify_checksum </code> </a> . </p> </li> <li class="listitem"> <p> <a name="sysvar_max_binlog_cache_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_cache_size"> <code class="literal"> max_binlog_cache_size </code> </a> </p> <a class="indexterm" name="idm46045139510704"> </a> <a class="indexterm" name="idm46045139509664"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for max_binlog_cache_size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --max-binlog-cache-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_cache_size"> max_binlog_cache_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value (64-bit platforms) </th> <td> <code class="literal"> 18446744073709547520 </code> </td> </tr> <tr> <th> Default Value (32-bit platforms) </th> <td> <code class="literal"> 4294967295 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 4096 </code> </td> </tr> <tr> <th> Maximum Value (64-bit platforms) </th> <td> <code class="literal"> 18446744073709547520 </code> </td> </tr> <tr> <th> Maximum Value (32-bit platforms) </th> <td> <code class="literal"> 4294967295 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> <tr> <th> <a class="link" href="server-system-variables.html#system-variables-block-size" title="Note"> Block Size </a> </th> <td> <code class="literal"> 4096 </code> </td> </tr> </tbody> </table> </div> <p> If a transaction requires more than this many bytes, the server generates a <span class="errortext"> Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage </span> error. When <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode"> <code class="literal"> gtid_mode </code> </a> is not <code class="literal"> ON </code> , the maximum recommended value is 4GB, due to the fact that, in this case, MySQL cannot work with binary log positions greater than 4GB; when <code class="literal"> gtid_mode </code> is <code class="literal"> ON </code> , this limitation does not apply, and the server can work with binary log positions of arbitrary size. </p> <p> If, because <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode"> <code class="literal"> gtid_mode </code> </a> is not <code class="literal"> ON </code> , or for some other reason, you need to guarantee that the binary log does not exceed a given size <em class="replaceable"> <code> maxsize </code> </em> , you should set this variable according to the formula shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa68218065"><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-simple">max_binlog_cache_size <span class="token operator">&lt;</span> <span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">(</span><em class="replaceable">maxsize</em> <span class="token operator">-</span> max_binlog_size<span class="token punctuation">)</span> <span class="token operator">/</span> max_connections<span class="token punctuation">)</span> <span class="token operator">-</span> 1000<span class="token punctuation">)</span> <span class="token operator">/</span> 1<span class="token punctuation">.</span>2</code></pre> </div> <p> This calculation takes into account the following conditions: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> The server writes to the binary log as long as the size before it begins to write is less than <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> <code class="literal"> max_binlog_size </code> </a> . </p> </li> <li class="listitem"> <p> The server does not write single transactions, but rather groups of transactions. The maximum possible number of transactions in a group is equal to <a class="link" href="server-system-variables.html#sysvar_max_connections"> <code class="literal"> max_connections </code> </a> . </p> </li> <li class="listitem"> <p> The server writes data that is not included in the cache. This includes a 4-byte checksum for each event; while this adds less than 20% to the transaction size, this amount is non-negible. In addition, the server writes a <code class="literal"> Gtid_log_event </code> for each transaction; each of these events can add another 1 KB to what is written to the binary log. </p> </li> </ul> </div> <p> <code class="literal"> max_binlog_cache_size </code> sets the size for the transaction cache only; the upper limit for the statement cache is governed by the <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_stmt_cache_size"> <code class="literal"> max_binlog_stmt_cache_size </code> </a> system variable. </p> <p> The visibility to sessions of <code class="literal"> max_binlog_cache_size </code> matches that of the <a class="link" href="replication-options-binary-log.html#sysvar_binlog_cache_size"> <code class="literal"> binlog_cache_size </code> </a> system variable; in other words, changing its value affects only new sessions that are started after the value is changed. </p> </li> <li class="listitem"> <p> <a name="sysvar_max_binlog_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> <code class="literal"> max_binlog_size </code> </a> </p> <a class="indexterm" name="idm46045139446896"> </a> <a class="indexterm" name="idm46045139445808"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for max_binlog_size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --max-binlog-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> max_binlog_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 1073741824 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 4096 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 1073741824 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> <tr> <th> <a class="link" href="server-system-variables.html#system-variables-block-size" title="Note"> Block Size </a> </th> <td> <code class="literal"> 4096 </code> </td> </tr> </tbody> </table> </div> <p> If a write to the binary log causes the current log file size to exceed the value of this variable, the server rotates the binary logs (closes the current file and opens the next one). The minimum value is 4096 bytes. The maximum and default value is 1GB. Encrypted binary log files have an additional 512-byte header, which is included in <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> <code class="literal"> max_binlog_size </code> </a> . </p> <p> A transaction is written in one chunk to the binary log, so it is never split between several binary logs. Therefore, if you have big transactions, you might see binary log files larger than <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> <code class="literal"> max_binlog_size </code> </a> . </p> <p> If <a class="link" href="replication-options-replica.html#sysvar_max_relay_log_size"> <code class="literal"> max_relay_log_size </code> </a> is 0, the value of <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> <code class="literal"> max_binlog_size </code> </a> applies to relay logs as well. </p> <p> With GTIDs in use on the server, when <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_size"> <code class="literal"> max_binlog_size </code> </a> is reached, if the system table <code class="literal"> mysql.gtid_executed </code> cannot be accessed to write the GTIDs from the current binary log file, the binary log cannot be rotated. In this situation, the server responds according to its <a class="link" href="replication-options-binary-log.html#sysvar_binlog_error_action"> <code class="literal"> binlog_error_action </code> </a> setting. If <code class="literal"> IGNORE_ERROR </code> is set, an error is logged on the server and binary logging is halted, or if <code class="literal"> ABORT_SERVER </code> is set, the server shuts down. </p> </li> <li class="listitem"> <p> <a name="sysvar_max_binlog_stmt_cache_size"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_stmt_cache_size"> <code class="literal"> max_binlog_stmt_cache_size </code> </a> </p> <a class="indexterm" name="idm46045139399440"> </a> <a class="indexterm" name="idm46045139398336"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for max_binlog_stmt_cache_size"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --max-binlog-stmt-cache-size=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_stmt_cache_size"> max_binlog_stmt_cache_size </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 18446744073709547520 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 4096 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 18446744073709547520 </code> </td> </tr> <tr> <th> Unit </th> <td> bytes </td> </tr> <tr> <th> <a class="link" href="server-system-variables.html#system-variables-block-size" title="Note"> Block Size </a> </th> <td> <code class="literal"> 4096 </code> </td> </tr> </tbody> </table> </div> <p> If nontransactional statements within a transaction require more than this many bytes of memory, the server generates an error. The minimum value is 4096. The maximum and default values are 4GB on 32-bit platforms and 16EB (exabytes) on 64-bit platforms. </p> <p> <code class="literal"> max_binlog_stmt_cache_size </code> sets the size for the statement cache only; the upper limit for the transaction cache is governed exclusively by the <a class="link" href="replication-options-binary-log.html#sysvar_max_binlog_cache_size"> <code class="literal"> max_binlog_cache_size </code> </a> system variable. </p> </li> <li class="listitem"> <p> <a name="sysvar_original_commit_timestamp"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_original_commit_timestamp"> <code class="literal"> original_commit_timestamp </code> </a> </p> <a class="indexterm" name="idm46045139360592"> </a> <a class="indexterm" name="idm46045139359488"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for original_commit_timestamp"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_original_commit_timestamp"> original_commit_timestamp </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Numeric </td> </tr> </tbody> </table> </div> <p> For internal use by replication. When re-executing a transaction on a replica, this is set to the time when the transaction was committed on the original source, measured in microseconds since the epoch. This allows the original commit timestamp to be propagated throughout a replication topology. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have either the <a class="link" href="privileges-provided.html#priv_replication-applier"> <code class="literal"> REPLICATION_APPLIER </code> </a> privilege (see <a class="xref" href="replication-privilege-checks.html" title="19.3.3 Replication Privilege Checks"> Section 19.3.3, “Replication Privilege Checks” </a> ), or privileges sufficient to set restricted session variables (see <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> ). However, note that the variable is not intended for users to set; it is set automatically by the replication infrastructure. </p> </li> <li class="listitem"> <p> <a name="sysvar_source_verify_checksum"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_source_verify_checksum"> <code class="literal"> source_verify_checksum </code> </a> </p> <a class="indexterm" name="idm46045139335984"> </a> <a class="indexterm" name="idm46045139334944"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for source_verify_checksum"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --source-verify-checksum[={OFF|ON}] </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_source_verify_checksum"> source_verify_checksum </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> OFF </code> </td> </tr> </tbody> </table> </div> <p> Enabling <a class="link" href="replication-options-binary-log.html#sysvar_source_verify_checksum"> <code class="literal"> source_verify_checksum </code> </a> causes the source to verify events read from the binary log by examining checksums, and to stop with an error in the event of a mismatch. <a class="link" href="replication-options-binary-log.html#sysvar_source_verify_checksum"> <code class="literal"> source_verify_checksum </code> </a> is disabled by default; in this case, the source uses the event length from the binary log to verify events, so that only complete events are read from the binary log. </p> </li> <li class="listitem"> <p> <a name="sysvar_sql_log_bin"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin"> <code class="literal"> sql_log_bin </code> </a> </p> <a class="indexterm" name="idm46045139307648"> </a> <a class="indexterm" name="idm46045139306560"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for sql_log_bin"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin"> sql_log_bin </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Session </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Boolean </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> ON </code> </td> </tr> </tbody> </table> </div> <p> This variable controls whether logging to the binary log is enabled for the current session (assuming that the binary log itself is enabled). The default value is <code class="literal"> ON </code> . To disable or enable binary logging for the current session, set the session <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin"> <code class="literal"> sql_log_bin </code> </a> variable to <code class="literal"> OFF </code> or <code class="literal"> ON </code> . </p> <p> Set this variable to <code class="literal"> OFF </code> for a session to temporarily disable binary logging while making changes to the source you do not want replicated to the replica. </p> <p> Setting the session value of this system variable is a restricted operation. The session user must have privileges sufficient to set restricted session variables. See <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges"> Section 7.1.9.1, “System Variable Privileges” </a> . </p> <p> It is not possible to set the session value of <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin"> <code class="literal"> sql_log_bin </code> </a> within a transaction or subquery. </p> <p> <span class="emphasis"> <em> Setting this variable to <code class="literal"> OFF </code> prevents GTIDs from being assigned to transactions in the binary log </em> </span> . If you are using GTIDs for replication, this means that even when binary logging is later enabled again, the GTIDs written into the log from this point do not account for any transactions that occurred in the meantime, so in effect those transactions are lost. </p> </li> <li class="listitem"> <p> <a name="sysvar_sync_binlog"> </a> <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog </code> </a> </p> <a class="indexterm" name="idm46045139274816"> </a> <a class="indexterm" name="idm46045139273728"> </a> <div class="informaltable"> <table frame="box" rules="all" summary="Properties for sync_binlog"> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <tbody> <tr> <th> Command-Line Format </th> <td> <code class="literal"> --sync-binlog=# </code> </td> </tr> <tr> <th> System Variable </th> <td> <code class="literal"> <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> sync_binlog </a> </code> </td> </tr> <tr> <th> Scope </th> <td> Global </td> </tr> <tr> <th> Dynamic </th> <td> Yes </td> </tr> <tr> <th> <a class="link" href="optimizer-hints.html#optimizer-hints-set-var" title="Variable-Setting Hint Syntax"> <code class="literal"> SET_VAR </code> </a> Hint Applies </th> <td> No </td> </tr> <tr> <th> Type </th> <td> Integer </td> </tr> <tr> <th> Default Value </th> <td> <code class="literal"> 1 </code> </td> </tr> <tr> <th> Minimum Value </th> <td> <code class="literal"> 0 </code> </td> </tr> <tr> <th> Maximum Value </th> <td> <code class="literal"> 4294967295 </code> </td> </tr> </tbody> </table> </div> <p> Controls how often the MySQL server synchronizes the binary log to disk. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog=0 </code> </a> : Disables synchronization of the binary log to disk by the MySQL server. Instead, the MySQL server relies on the operating system to flush the binary log to disk from time to time as it does for any other file. This setting provides the best performance, but in the event of a power failure or operating system crash, it is possible that the server has committed transactions that have not been synchronized to the binary log. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog=1 </code> </a> : Enables synchronization of the binary log to disk before transactions are committed. This is the safest setting but can have a negative impact on performance due to the increased number of disk writes. In the event of a power failure or operating system crash, transactions that are missing from the binary log are only in a prepared state. This permits the automatic recovery routine to roll back the transactions, which guarantees that no transaction is lost from the binary log. </p> </li> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog= <em class="replaceable"> <code> N </code> </em> </code> </a> , where <em class="replaceable"> <code> N </code> </em> is a value other than 0 or 1: The binary log is synchronized to disk after <code class="literal"> N </code> binary log commit groups have been collected. In the event of a power failure or operating system crash, it is possible that the server has committed transactions that have not been flushed to the binary log. This setting can have a negative impact on performance due to the increased number of disk writes. A higher value improves performance, but with an increased risk of data loss. </p> </li> </ul> </div> <p> For the greatest possible durability and consistency in a replication setup that uses <code class="literal"> InnoDB </code> with transactions, use these settings: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <a class="link" href="replication-options-binary-log.html#sysvar_sync_binlog"> <code class="literal"> sync_binlog=1 </code> </a> . </p> </li> <li class="listitem"> <p> <a class="link" href="innodb-parameters.html#sysvar_innodb_flush_log_at_trx_commit"> <code class="literal"> innodb_flush_log_at_trx_commit=1 </code> </a> . </p> </li> </ul> </div> <div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Caution </div> <p> Many operating systems and some disk hardware fool the flush-to-disk operation. They may tell <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> that the flush has taken place, even though it has not. In this case, the durability of transactions is not guaranteed even with the recommended settings, and in the worst case, a power outage can corrupt <code class="literal"> InnoDB </code> data. Using a battery-backed disk cache in the SCSI disk controller or in the disk itself speeds up file flushes, and makes the operation safer. You can also try to disable the caching of disk writes in hardware caches. </p> </div> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-replication-schema.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="mysql-cluster-replication-schema"> </a> 25.7.4 NDB Cluster Replication Schema and Tables </h3> </div> </div> </div> <a class="indexterm" name="idm46045086535216"> </a> <a class="indexterm" name="idm46045086533728"> </a> <a class="indexterm" name="idm46045086532272"> </a> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-ndb-apply-status" title="ndb_apply_status Table"> ndb_apply_status Table </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-ndb-binlog-index" title="ndb_binlog_index Table"> ndb_binlog_index Table </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-ndb-replication" title="ndb_replication Table"> ndb_replication Table </a> </p> </li> </ul> </div> <p> Replication in NDB Cluster makes use of a number of dedicated tables in the <code class="literal"> mysql </code> database on each MySQL Server instance acting as an SQL node in both the cluster being replicated and in the replica. This is true regardless of whether the replica is a single server or a cluster. </p> <p> The <code class="literal"> ndb_binlog_index </code> and <code class="literal"> ndb_apply_status </code> tables are created in the <code class="literal"> mysql </code> database. They should not be explicitly replicated by the user. User intervention is normally not required to create or maintain either of these tables, since both are maintained by the <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> binary log (binlog) injector thread. This keeps the source <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> process updated to changes performed by the <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> storage engine. The <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> <span class="firstterm"> binlog injector thread </span> receives events directly from the <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> storage engine. The <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> injector is responsible for capturing all the data events within the cluster, and ensures that all events which change, insert, or delete data are recorded in the <code class="literal"> ndb_binlog_index </code> table. The replica I/O (receiver) thread transfers the events from the source's binary log to the replica's relay log. </p> <p> The <code class="literal"> ndb_replication </code> table must be created manually. This table can be updated by the user to perform filtering by database or table. See <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-ndb-replication" title="ndb_replication Table"> ndb_replication Table </a> , for more information. <code class="literal"> ndb_replication </code> is also used in NDB Replication conflict detection and resolution for conflict resolution control; see <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#conflict-resolution-control" title="Conflict Resolution Control"> Conflict Resolution Control </a> . </p> <p> Even though <code class="literal"> ndb_binlog_index </code> and <code class="literal"> ndb_apply_status </code> are created and maintained automatically, it is advisable to check for the existence and integrity of these tables as an initial step in preparing an NDB Cluster for replication. It is possible to view event data recorded in the binary log by querying the <code class="literal"> mysql.ndb_binlog_index </code> table directly on the source. This can be also be accomplished using the <a class="link" href="show-binlog-events.html" title="15.7.7.3 SHOW BINLOG EVENTS Statement"> <code class="literal"> SHOW BINLOG EVENTS </code> </a> statement on either the source or replica SQL node. (See <a class="xref" href="show-binlog-events.html" title="15.7.7.3 SHOW BINLOG EVENTS Statement"> Section 15.7.7.3, “SHOW BINLOG EVENTS Statement” </a> .) </p> <p> You can also obtain useful information from the output of <a class="link" href="show-engine.html" title="15.7.7.16 SHOW ENGINE Statement"> <code class="literal"> SHOW ENGINE NDB STATUS </code> </a> . </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> When performing schema changes on <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables, applications should wait until the <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement has returned in the MySQL client connection that issued the statement before attempting to use the updated definition of the table. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="ndb-replication-ndb-apply-status"> </a> ndb_apply_status Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045086499456"> </a> <a class="indexterm" name="idm46045086497936"> </a> <p> <code class="literal"> ndb_apply_status </code> is used to keep a record of the operations that have been replicated from the source to the replica. If the <code class="literal"> ndb_apply_status </code> table does not exist on the replica, <a class="link" href="mysql-cluster-programs-ndb-restore.html" title="25.5.23 ndb_restore — Restore an NDB Cluster Backup"> <span class="command"> <strong> ndb_restore </strong> </span> </a> re-creates it. </p> <p> Unlike the case with <code class="literal"> ndb_binlog_index </code> , the data in this table is not specific to any one SQL node in the (replica) cluster, and so <code class="literal"> ndb_apply_status </code> can use the <code class="literal"> NDBCLUSTER </code> storage engine, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa48819377"><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">TABLE</span> <span class="token punctuation">`</span>ndb_apply_status<span class="token punctuation">`</span> <span class="token punctuation">(</span> <span class="token punctuation">`</span>server_id<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>epoch<span class="token punctuation">`</span> <span class="token datatype">BIGINT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>log_name<span class="token punctuation">`</span> <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> latin1 <span class="token keyword">COLLATE</span> latin1_bin <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>start_pos<span class="token punctuation">`</span> <span class="token datatype">BIGINT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>end_pos<span class="token punctuation">`</span> <span class="token datatype">BIGINT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>server_id<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">USING</span> <span class="token keyword">HASH</span> <span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDBCLUSTER</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COLLATE</span><span class="token operator">=</span>utf8mb4_0900_ai_ci<span class="token punctuation">;</span></code></pre> </div> <p> The <code class="literal"> ndb_apply_status </code> table is populated only on replicas, which means that, on the source, this table never contains any rows; thus, there is no need to allot any <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datamemory"> <code class="literal"> DataMemory </code> </a> to <code class="literal"> ndb_apply_status </code> there. </p> <p> Because this table is populated from data originating on the source, it should be allowed to replicate; any replication filtering or binary log filtering rules that inadvertently prevent the replica from updating <code class="literal"> ndb_apply_status </code> , or that prevent the source from writing into the binary log may prevent replication between clusters from operating properly. For more information about potential problems arising from such filtering rules, see <a class="xref" href="mysql-cluster-replication-issues.html#mysql-cluster-replication-issues-filtering" title="Replication and binary log filtering rules with replication between NDB Clusters"> Replication and binary log filtering rules with replication between NDB Clusters </a> . </p> <p> It is possible to delete this table, but this is not recommended. Deleting it puts all SQL nodes in read-only mode; <code class="literal"> NDB </code> detects that this table has been dropped, and re-creates it, after which it is possible once again to perform updates. Dropping and re-creating <code class="literal"> ndb_apply_status </code> creates a gap event in the binary log; the gap event causes replica SQL nodes to stop applying changes from the source until the replication channel is restarted. </p> <p> <code class="literal"> 0 </code> in the <code class="literal"> epoch </code> column of this table indicates a transaction originating from a storage engine other than <code class="literal"> NDB </code> . </p> <p> <code class="literal"> ndb_apply_status </code> is used to record which epoch transactions have been replicated and applied to a replica cluster from an upstream source. This information is captured in an <code class="literal"> NDB </code> online backup, but (by design) it is not restored by <a class="link" href="mysql-cluster-programs-ndb-restore.html" title="25.5.23 ndb_restore — Restore an NDB Cluster Backup"> <span class="command"> <strong> ndb_restore </strong> </span> </a> . In some cases, it can be helpful to restore this information for use in new setups; you can do this by invoking <a class="link" href="mysql-cluster-programs-ndb-restore.html" title="25.5.23 ndb_restore — Restore an NDB Cluster Backup"> <span class="command"> <strong> ndb_restore </strong> </span> </a> with the <a class="link" href="mysql-cluster-programs-ndb-restore.html#option_ndb_restore_with-apply-status"> <code class="option"> --with-apply-status </code> </a> option. See the description of the option for more information. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="ndb-replication-ndb-binlog-index"> </a> ndb_binlog_index Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045086471760"> </a> <a class="indexterm" name="idm46045086470304"> </a> <p> NDB Cluster Replication uses the <code class="literal"> ndb_binlog_index </code> table for storing the binary log's indexing data. Since this table is local to each MySQL server and does not participate in clustering, it uses the <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine"> <code class="literal"> InnoDB </code> </a> storage engine. This means that it must be created separately on each <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> participating in the source cluster. (The binary log itself contains updates from all MySQL servers in the cluster.) This table is defined as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60048383"><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">TABLE</span> <span class="token punctuation">`</span>ndb_binlog_index<span class="token punctuation">`</span> <span class="token punctuation">(</span> <span class="token punctuation">`</span>Position<span class="token punctuation">`</span> <span class="token datatype">BIGINT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span><span class="token keyword">File</span><span class="token punctuation">`</span> <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>epoch<span class="token punctuation">`</span> <span class="token datatype">BIGINT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>inserts<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>updates<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>deletes<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>schemaops<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>orig_server_id<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>orig_epoch<span class="token punctuation">`</span> <span class="token datatype">BIGINT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>gci<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">UNSIGNED</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>next_position<span class="token punctuation">`</span> <span class="token datatype">bigint</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">unsigned</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>next_file<span class="token punctuation">`</span> <span class="token datatype">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>epoch<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>orig_server_id<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>orig_epoch<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>InnoDB <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COLLATE</span><span class="token operator">=</span>utf8mb4_0900_ai_ci<span class="token punctuation">;</span></code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If you are upgrading from an older release, perform the MySQL upgrade procedure and ensure that the system tables are upgraded by starting the MySQL server with the <code class="option"> --upgrade=FORCE </code> option. The system table upgrade causes an <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE ... ENGINE=INNODB </code> </a> statement to be executed for this table. Use of the <code class="literal"> MyISAM </code> storage engine for this table continues to be supported for backward compatibility. </p> <p> <code class="literal"> ndb_binlog_index </code> may require additional disk space after being converted to <code class="literal"> InnoDB </code> . If this becomes an issue, you may be able to conserve space by using an <code class="literal"> InnoDB </code> tablespace for this table, changing its <code class="literal"> ROW_FORMAT </code> to <code class="literal"> COMPRESSED </code> , or both. For more information, see <a class="xref" href="create-tablespace.html" title="15.1.21 CREATE TABLESPACE Statement"> Section 15.1.21, “CREATE TABLESPACE Statement” </a> , and <a class="xref" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> Section 15.1.20, “CREATE TABLE Statement” </a> , as well as <a class="xref" href="innodb-tablespace.html" title="17.6.3 Tablespaces"> Section 17.6.3, “Tablespaces” </a> . </p> </div> <p> The size of the <code class="literal"> ndb_binlog_index </code> table is dependent on the number of epochs per binary log file and the number of binary log files. The number of epochs per binary log file normally depends on the amount of binary log generated per epoch and the size of the binary log file, with smaller epochs resulting in more epochs per file. You should be aware that empty epochs produce inserts to the <code class="filename"> ndb_binlog_index </code> table, even when the <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-empty-epochs"> <code class="option"> --ndb-log-empty-epochs </code> </a> option is <code class="literal"> OFF </code> , meaning that the number of entries per file depends on the length of time that the file is in use; this relationship can be represented by the formula shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa90452862"><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-simple"><span class="token punctuation">[</span>number of epochs per file<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>time spent per file<span class="token punctuation">]</span> <span class="token operator">/</span> TimeBetweenEpochs</code></pre> </div> <p> A busy NDB Cluster writes to the binary log regularly and presumably rotates binary log files more quickly than a quiet one. This means that a <span class="quote"> “ <span class="quote"> quiet </span> ” </span> NDB Cluster with <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-empty-epochs"> <code class="option"> --ndb-log-empty-epochs=ON </code> </a> can actually have a much higher number of <code class="literal"> ndb_binlog_index </code> rows per file than one with a great deal of activity. </p> <p> When <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> is started with the <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-orig"> <code class="option"> --ndb-log-orig </code> </a> option, the <code class="literal"> orig_server_id </code> and <code class="literal"> orig_epoch </code> columns store, respectively, the ID of the server on which the event originated and the epoch in which the event took place on the originating server, which is useful in NDB Cluster replication setups employing multiple sources. The <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> statement used to find the closest binary log position to the highest applied epoch on the replica in a multi-source setup (see <a class="xref" href="mysql-cluster-replication-multi-source.html" title="25.7.10 NDB Cluster Replication: Bidirectional and Circular Replication"> Section 25.7.10, “NDB Cluster Replication: Bidirectional and Circular Replication” </a> ) employs these two columns, which are not indexed. This can lead to performance issues when trying to fail over, since the query must perform a table scan, especially when the source has been running with <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-empty-epochs"> <code class="option"> --ndb-log-empty-epochs=ON </code> </a> . You can improve multi-source failover times by adding an index to these columns, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53337061"><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">ALTER</span> <span class="token keyword">TABLE</span> mysql<span class="token punctuation">.</span>ndb_binlog_index <span class="token keyword">ADD</span> <span class="token keyword">INDEX</span> orig_lookup <span class="token keyword">USING</span> <span class="token keyword">BTREE</span> <span class="token punctuation">(</span>orig_server_id<span class="token punctuation">,</span> orig_epoch<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> Adding this index provides no benefit when replicating from a single source to a single replica, since the query used to get the binary log position in such cases makes no use of <code class="literal"> orig_server_id </code> or <code class="literal"> orig_epoch </code> . </p> <p> See <a class="xref" href="mysql-cluster-replication-failover.html" title="25.7.8 Implementing Failover with NDB Cluster Replication"> Section 25.7.8, “Implementing Failover with NDB Cluster Replication” </a> , for more information about using the <code class="literal"> next_position </code> and <code class="literal"> next_file </code> columns. </p> <p> The following figure shows the relationship of the NDB Cluster replication source server, its binary log injector thread, and the <code class="literal"> mysql.ndb_binlog_index </code> table. </p> <div class="figure"> <a name="fig-mysql-cluster-replication-source-cluster"> </a> <p class="title"> <b> Figure 25.13 The Replication Source Cluster </b> </p> <div class="figure-contents"> <div class="mediaobject"> <img alt="Most concepts are described in the surrounding text. This complex image has three main areas. The top left area is divided into three sections: MySQL Server (mysqld), NDBCLUSTER table handler, and mutex. A connection thread connects these, and receiver and injector threads connect the NDBCLUSTER table handler and mutex. The bottom area shows four data nodes (ndbd). They all produce events represented by arrows pointing to the receiver thread, and the receiver thread also points to the connection and injector threads. One node sends and receives to the mutex area. The arrow representing the injector thread points to a binary log as well as the ndb_binlog_index table, which is described in the surrounding text." src="images/cluster-replication-binlog-injector.png" style="width: 100%; max-width: 750px;"/> </div> </div> </div> <br class="figure-break"/> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="ndb-replication-ndb-replication"> </a> ndb_replication Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045086420608"> </a> <a class="indexterm" name="idm46045086419536"> </a> <p> The <code class="literal"> ndb_replication </code> table is used to control binary logging and conflict resolution, and acts on a per-table basis. Each row in this table corresponds to a table being replicated, determines how to log changes to the table and, if a conflict resolution function is specified, and determines how to resolve conflicts for that table. </p> <p> Unlike the <code class="literal"> ndb_apply_status </code> and <code class="literal"> ndb_replication </code> tables, the <code class="literal"> ndb_replication </code> table must be created manually, using the SQL statement shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa83724997"><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">TABLE</span> mysql<span class="token punctuation">.</span>ndb_replication <span class="token punctuation">(</span> db <span class="token datatype">VARBINARY</span><span class="token punctuation">(</span><span class="token number">63</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">table_name</span> <span class="token datatype">VARBINARY</span><span class="token punctuation">(</span><span class="token number">63</span><span class="token punctuation">)</span><span class="token punctuation">,</span> server_id <span class="token datatype">INT</span> <span class="token keyword">UNSIGNED</span><span class="token punctuation">,</span> binlog_type <span class="token datatype">INT</span> <span class="token keyword">UNSIGNED</span><span class="token punctuation">,</span> conflict_fn <span class="token datatype">VARBINARY</span><span class="token punctuation">(</span><span class="token number">128</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token keyword">USING</span> <span class="token keyword">HASH</span> <span class="token punctuation">(</span>db<span class="token punctuation">,</span> <span class="token keyword">table_name</span><span class="token punctuation">,</span> server_id<span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDB</span> <span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> <span class="token keyword">KEY</span><span class="token punctuation">(</span>db<span class="token punctuation">,</span><span class="token keyword">table_name</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> The columns of this table are listed here, with descriptions: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> db </code> column </p> <p> The name of the database containing the table to be replicated. </p> <p> You may employ either or both of the wildcards <code class="literal"> _ </code> and <code class="literal"> % </code> as part of the database name. (See <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-wildcards" title="Matching with wildcards"> Matching with wildcards </a> , later in this section.) </p> </li> <li class="listitem"> <p> <code class="literal"> table_name </code> column </p> <p> The name of the table to be replicated. </p> <p> The table name may include either or both of the wildcards <code class="literal"> _ </code> and <code class="literal"> % </code> . See <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-wildcards" title="Matching with wildcards"> Matching with wildcards </a> , later in this section. </p> </li> <li class="listitem"> <p> <code class="literal"> server_id </code> column </p> <p> The unique server ID of the MySQL instance (SQL node) where the table resides. </p> <p> <code class="literal"> 0 </code> in this column acts like a wildcard equivalent to <code class="literal"> % </code> , and matches any server ID. (See <a class="xref" href="mysql-cluster-replication-schema.html#ndb-replication-wildcards" title="Matching with wildcards"> Matching with wildcards </a> , later in this section.) </p> </li> <li class="listitem"> <p> <code class="literal"> binlog_type </code> column </p> <p> The type of binary logging to be employed. See text for values and descriptions. </p> </li> <li class="listitem"> <p> <code class="literal"> conflict_fn </code> column </p> <p> The conflict resolution function to be applied; one of <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-old" title="NDB$OLD()"> NDB$OLD() </a> , <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-max" title="NDB$MAX()"> NDB$MAX() </a> , <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-max-delete-win" title="NDB$MAX_DELETE_WIN()"> NDB$MAX_DELETE_WIN() </a> , <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-epoch" title="NDB$EPOCH()"> NDB$EPOCH() </a> , <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-epoch-trans" title="NDB$EPOCH_TRANS()"> NDB$EPOCH_TRANS() </a> , <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-epoch2" title="NDB$EPOCH2()"> NDB$EPOCH2() </a> , <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-epoch2-trans" title="NDB$EPOCH2_TRANS()"> NDB$EPOCH2_TRANS() </a> <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-max-ins" title="NDB$MAX_INS()"> NDB$MAX_INS() </a> , or <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#mysql-cluster-replication-ndb-max-del-win-ins" title="NDB$MAX_DEL_WIN_INS()"> NDB$MAX_DEL_WIN_INS() </a> ; <code class="literal"> NULL </code> indicates that conflict resolution is not used for this table. </p> <p> See <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#conflict-resolution-functions" title="Conflict Resolution Functions"> Conflict Resolution Functions </a> , for more information about these functions and their uses in NDB Replication conflict resolution. </p> <p> Some conflict resolution functions ( <code class="literal"> NDB$OLD() </code> , <code class="literal"> NDB$EPOCH() </code> , <code class="literal"> NDB$EPOCH_TRANS() </code> ) require the use of one or more user-created exceptions tables. See <a class="xref" href="mysql-cluster-replication-conflict-resolution.html#conflict-resolution-exceptions-table" title="Conflict Resolution Exceptions Table"> Conflict Resolution Exceptions Table </a> . </p> </li> </ul> </div> <p> To enable conflict resolution with NDB Replication, it is necessary to create and populate this table with control information on the SQL node or nodes on which the conflict should be resolved. Depending on the conflict resolution type and method to be employed, this may be the source, the replica, or both servers. In a simple source-replica setup where data can also be changed locally on the replica this is typically the replica. In a more complex replication scheme, such as bidirectional replication, this is usually all of the sources involved. See <a class="xref" href="mysql-cluster-replication-conflict-resolution.html" title="25.7.12 NDB Cluster Replication Conflict Resolution"> Section 25.7.12, “NDB Cluster Replication Conflict Resolution” </a> , for more information. </p> <p> The <code class="literal"> ndb_replication </code> table allows table-level control over binary logging outside the scope of conflict resolution, in which case <code class="literal"> conflict_fn </code> is specified as <code class="literal"> NULL </code> , while the remaining column values are used to control binary logging for a given table or set of tables matching a wildcard expression. By setting the proper value for the <code class="literal"> binlog_type </code> column, you can make logging for a given table or tables use a desired binary log format, or disabling binary logging altogether. Possible values for this column, with values and descriptions, are shown in the following table: </p> <div class="table"> <a name="idm46045086374816"> </a> <p class="title"> <b> Table 25.42 binlog_type values, with values and descriptions </b> </p> <div class="table-contents"> <table> <colgroup> <col width="10%"/> <col width="55%"/> </colgroup> <thead> <tr> <th scope="col"> Value </th> <th scope="col"> Description </th> </tr> </thead> <tbody> <tr> <th scope="row"> 0 </th> <td> Use server default </td> </tr> <tr> <th scope="row"> 1 </th> <td> Do not log this table in the binary log (same effect as <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin"> <code class="literal"> sql_log_bin = 0 </code> </a> , but applies to one or more specified tables only) </td> </tr> <tr> <th scope="row"> 2 </th> <td> Log updated attributes only; log these as <code class="literal"> WRITE_ROW </code> events </td> </tr> <tr> <th scope="row"> 3 </th> <td> Log full row, even if not updated (MySQL server default behavior) </td> </tr> <tr> <th scope="row"> 6 </th> <td> Use updated attributes, even if values are unchanged </td> </tr> <tr> <th scope="row"> 7 </th> <td> Log full row, even if no values are changed; log updates as <code class="literal"> UPDATE_ROW </code> events </td> </tr> <tr> <th scope="row"> 8 </th> <td> Log update as <code class="literal"> UPDATE_ROW </code> ; log only primary key columns in before image, and only updated columns in after image (same effect as <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-minimal"> <code class="option"> --ndb-log-update-minimal </code> </a> , but applies to one or more specified tables only) </td> </tr> <tr> <th scope="row"> 9 </th> <td> Log update as <code class="literal"> UPDATE_ROW </code> ; log only primary key columns in before image, and all columns other than primary key columns in after image </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> <code class="literal"> binlog_type </code> values 4 and 5 are not used, and so are omitted from the table just shown, as well as from the next table. </p> </div> <p> Several <code class="literal"> binlog_type </code> values are equivalent to various combinations of the <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> logging options <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-updated-only"> <code class="option"> --ndb-log-updated-only </code> </a> , <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-as-write"> <code class="option"> --ndb-log-update-as-write </code> </a> , and <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-minimal"> <code class="option"> --ndb-log-update-minimal </code> </a> , as shown in the following table: </p> <div class="table"> <a name="idm46045086336368"> </a> <p class="title"> <b> Table 25.43 binlog_type values with equivalent combinations of NDB logging options </b> </p> <div class="table-contents"> <table> <colgroup> <col width="10%"/> <col width="30%"/> <col width="30%"/> <col width="30%"/> </colgroup> <thead> <tr> <th scope="col"> Value </th> <th scope="col"> <code class="option"> --ndb-log-updated-only </code> Value </th> <th scope="col"> <code class="option"> --ndb-log-update-as-write </code> Value </th> <th scope="col"> <code class="option"> --ndb-log-update-minimal </code> Value </th> </tr> </thead> <tbody> <tr> <th scope="row"> 0 </th> <td> -- </td> <td> -- </td> <td> -- </td> </tr> <tr> <th scope="row"> 1 </th> <td> -- </td> <td> -- </td> <td> -- </td> </tr> <tr> <th scope="row"> 2 </th> <td> ON </td> <td> ON </td> <td> OFF </td> </tr> <tr> <th scope="row"> 3 </th> <td> OFF </td> <td> ON </td> <td> OFF </td> </tr> <tr> <th scope="row"> 6 </th> <td> ON </td> <td> OFF </td> <td> OFF </td> </tr> <tr> <th scope="row"> 7 </th> <td> OFF </td> <td> OFF </td> <td> OFF </td> </tr> <tr> <th scope="row"> 8 </th> <td> ON </td> <td> OFF </td> <td> ON </td> </tr> <tr> <th scope="row"> 9 </th> <td> OFF </td> <td> OFF </td> <td> ON </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <p> Binary logging can be set to different formats for different tables by inserting rows into the <code class="literal"> ndb_replication </code> table using the appropriate <code class="literal"> db </code> , <code class="literal"> table_name </code> , and <code class="literal"> binlog_type </code> column values. The internal integer value shown in the preceding table should be used when setting the binary logging format. The following two statements set binary logging to logging of full rows ( value 3) for table <code class="literal"> test.a </code> , and to logging of updates only ( value 2) for table <code class="literal"> test.b </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61641893"><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 comment" spellcheck="true"># Table test.a: Log full rows</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> mysql<span class="token punctuation">.</span>ndb_replication <span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">"test"</span><span class="token punctuation">,</span> <span class="token string">"a"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true"># Table test.b: log updates only</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> mysql<span class="token punctuation">.</span>ndb_replication <span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">"test"</span><span class="token punctuation">,</span> <span class="token string">"b"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> To disable logging for one or more tables, use 1 for <code class="literal"> binlog_type </code> , as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa64870822"><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 comment" spellcheck="true"># Disable binary logging for table test.t1</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> mysql<span class="token punctuation">.</span>ndb_replication <span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">"test"</span><span class="token punctuation">,</span> <span class="token string">"t1"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true"># Disable binary logging for any table in 'test' whose name begins with 't'</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> mysql<span class="token punctuation">.</span>ndb_replication <span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">"test"</span><span class="token punctuation">,</span> <span class="token string">"t%"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> Disabling logging for a given table is the equivalent of setting <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin"> <code class="literal"> sql_log_bin = 0 </code> </a> , except that it applies to one or more tables individually. If an SQL node is not performing binary logging for a given table, it is not sent the row change events for those tables. This means that it is not receiving all changes and discarding some, but rather it is not subscribing to these changes. </p> <p> Disabling logging can be useful for a number of reasons, including those listed here: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Not sending changes across the network generally saves bandwidth, buffering, and CPU resources. </p> </li> <li class="listitem"> <p> Not logging changes to tables with very frequent updates but whose value is not great is a good fit for transient data (such as session data) that may be relatively unimportant in the event of a complete failure of the cluster. </p> </li> <li class="listitem"> <p> Using a session variable (or <code class="literal"> sql_log_bin </code> ) and application code, it is also possible to log (or not to log) certain SQL statements or types of SQL statements; for example, it may be desirable in some cases not to record DDL statements on one or more tables. </p> </li> <li class="listitem"> <p> Splitting replication streams into two (or more) binary logs can be done for reasons of performance, a need to replicate different databases to different places, use of different binary logging types for different databases, and so on. </p> </li> </ul> </div> <p> <a name="ndb-replication-wildcards"> </a> <b> Matching with wildcards. </b> In order not to make it necessary to insert a row in the <code class="literal"> ndb_replication </code> table for each and every combination of database, table, and SQL node in your replication setup, <code class="literal"> NDB </code> supports wildcard matching on the this table's <code class="literal"> db </code> , <code class="literal"> table_name </code> , and <code class="literal"> server_id </code> columns. Database and table names used in, respectively, <code class="literal"> db </code> and <code class="literal"> table_name </code> may contain either or both of the following wildcards: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> _ </code> (underscore character): matches zero or more characters </p> </li> <li class="listitem"> <p> <code class="literal"> % </code> (percent sign): matches a single character </p> </li> </ul> </div> <p> (These are the same wildcards as supported by the MySQL <a class="link" href="string-comparison-functions.html#operator_like"> <code class="literal"> LIKE </code> </a> operator.) </p> <p> The <code class="literal"> server_id </code> column supports <code class="literal"> 0 </code> as a wildcard equivalent to <code class="literal"> _ </code> (matches anything). This is used in the examples shown previously. </p> <p> A given row in the <code class="literal"> ndb_replication </code> table can use wildcards to match any of the database name, table name, and server ID in any combination. Where there are multiple potential matches in the table, the best match is chosen, according to the table shown here, where <span class="emphasis"> <em> W </em> </span> represents a wildcard match, <span class="emphasis"> <em> E </em> </span> an exact match, and the greater the value in the <span class="emphasis"> <em> Quality </em> </span> column, the better the match: </p> <div class="table"> <a name="idm46045086258784"> </a> <p class="title"> <b> Table 25.44 Weights of different combinations of wildcard and exact matches on columns in the mysql.ndb_replication table </b> </p> <div class="table-contents"> <table> <colgroup> <col style="width: 25%"/> <col style="width: 25%"/> <col style="width: 25%"/> <col style="width: 25%"/> </colgroup> <thead> <tr> <th scope="col"> <code class="literal"> db </code> </th> <th scope="col"> <code class="literal"> table_name </code> </th> <th scope="col"> <code class="literal"> server_id </code> </th> <th scope="col"> Quality </th> </tr> </thead> <tbody> <tr> <td scope="row"> W </td> <td> W </td> <td> W </td> <td> 1 </td> </tr> <tr> <td scope="row"> W </td> <td> W </td> <td> E </td> <td> 2 </td> </tr> <tr> <td scope="row"> W </td> <td> E </td> <td> W </td> <td> 3 </td> </tr> <tr> <td scope="row"> W </td> <td> E </td> <td> E </td> <td> 4 </td> </tr> <tr> <td scope="row"> E </td> <td> W </td> <td> W </td> <td> 5 </td> </tr> <tr> <td scope="row"> E </td> <td> W </td> <td> E </td> <td> 6 </td> </tr> <tr> <td scope="row"> E </td> <td> E </td> <td> W </td> <td> 7 </td> </tr> <tr> <td scope="row"> E </td> <td> E </td> <td> E </td> <td> 8 </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <p> Thus, an exact match on database name, table name, and server ID is considered best (strongest), while the weakest (worst) match is a wildcard match on all three columns. Only the strength of the match is considered when choosing which rule to apply; the order in which the rows occur in the table has no effect on this determination. </p> <p> <a name="ndb-replication-full-or-partial"> </a> <b> Logging Full or Partial Rows. </b> <a class="indexterm" name="idm46045086213104"> </a> There are two basic methods of logging rows, as determined by the setting of the <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-updated-only"> <code class="option"> --ndb-log-updated-only </code> </a> option for <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> : </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Log complete rows (option set to <code class="literal"> ON </code> ) </p> </li> <li class="listitem"> <p> Log only column data that has been updated—that is, column data whose value has been set, regardless of whether or not this value was actually changed. This is the default behavior (option set to <code class="literal"> OFF </code> ). </p> </li> </ul> </div> <p> It is usually sufficient—and more efficient—to log updated columns only; however, if you need to log full rows, you can do so by setting <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-updated-only"> <code class="option"> --ndb-log-updated-only </code> </a> to <code class="literal"> 0 </code> or <code class="literal"> OFF </code> . </p> <p> <a name="ndb-replication-changes-as-updates"> </a> <b> Logging Changed Data as Updates. </b> <a class="indexterm" name="idm46045086201040"> </a> The setting of the MySQL Server's <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-as-write"> <code class="option"> --ndb-log-update-as-write </code> </a> option determines whether logging is performed with or without the <span class="quote"> “ <span class="quote"> before </span> ” </span> image. </p> <p> Because conflict resolution for updates and delete operations is done in the MySQL Server's update handler, it is necessary to control the logging performed by the replication source such that updates are updates and not writes; that is, such that updates are treated as changes in existing rows rather than the writing of new rows, even though these replace existing rows. </p> <p> This option is turned on by default; in other words, updates are treated as writes. That is, updates are by default written as <code class="literal"> write_row </code> events in the binary log, rather than as <code class="literal"> update_row </code> events. </p> <p> To disable the option, start the source <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> with <code class="option"> --ndb-log-update-as-write=0 </code> or <code class="option"> --ndb-log-update-as-write=OFF </code> . You must do this when replicating from NDB tables to tables using a different storage engine; see <a class="xref" href="mysql-cluster-replication-issues.html#mysql-cluster-replication-ndb-to-non-ndb" title="Replication from NDB to other storage engines"> Replication from NDB to other storage engines </a> , and <a class="xref" href="mysql-cluster-replication-issues.html#mysql-cluster-replication-ndb-to-nontransactional" title="Replication from NDB to a nontransactional storage engine"> Replication from NDB to a nontransactional storage engine </a> , for more information. </p> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> For insert conflict resolution using <code class="literal"> NDB$MAX_INS() </code> or <code class="literal"> NDB$MAX_DEL_WIN_INS() </code> , an SQL node (that is, a <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> process) can record row updates on the source cluster as <code class="literal"> WRITE_ROW </code> events with the <a class="link" href="mysql-cluster-options-variables.html#option_mysqld_ndb-log-update-as-write"> <code class="option"> --ndb-log-update-as-write </code> </a> option enabled for idempotency and optimal size. This works for these algorithms since they both map a <code class="literal"> WRITE_ROW </code> event to an insert or update depending on whether the row already exists, and the required metadata (the <span class="quote"> “ <span class="quote"> after </span> ” </span> image for the timestamp column) is present in the <span class="quote"> “ <span class="quote"> WRITE_ROW </span> ” </span> event. </p> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/regexp.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="regexp"> </a> 14.8.2 Regular Expressions </h3> </div> </div> </div> <a class="indexterm" name="idm46045202491536"> </a> <a class="indexterm" name="idm46045202490464"> </a> <a class="indexterm" name="idm46045202489392"> </a> <a class="indexterm" name="idm46045202488304"> </a> <div class="table"> <a name="idm46045202486816"> </a> <p class="title"> <b> Table 14.14 Regular Expression Functions and Operators </b> </p> <div class="table-contents"> <table frame="box" rules="all" summary="A reference that lists regular expression functions and operators."> <colgroup> <col style="width: 28%"/> <col style="width: 71%"/> </colgroup> <thead> <tr> <th> Name </th> <th> Description </th> </tr> </thead> <tbody> <tr> <td> <a class="link" href="regexp.html#operator_not-regexp"> <code class="literal"> NOT REGEXP </code> </a> </td> <td> Negation of REGEXP </td> </tr> <tr> <td> <a class="link" href="regexp.html#operator_regexp"> <code class="literal"> REGEXP </code> </a> </td> <td> Whether string matches regular expression </td> </tr> <tr> <td> <a class="link" href="regexp.html#function_regexp-instr"> <code class="literal"> REGEXP_INSTR() </code> </a> </td> <td> Starting index of substring matching regular expression </td> </tr> <tr> <td> <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> </td> <td> Whether string matches regular expression </td> </tr> <tr> <td> <a class="link" href="regexp.html#function_regexp-replace"> <code class="literal"> REGEXP_REPLACE() </code> </a> </td> <td> Replace substrings matching regular expression </td> </tr> <tr> <td> <a class="link" href="regexp.html#function_regexp-substr"> <code class="literal"> REGEXP_SUBSTR() </code> </a> </td> <td> Return substring matching regular expression </td> </tr> <tr> <td> <a class="link" href="regexp.html#operator_regexp"> <code class="literal"> RLIKE </code> </a> </td> <td> Whether string matches regular expression </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <p> A regular expression is a powerful way of specifying a pattern for a complex search. This section discusses the functions and operators available for regular expression matching and illustrates, with examples, some of the special characters and constructs that can be used for regular expression operations. See also <a class="xref" href="pattern-matching.html" title="5.3.4.7 Pattern Matching"> Section 5.3.4.7, “Pattern Matching” </a> . </p> <p> MySQL implements regular expression support using International Components for Unicode (ICU), which provides full Unicode support and is multibyte safe. </p> <p> Use of a binary string with any of the MySQL regular expression functions is rejected with <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_character_set_mismatch" target="_top"> <code class="literal"> ER_CHARACTER_SET_MISMATCH </code> </a> . </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="regexp.html#regexp-operator-descriptions" title="Regular Expression Function and Operator Descriptions"> Regular Expression Function and Operator Descriptions </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="regexp.html#regexp-syntax" title="Regular Expression Syntax"> Regular Expression Syntax </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="regexp.html#regexp-resource-control" title="Regular Expression Resource Control"> Regular Expression Resource Control </a> </p> </li> </ul> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="regexp-operator-descriptions"> </a> Regular Expression Function and Operator Descriptions </h4> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <a name="operator_not-regexp"> </a> <p> <a class="link" href="regexp.html#operator_not-regexp"> <code class="literal"> <em class="replaceable"> <code> expr </code> </em> NOT REGEXP <em class="replaceable"> <code> pat </code> </em> </code> </a> , <a class="link" href="regexp.html#operator_not-regexp"> <code class="literal"> <em class="replaceable"> <code> expr </code> </em> NOT RLIKE <em class="replaceable"> <code> pat </code> </em> </code> </a> </p> <a class="indexterm" name="idm46045202444368"> </a> <p> This is the same as <code class="literal"> NOT ( <em class="replaceable"> <code> expr </code> </em> REGEXP <em class="replaceable"> <code> pat </code> </em> ) </code> . </p> </li> <li class="listitem"> <a name="operator_regexp"> </a> <p> <a class="link" href="regexp.html#operator_regexp"> <code class="literal"> <em class="replaceable"> <code> expr </code> </em> REGEXP <em class="replaceable"> <code> pat </code> </em> </code> </a> , <a class="link" href="regexp.html#operator_regexp"> <code class="literal"> <em class="replaceable"> <code> expr </code> </em> RLIKE <em class="replaceable"> <code> pat </code> </em> </code> </a> </p> <a class="indexterm" name="idm46045202432976"> </a> <a class="indexterm" name="idm46045202431904"> </a> <p> Returns 1 if the string <em class="replaceable"> <code> expr </code> </em> matches the regular expression specified by the pattern <em class="replaceable"> <code> pat </code> </em> , 0 otherwise. If <em class="replaceable"> <code> expr </code> </em> or <em class="replaceable"> <code> pat </code> </em> is <code class="literal"> NULL </code> , the return value is <code class="literal"> NULL </code> . </p> <p> <a class="link" href="regexp.html#operator_regexp"> <code class="literal"> REGEXP </code> </a> and <a class="link" href="regexp.html#operator_regexp"> <code class="literal"> RLIKE </code> </a> are synonyms for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> <p> For additional information about how matching occurs, see the description for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51708473"><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">SELECT</span> <span class="token string">'Michael!'</span> <span class="token operator">REGEXP</span> <span class="token string">'.*'</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> <span class="token output"><span class="token punctuation">|</span> 'Michael!' REGEXP '.*' <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'new*\n*line'</span> <span class="token operator">REGEXP</span> <span class="token string">'new\\*.\\*line'</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> <span class="token output"><span class="token punctuation">|</span> 'new*\n*line' REGEXP 'new\\*.\\*line' <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> <span class="token output"><span class="token punctuation">|</span> 0 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'a'</span> <span class="token operator">REGEXP</span> <span class="token string">'^[a-d]'</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> <span class="token output"><span class="token punctuation">|</span> 'a' REGEXP '^[a<span class="token punctuation">-</span>d]' <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> <span class="token output"><span class="token punctuation">|</span> 1 <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></code></pre> </div> </li> <li class="listitem"> <a name="function_regexp-instr"> </a> <p> <a class="link" href="regexp.html#function_regexp-instr"> <code class="literal"> REGEXP_INSTR( <em class="replaceable"> <code> expr </code> </em> , <em class="replaceable"> <code> pat </code> </em> [, <em class="replaceable"> <code> pos </code> </em> [, <em class="replaceable"> <code> occurrence </code> </em> [, <em class="replaceable"> <code> return_option </code> </em> [, <em class="replaceable"> <code> match_type </code> </em> ]]]]) </code> </a> </p> <a class="indexterm" name="idm46045202408144"> </a> <p> Returns the starting index of the substring of the string <em class="replaceable"> <code> expr </code> </em> that matches the regular expression specified by the pattern <em class="replaceable"> <code> pat </code> </em> , 0 if there is no match. If <em class="replaceable"> <code> expr </code> </em> or <em class="replaceable"> <code> pat </code> </em> is <code class="literal"> NULL </code> , the return value is <code class="literal"> NULL </code> . Character indexes begin at 1. </p> <p> <a class="link" href="regexp.html#function_regexp-instr"> <code class="literal"> REGEXP_INSTR() </code> </a> takes these optional arguments: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <em class="replaceable"> <code> pos </code> </em> : The position in <em class="replaceable"> <code> expr </code> </em> at which to start the search. If omitted, the default is 1. </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> occurrence </code> </em> : Which occurrence of a match to search for. If omitted, the default is 1. </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> return_option </code> </em> : Which type of position to return. If this value is 0, <a class="link" href="regexp.html#function_regexp-instr"> <code class="literal"> REGEXP_INSTR() </code> </a> returns the position of the matched substring's first character. If this value is 1, <a class="link" href="regexp.html#function_regexp-instr"> <code class="literal"> REGEXP_INSTR() </code> </a> returns the position following the matched substring. If omitted, the default is 0. </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> match_type </code> </em> : A string that specifies how to perform matching. The meaning is as described for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> </li> </ul> </div> <p> For additional information about how matching occurs, see the description for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46406074"><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">SELECT</span> <span class="token function">REGEXP_INSTR</span><span class="token punctuation">(</span><span class="token string">'dog cat dog'</span><span class="token punctuation">,</span> <span class="token string">'dog'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_INSTR('dog cat dog', 'dog') <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_INSTR</span><span class="token punctuation">(</span><span class="token string">'dog cat dog'</span><span class="token punctuation">,</span> <span class="token string">'dog'</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_INSTR('dog cat dog', 'dog', 2) <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> <span class="token output"><span class="token punctuation">|</span> 9 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_INSTR</span><span class="token punctuation">(</span><span class="token string">'aa aaa aaaa'</span><span class="token punctuation">,</span> <span class="token string">'a{2}'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_INSTR('aa aaa aaaa', 'a{2}') <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_INSTR</span><span class="token punctuation">(</span><span class="token string">'aa aaa aaaa'</span><span class="token punctuation">,</span> <span class="token string">'a{4}'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_INSTR('aa aaa aaaa', 'a{4}') <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> <span class="token output"><span class="token punctuation">|</span> 8 <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></code></pre> </div> </li> <li class="listitem"> <a name="function_regexp-like"> </a> <p> <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE( <em class="replaceable"> <code> expr </code> </em> , <em class="replaceable"> <code> pat </code> </em> [, <em class="replaceable"> <code> match_type </code> </em> ]) </code> </a> </p> <a class="indexterm" name="idm46045202377232"> </a> <p> Returns 1 if the string <em class="replaceable"> <code> expr </code> </em> matches the regular expression specified by the pattern <em class="replaceable"> <code> pat </code> </em> , 0 otherwise. If <em class="replaceable"> <code> expr </code> </em> or <em class="replaceable"> <code> pat </code> </em> is <code class="literal"> NULL </code> , the return value is <code class="literal"> NULL </code> . </p> <p> The pattern can be an extended regular expression, the syntax for which is discussed in <a class="xref" href="regexp.html#regexp-syntax" title="Regular Expression Syntax"> Regular Expression Syntax </a> . The pattern need not be a literal string. For example, it can be specified as a string expression or table column. </p> <p> The optional <em class="replaceable"> <code> match_type </code> </em> argument is a string that may contain any or all the following characters specifying how to perform matching: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <code class="literal"> c </code> : Case-sensitive matching. </p> </li> <li class="listitem"> <p> <code class="literal"> i </code> : Case-insensitive matching. </p> </li> <li class="listitem"> <p> <code class="literal"> m </code> : Multiple-line mode. Recognize line terminators within the string. The default behavior is to match line terminators only at the start and end of the string expression. </p> </li> <li class="listitem"> <p> <code class="literal"> n </code> : The <code class="literal"> . </code> character matches line terminators. The default is for <code class="literal"> . </code> matching to stop at the end of a line. </p> </li> <li class="listitem"> <p> <code class="literal"> u </code> : Unix-only line endings. Only the newline character is recognized as a line ending by the <code class="literal"> . </code> , <code class="literal"> ^ </code> , and <code class="literal"> $ </code> match operators. </p> </li> </ul> </div> <p> If characters specifying contradictory options are specified within <em class="replaceable"> <code> match_type </code> </em> , the rightmost one takes precedence. </p> <p> By default, regular expression operations use the character set and collation of the <em class="replaceable"> <code> expr </code> </em> and <em class="replaceable"> <code> pat </code> </em> arguments when deciding the type of a character and performing the comparison. If the arguments have different character sets or collations, coercibility rules apply as described in <a class="xref" href="charset-collation-coercibility.html" title="12.8.4 Collation Coercibility in Expressions"> Section 12.8.4, “Collation Coercibility in Expressions” </a> . Arguments may be specified with explicit collation indicators to change comparison behavior. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa6957101"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'CamelCase'</span><span class="token punctuation">,</span> <span class="token string">'CAMELCASE'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_LIKE('CamelCase', 'CAMELCASE') <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'CamelCase'</span><span class="token punctuation">,</span> <span class="token string">'CAMELCASE'</span> <span class="token keyword">COLLATE</span> utf8mb4_0900_as_cs<span class="token punctuation">)</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> REGEXP_LIKE('CamelCase', 'CAMELCASE' COLLATE utf8mb4_0900_as_cs) <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 0 <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> <em class="replaceable"> <code> match_type </code> </em> may be specified with the <code class="literal"> c </code> or <code class="literal"> i </code> characters to override the default case sensitivity. Exception: If either argument is a binary string, the arguments are handled in case-sensitive fashion as binary strings, even if <em class="replaceable"> <code> match_type </code> </em> contains the <code class="literal"> i </code> character. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> MySQL uses C escape syntax in strings (for example, <code class="literal"> \n </code> to represent the newline character). If you want your <em class="replaceable"> <code> expr </code> </em> or <em class="replaceable"> <code> pat </code> </em> argument to contain a literal <code class="literal"> \ </code> , you must double it. (Unless the <a class="link" href="sql-mode.html#sqlmode_no_backslash_escapes"> <code class="literal"> NO_BACKSLASH_ESCAPES </code> </a> SQL mode is enabled, in which case no escape character is used.) </p> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99587389"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Michael!'</span><span class="token punctuation">,</span> <span class="token string">'.*'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_LIKE('Michael!', '.*') <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'new*\n*line'</span><span class="token punctuation">,</span> <span class="token string">'new\\*.\\*line'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_LIKE('new*\n*line', 'new\\*.\\*line') <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> <span class="token output"><span class="token punctuation">|</span> 0 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token string">'^[a-d]'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_LIKE('a', '^[a<span class="token punctuation">-</span>d]') <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> <span class="token output"><span class="token punctuation">|</span> 1 <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></code></pre> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47306581"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">,</span> <span class="token string">'ABC'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_LIKE('abc', 'ABC') <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">,</span> <span class="token string">'ABC'</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_LIKE('abc', 'ABC', 'c') <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> <span class="token output"><span class="token punctuation">|</span> 0 <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></code></pre> </div> </li> <li class="listitem"> <a name="function_regexp-replace"> </a> <p> <a class="link" href="regexp.html#function_regexp-replace"> <code class="literal"> REGEXP_REPLACE( <em class="replaceable"> <code> expr </code> </em> , <em class="replaceable"> <code> pat </code> </em> , <em class="replaceable"> <code> repl </code> </em> [, <em class="replaceable"> <code> pos </code> </em> [, <em class="replaceable"> <code> occurrence </code> </em> [, <em class="replaceable"> <code> match_type </code> </em> ]]]) </code> </a> </p> <a class="indexterm" name="idm46045202327888"> </a> <p> Replaces occurrences in the string <em class="replaceable"> <code> expr </code> </em> that match the regular expression specified by the pattern <em class="replaceable"> <code> pat </code> </em> with the replacement string <em class="replaceable"> <code> repl </code> </em> , and returns the resulting string. If <em class="replaceable"> <code> expr </code> </em> , <em class="replaceable"> <code> pat </code> </em> , or <em class="replaceable"> <code> repl </code> </em> is <code class="literal"> NULL </code> , the return value is <code class="literal"> NULL </code> . </p> <p> <a class="link" href="regexp.html#function_regexp-replace"> <code class="literal"> REGEXP_REPLACE() </code> </a> takes these optional arguments: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <em class="replaceable"> <code> pos </code> </em> : The position in <em class="replaceable"> <code> expr </code> </em> at which to start the search. If omitted, the default is 1. </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> occurrence </code> </em> : Which occurrence of a match to replace. If omitted, the default is 0 (which means <span class="quote"> “ <span class="quote"> replace all occurrences </span> ” </span> ). </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> match_type </code> </em> : A string that specifies how to perform matching. The meaning is as described for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> </li> </ul> </div> <p> The result returned by this function uses the character set and collation of the expression searched for matches. </p> <p> For additional information about how matching occurs, see the description for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60205605"><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">SELECT</span> <span class="token function">REGEXP_REPLACE</span><span class="token punctuation">(</span><span class="token string">'a b c'</span><span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token string">'X'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_REPLACE('a b c', 'b', 'X') <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> <span class="token output"><span class="token punctuation">|</span> a X c <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_REPLACE</span><span class="token punctuation">(</span><span class="token string">'abc def ghi'</span><span class="token punctuation">,</span> <span class="token string">'[a-z]+'</span><span class="token punctuation">,</span> <span class="token string">'X'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_REPLACE('abc def ghi', '[a<span class="token punctuation">-</span>z]<span class="token punctuation">+</span>', 'X', 1, 3) <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> <span class="token output"><span class="token punctuation">|</span> abc def X <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></code></pre> </div> </li> <li class="listitem"> <a name="function_regexp-substr"> </a> <p> <a class="link" href="regexp.html#function_regexp-substr"> <code class="literal"> REGEXP_SUBSTR( <em class="replaceable"> <code> expr </code> </em> , <em class="replaceable"> <code> pat </code> </em> [, <em class="replaceable"> <code> pos </code> </em> [, <em class="replaceable"> <code> occurrence </code> </em> [, <em class="replaceable"> <code> match_type </code> </em> ]]]) </code> </a> </p> <a class="indexterm" name="idm46045202300352"> </a> <p> Returns the substring of the string <em class="replaceable"> <code> expr </code> </em> that matches the regular expression specified by the pattern <em class="replaceable"> <code> pat </code> </em> , <code class="literal"> NULL </code> if there is no match. If <em class="replaceable"> <code> expr </code> </em> or <em class="replaceable"> <code> pat </code> </em> is <code class="literal"> NULL </code> , the return value is <code class="literal"> NULL </code> . </p> <p> <a class="link" href="regexp.html#function_regexp-substr"> <code class="literal"> REGEXP_SUBSTR() </code> </a> takes these optional arguments: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <em class="replaceable"> <code> pos </code> </em> : The position in <em class="replaceable"> <code> expr </code> </em> at which to start the search. If omitted, the default is 1. </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> occurrence </code> </em> : Which occurrence of a match to search for. If omitted, the default is 1. </p> </li> <li class="listitem"> <p> <em class="replaceable"> <code> match_type </code> </em> : A string that specifies how to perform matching. The meaning is as described for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> </li> </ul> </div> <p> The result returned by this function uses the character set and collation of the expression searched for matches. </p> <p> For additional information about how matching occurs, see the description for <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40903981"><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">SELECT</span> <span class="token function">REGEXP_SUBSTR</span><span class="token punctuation">(</span><span class="token string">'abc def ghi'</span><span class="token punctuation">,</span> <span class="token string">'[a-z]+'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_SUBSTR('abc def ghi', '[a<span class="token punctuation">-</span>z]<span class="token punctuation">+</span>') <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> <span class="token output"><span class="token punctuation">|</span> abc <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_SUBSTR</span><span class="token punctuation">(</span><span class="token string">'abc def ghi'</span><span class="token punctuation">,</span> <span class="token string">'[a-z]+'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> REGEXP_SUBSTR('abc def ghi', '[a<span class="token punctuation">-</span>z]<span class="token punctuation">+</span>', 1, 3) <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> <span class="token output"><span class="token punctuation">|</span> ghi <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></code></pre> </div> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="regexp-syntax"> </a> Regular Expression Syntax </h4> </div> </div> </div> <p> A regular expression describes a set of strings. The simplest regular expression is one that has no special characters in it. For example, the regular expression <code class="literal"> hello </code> matches <code class="literal"> hello </code> and nothing else. </p> <p> Nontrivial regular expressions use certain special constructs so that they can match more than one string. For example, the regular expression <code class="literal"> hello|world </code> contains the <code class="literal"> | </code> alternation operator and matches either the <code class="literal"> hello </code> or <code class="literal"> world </code> . </p> <p> As a more complex example, the regular expression <code class="literal"> B[an]*s </code> matches any of the strings <code class="literal"> Bananas </code> , <code class="literal"> Baaaaas </code> , <code class="literal"> Bs </code> , and any other string starting with a <code class="literal"> B </code> , ending with an <code class="literal"> s </code> , and containing any number of <code class="literal"> a </code> or <code class="literal"> n </code> characters in between. </p> <p> The following list covers some of the basic special characters and constructs that can be used in regular expressions. For information about the full regular expression syntax supported by the ICU library used to implement regular expression support, visit the <a class="ulink" href="https://unicode-org.github.io/icu/userguide/" target="_blank"> International Components for Unicode web site </a> . </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> ^ </code> </p> <p> Match the beginning of a string. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11036312"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fo\nfo'</span><span class="token punctuation">,</span> <span class="token string">'^fo$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fofo'</span><span class="token punctuation">,</span> <span class="token string">'^fo'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> $ </code> </p> <p> Match the end of a string. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa91304811"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fo\no'</span><span class="token punctuation">,</span> <span class="token string">'^fo\no$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fo\no'</span><span class="token punctuation">,</span> <span class="token string">'^fo$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> . </code> </p> <p> Match any character (including carriage return and newline, although to match these in the middle of a string, the <code class="literal"> m </code> (multiple line) match-control character or the <code class="literal"> (?m) </code> within-pattern modifier must be given). </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84742501"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fofo'</span><span class="token punctuation">,</span> <span class="token string">'^f.*$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fo\r\nfo'</span><span class="token punctuation">,</span> <span class="token string">'^f.*$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fo\r\nfo'</span><span class="token punctuation">,</span> <span class="token string">'^f.*$'</span><span class="token punctuation">,</span> <span class="token string">'m'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'fo\r\nfo'</span><span class="token punctuation">,</span> <span class="token string">'(?m)^f.*$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> a* </code> </p> <p> Match any sequence of zero or more <code class="literal"> a </code> characters. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70442481"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Ban'</span><span class="token punctuation">,</span> <span class="token string">'^Ba*n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Baaan'</span><span class="token punctuation">,</span> <span class="token string">'^Ba*n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Bn'</span><span class="token punctuation">,</span> <span class="token string">'^Ba*n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> a+ </code> </p> <p> Match any sequence of one or more <code class="literal"> a </code> characters. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69446014"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Ban'</span><span class="token punctuation">,</span> <span class="token string">'^Ba+n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Bn'</span><span class="token punctuation">,</span> <span class="token string">'^Ba+n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> a? </code> </p> <p> Match either zero or one <code class="literal"> a </code> character. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38834136"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Bn'</span><span class="token punctuation">,</span> <span class="token string">'^Ba?n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Ban'</span><span class="token punctuation">,</span> <span class="token string">'^Ba?n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'Baan'</span><span class="token punctuation">,</span> <span class="token string">'^Ba?n'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> de|abc </code> </p> <p> Alternation; match either of the sequences <code class="literal"> de </code> or <code class="literal"> abc </code> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46986600"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'pi'</span><span class="token punctuation">,</span> <span class="token string">'pi|apa'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'axe'</span><span class="token punctuation">,</span> <span class="token string">'pi|apa'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'apa'</span><span class="token punctuation">,</span> <span class="token string">'pi|apa'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'apa'</span><span class="token punctuation">,</span> <span class="token string">'^(pi|apa)$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'pi'</span><span class="token punctuation">,</span> <span class="token string">'^(pi|apa)$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'pix'</span><span class="token punctuation">,</span> <span class="token string">'^(pi|apa)$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> (abc)* </code> </p> <p> Match zero or more instances of the sequence <code class="literal"> abc </code> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17589560"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'pi'</span><span class="token punctuation">,</span> <span class="token string">'^(pi)*$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'pip'</span><span class="token punctuation">,</span> <span class="token string">'^(pi)*$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'pipi'</span><span class="token punctuation">,</span> <span class="token string">'^(pi)*$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> {1} </code> , <code class="literal"> {2,3} </code> </p> <p> Repetition; <code class="literal"> { <em class="replaceable"> <code> n </code> </em> } </code> and <code class="literal"> { <em class="replaceable"> <code> m </code> </em> , <em class="replaceable"> <code> n </code> </em> } </code> notation provide a more general way of writing regular expressions that match many occurrences of the previous atom (or <span class="quote"> “ <span class="quote"> piece </span> ” </span> ) of the pattern. <em class="replaceable"> <code> m </code> </em> and <em class="replaceable"> <code> n </code> </em> are integers. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <code class="literal"> a* </code> </p> <p> Can be written as <code class="literal"> a{0,} </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> a+ </code> </p> <p> Can be written as <code class="literal"> a{1,} </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> a? </code> </p> <p> Can be written as <code class="literal"> a{0,1} </code> . </p> </li> </ul> </div> <p> To be more precise, <code class="literal"> a{ <em class="replaceable"> <code> n </code> </em> } </code> matches exactly <em class="replaceable"> <code> n </code> </em> instances of <code class="literal"> a </code> . <code class="literal"> a{ <em class="replaceable"> <code> n </code> </em> ,} </code> matches <em class="replaceable"> <code> n </code> </em> or more instances of <code class="literal"> a </code> . <code class="literal"> a{ <em class="replaceable"> <code> m </code> </em> , <em class="replaceable"> <code> n </code> </em> } </code> matches <em class="replaceable"> <code> m </code> </em> through <em class="replaceable"> <code> n </code> </em> instances of <code class="literal"> a </code> , inclusive. If both <em class="replaceable"> <code> m </code> </em> and <em class="replaceable"> <code> n </code> </em> are given, <em class="replaceable"> <code> m </code> </em> must be less than or equal to <em class="replaceable"> <code> n </code> </em> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa30274226"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'abcde'</span><span class="token punctuation">,</span> <span class="token string">'a[bcd]{2}e'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'abcde'</span><span class="token punctuation">,</span> <span class="token string">'a[bcd]{3}e'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'abcde'</span><span class="token punctuation">,</span> <span class="token string">'a[bcd]{1,10}e'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> [a-dX] </code> , <code class="literal"> [^a-dX] </code> </p> <p> Matches any character that is (or is not, if <code class="literal"> ^ </code> is used) either <code class="literal"> a </code> , <code class="literal"> b </code> , <code class="literal"> c </code> , <code class="literal"> d </code> or <code class="literal"> X </code> . A <code class="literal"> - </code> character between two other characters forms a range that matches all characters from the first character to the second. For example, <code class="literal"> [0-9] </code> matches any decimal digit. To include a literal <code class="literal"> ] </code> character, it must immediately follow the opening bracket <code class="literal"> [ </code> . To include a literal <code class="literal"> - </code> character, it must be written first or last. Any character that does not have a defined special meaning inside a <code class="literal"> [] </code> pair matches only itself. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa37885166"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'aXbc'</span><span class="token punctuation">,</span> <span class="token string">'[a-dXYZ]'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'aXbc'</span><span class="token punctuation">,</span> <span class="token string">'^[a-dXYZ]$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'aXbc'</span><span class="token punctuation">,</span> <span class="token string">'^[a-dXYZ]+$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'aXbc'</span><span class="token punctuation">,</span> <span class="token string">'^[^a-dXYZ]+$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'gheis'</span><span class="token punctuation">,</span> <span class="token string">'^[^a-dXYZ]+$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'gheisa'</span><span class="token punctuation">,</span> <span class="token string">'^[^a-dXYZ]+$'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> [=character_class=] </code> </p> <p> Within a bracket expression (written using <code class="literal"> [ </code> and <code class="literal"> ] </code> ), <code class="literal"> [=character_class=] </code> represents an equivalence class. It matches all characters with the same collation value, including itself. For example, if <code class="literal"> o </code> and <code class="literal"> (+) </code> are the members of an equivalence class, <code class="literal"> [[=o=]] </code> , <code class="literal"> [[=(+)=]] </code> , and <code class="literal"> [o(+)] </code> are all synonymous. An equivalence class may not be used as an endpoint of a range. </p> </li> <li class="listitem"> <p> <code class="literal"> [:character_class:] </code> </p> <p> Within a bracket expression (written using <code class="literal"> [ </code> and <code class="literal"> ] </code> ), <code class="literal"> [:character_class:] </code> represents a character class that matches all characters belonging to that class. The following table lists the standard class names. These names stand for the character classes defined in the <code class="literal"> ctype(3) </code> manual page. A particular locale may provide other class names. A character class may not be used as an endpoint of a range. </p> <div class="informaltable"> <table summary="Character class names and the meaning of each class."> <colgroup> <col style="width: 20%"/> <col style="width: 80%"/> </colgroup> <thead> <tr> <th> Character Class Name </th> <th> Meaning </th> </tr> </thead> <tbody> <tr> <td> <code class="literal"> alnum </code> </td> <td> Alphanumeric characters </td> </tr> <tr> <td> <code class="literal"> alpha </code> </td> <td> Alphabetic characters </td> </tr> <tr> <td> <code class="literal"> blank </code> </td> <td> Whitespace characters </td> </tr> <tr> <td> <code class="literal"> cntrl </code> </td> <td> Control characters </td> </tr> <tr> <td> <code class="literal"> digit </code> </td> <td> Digit characters </td> </tr> <tr> <td> <code class="literal"> graph </code> </td> <td> Graphic characters </td> </tr> <tr> <td> <code class="literal"> lower </code> </td> <td> Lowercase alphabetic characters </td> </tr> <tr> <td> <code class="literal"> print </code> </td> <td> Graphic or space characters </td> </tr> <tr> <td> <code class="literal"> punct </code> </td> <td> Punctuation characters </td> </tr> <tr> <td> <code class="literal"> space </code> </td> <td> Space, tab, newline, and carriage return </td> </tr> <tr> <td> <code class="literal"> upper </code> </td> <td> Uppercase alphabetic characters </td> </tr> <tr> <td> <code class="literal"> xdigit </code> </td> <td> Hexadecimal digit characters </td> </tr> </tbody> </table> </div> <div class="informaltable"> <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 431px; width: 709px;"> <thead> <tr> <th style="width: 141.594px;"> Character Class Name </th> <th style="width: 566.406px;"> Meaning </th> </tr> </thead> </table> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59116385"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'justalnums'</span><span class="token punctuation">,</span> <span class="token string">'[[:alnum:]]+'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'!!'</span><span class="token punctuation">,</span> <span class="token string">'[[:alnum:]]+'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </li> </ul> </div> <p> To use a literal instance of a special character in a regular expression, precede it by two backslash (\) characters. The MySQL parser interprets one of the backslashes, and the regular expression library interprets the other. For example, to match the string <code class="literal"> 1+2 </code> that contains the special <code class="literal"> + </code> character, only the last of the following regular expressions is the correct one: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa94567478"><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">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'1+2'</span><span class="token punctuation">,</span> <span class="token string">'1+2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'1+2'</span><span class="token punctuation">,</span> <span class="token string">'1\+2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">REGEXP_LIKE</span><span class="token punctuation">(</span><span class="token string">'1+2'</span><span class="token punctuation">,</span> <span class="token string">'1\\+2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="regexp-resource-control"> </a> Regular Expression Resource Control </h4> </div> </div> </div> <p> <a class="link" href="regexp.html#function_regexp-like"> <code class="literal"> REGEXP_LIKE() </code> </a> and similar functions use resources that can be controlled by setting system variables: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The match engine uses memory for its internal stack. To control the maximum available memory for the stack in bytes, set the <a class="link" href="server-system-variables.html#sysvar_regexp_stack_limit"> <code class="literal"> regexp_stack_limit </code> </a> system variable. </p> </li> <li class="listitem"> <p> The match engine operates in steps. To control the maximum number of steps performed by the engine (and thus indirectly the execution time), set the <a class="link" href="server-system-variables.html#sysvar_regexp_time_limit"> <code class="literal"> regexp_time_limit </code> </a> system variable. Because this limit is expressed as number of steps, it affects execution time only indirectly. Typically, it is on the order of milliseconds. </p> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/component-statements.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="component-statements"> </a> 15.7.4 Component, Plugin, and Loadable Function Statements </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="create-function-loadable.html"> 15.7.4.1 CREATE FUNCTION Statement for Loadable Functions </a> </span> </dt> <dt> <span class="section"> <a href="drop-function-loadable.html"> 15.7.4.2 DROP FUNCTION Statement for Loadable Functions </a> </span> </dt> <dt> <span class="section"> <a href="install-component.html"> 15.7.4.3 INSTALL COMPONENT Statement </a> </span> </dt> <dt> <span class="section"> <a href="install-plugin.html"> 15.7.4.4 INSTALL PLUGIN Statement </a> </span> </dt> <dt> <span class="section"> <a href="uninstall-component.html"> 15.7.4.5 UNINSTALL COMPONENT Statement </a> </span> </dt> <dt> <span class="section"> <a href="uninstall-plugin.html"> 15.7.4.6 UNINSTALL PLUGIN Statement </a> </span> </dt> </dl> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/privilege-changes.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="privilege-changes"> </a> 8.2.13 When Privilege Changes Take Effect </h3> </div> </div> </div> <a class="indexterm" name="idm46045248776432"> </a> <a class="indexterm" name="idm46045248774976"> </a> <p> If the <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> server is started without the <a class="link" href="server-options.html#option_mysqld_skip-grant-tables"> <code class="option"> --skip-grant-tables </code> </a> option, it reads all grant table contents into memory during its startup sequence. The in-memory tables become effective for access control at that point. </p> <p> If you modify the grant tables indirectly using an account-management statement, the server notices these changes and loads the grant tables into memory again immediately. Account-management statements are described in <a class="xref" href="account-management-statements.html" title="15.7.1 Account Management Statements"> Section 15.7.1, “Account Management Statements” </a> . Examples include <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement"> <code class="literal"> GRANT </code> </a> , <a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement"> <code class="literal"> REVOKE </code> </a> , <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement"> <code class="literal"> SET PASSWORD </code> </a> , and <a class="link" href="rename-user.html" title="15.7.1.7 RENAME USER Statement"> <code class="literal"> RENAME USER </code> </a> . </p> <p> If you modify the grant tables directly 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> (which is not recommended), the changes have no effect on privilege checking until you either tell the server to reload the tables or restart it. Thus, if you change the grant tables directly but forget to reload them, the changes have <span class="emphasis"> <em> no effect </em> </span> until you restart the server. This may leave you wondering why your changes seem to make no difference! </p> <p> To tell the server to reload the grant tables, perform a flush-privileges operation. This can be done by issuing a <a class="link" href="flush.html#flush-privileges"> <code class="literal"> FLUSH PRIVILEGES </code> </a> statement or by executing a <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program"> <span class="command"> <strong> mysqladmin flush-privileges </strong> </span> </a> or <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> command. </p> <p> A grant table reload affects privileges for each existing client session as follows: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Table and column privilege changes take effect with the client's next request. </p> </li> <li class="listitem"> <p> Database privilege changes take effect the next time the client executes a <code class="literal"> USE <em class="replaceable"> <code> db_name </code> </em> </code> statement. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Client applications may cache the database name; thus, this effect may not be visible to them without actually changing to a different database. </p> </div> </li> <li class="listitem"> <p> Static global privileges and passwords are unaffected for a connected client. These changes take effect only in sessions for subsequent connections. Changes to dynamic global privileges apply immediately. For information about the differences between static and dynamic privileges, see <a class="xref" href="privileges-provided.html#static-dynamic-privileges" title="Static Versus Dynamic Privileges"> Static Versus Dynamic Privileges </a> .) </p> </li> </ul> </div> <p> Changes to the set of active roles within a session take effect immediately, for that session only. The <a class="link" href="set-role.html" title="15.7.1.11 SET ROLE Statement"> <code class="literal"> SET ROLE </code> </a> statement performs session role activation and deactivation (see <a class="xref" href="set-role.html" title="15.7.1.11 SET ROLE Statement"> Section 15.7.1.11, “SET ROLE Statement” </a> ). </p> <p> If the server is started with the <a class="link" href="server-options.html#option_mysqld_skip-grant-tables"> <code class="option"> --skip-grant-tables </code> </a> option, it does not read the grant tables or implement any access control. Any user can connect and perform any operation, <span class="emphasis"> <em> which is insecure. </em> </span> To cause a server thus started to read the tables and enable access checking, flush the privileges. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/deleting-from-related-tables.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="deleting-from-related-tables"> </a> B.3.4.6 Deleting Rows from Related Tables </h4> </div> </div> </div> <a class="indexterm" name="idm46045053488688"> </a> <a class="indexterm" name="idm46045053487232"> </a> <a class="indexterm" name="idm46045053485744"> </a> <p> If the total length of the <a class="link" href="delete.html" title="15.2.2 DELETE Statement"> <code class="literal"> DELETE </code> </a> statement for <code class="literal"> related_table </code> is more than the default value of the <a class="link" href="server-system-variables.html#sysvar_max_allowed_packet"> <code class="literal"> max_allowed_packet </code> </a> system variable, you should split it into smaller parts and execute multiple <a class="link" href="delete.html" title="15.2.2 DELETE Statement"> <code class="literal"> DELETE </code> </a> statements. You probably get the fastest <a class="link" href="delete.html" title="15.2.2 DELETE Statement"> <code class="literal"> DELETE </code> </a> by specifying only 100 to 1,000 <code class="literal"> related_column </code> values per statement if the <code class="literal"> related_column </code> is indexed. If the <code class="literal"> related_column </code> is not indexed, the speed is independent of the number of arguments in the <code class="literal"> IN </code> clause. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-tp-thread-group-state-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="performance-schema-tp-thread-group-state-table"> </a> 29.12.16.2 The tp_thread_group_state Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045069841152"> </a> <a class="indexterm" name="idm46045069839648"> </a> <p> The <a class="link" href="performance-schema-tp-thread-group-state-table.html" title="29.12.16.2 The tp_thread_group_state Table"> <code class="literal"> tp_thread_group_state </code> </a> table has one row per thread group in the thread pool. Each row provides information about the current state of a group. </p> <p> The <a class="link" href="performance-schema-tp-thread-group-state-table.html" title="29.12.16.2 The tp_thread_group_state Table"> <code class="literal"> tp_thread_group_state </code> </a> table has these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> TP_GROUP_ID </code> </p> <p> The thread group ID. This is a unique key within the table. </p> </li> <li class="listitem"> <p> <code class="literal"> CONSUMER THREADS </code> </p> <p> The number of consumer threads. There is at most one thread ready to start executing if the active threads become stalled or blocked. </p> </li> <li class="listitem"> <p> <code class="literal"> RESERVE_THREADS </code> </p> <p> The number of threads in the reserved state. This means that they are not started until there is a need to wake a new thread and there is no consumer thread. This is where most threads end up when the thread group has created more threads than needed for normal operation. Often a thread group needs additional threads for a short while and then does not need them again for a while. In this case, they go into the reserved state and remain until needed again. They take up some extra memory resources, but no extra computing resources. </p> </li> <li class="listitem"> <p> <code class="literal"> CONNECT_THREAD_COUNT </code> </p> <p> The number of threads that are processing or waiting to process connection initialization and authentication. There can be a maximum of four connection threads per thread group; these threads expire after a period of inactivity. </p> </li> <li class="listitem"> <p> <code class="literal"> CONNECTION_COUNT </code> </p> <p> The number of connections using this thread group. </p> </li> <li class="listitem"> <p> <code class="literal"> QUEUED_QUERIES </code> </p> <p> The number of statements waiting in the high-priority queue. </p> </li> <li class="listitem"> <p> <code class="literal"> QUEUED_TRANSACTIONS </code> </p> <p> The number of statements waiting in the low-priority queue. These are the initial statements for transactions that have not started, so they also represent queued transactions. </p> </li> <li class="listitem"> <p> <code class="literal"> STALL_LIMIT </code> </p> <p> The value of the <a class="link" href="server-system-variables.html#sysvar_thread_pool_stall_limit"> <code class="literal"> thread_pool_stall_limit </code> </a> system variable for the thread group. This is the same value for all thread groups. </p> </li> <li class="listitem"> <p> <code class="literal"> PRIO_KICKUP_TIMER </code> </p> <p> The value of the <a class="link" href="server-system-variables.html#sysvar_thread_pool_prio_kickup_timer"> <code class="literal"> thread_pool_prio_kickup_timer </code> </a> system variable for the thread group. This is the same value for all thread groups. </p> </li> <li class="listitem"> <p> <code class="literal"> ALGORITHM </code> </p> <p> The value of the <a class="link" href="server-system-variables.html#sysvar_thread_pool_algorithm"> <code class="literal"> thread_pool_algorithm </code> </a> system variable for the thread group. This is the same value for all thread groups. </p> </li> <li class="listitem"> <p> <code class="literal"> THREAD_COUNT </code> </p> <p> The number of threads started in the thread pool as part of this thread group. </p> </li> <li class="listitem"> <p> <code class="literal"> ACTIVE_THREAD_COUNT </code> </p> <p> The number of threads active in executing statements. </p> </li> <li class="listitem"> <p> <code class="literal"> STALLED_THREAD_COUNT </code> </p> <p> The number of stalled statements in the thread group. A stalled statement could be executing, but from a thread pool perspective it is stalled and making no progress. A long-running statement quickly ends up in this category. </p> </li> <li class="listitem"> <p> <code class="literal"> WAITING_THREAD_NUMBER </code> </p> <p> If there is a thread handling the polling of statements in the thread group, this specifies the thread number within this thread group. It is possible that this thread could be executing a statement. </p> </li> <li class="listitem"> <p> <code class="literal"> OLDEST_QUEUED </code> </p> <p> How long in milliseconds the oldest queued statement has been waiting for execution. </p> </li> <li class="listitem"> <p> <code class="literal"> MAX_THREAD_IDS_IN_GROUP </code> </p> <p> The maximum thread ID of the threads in the group. This is the same as <a class="link" href="aggregate-functions.html#function_max"> <code class="literal"> MAX(TP_THREAD_NUMBER) </code> </a> for the threads when selected from the <a class="link" href="performance-schema-tp-thread-state-table.html" title="29.12.16.4 The tp_thread_state Table"> <code class="literal"> tp_thread_state </code> </a> table. That is, these two queries are equivalent: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa20801702"><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> TP_GROUP_ID<span class="token punctuation">,</span> MAX_THREAD_IDS_IN_GROUP <span class="token keyword">FROM</span> tp_thread_group_state<span class="token punctuation">;</span> <span class="token keyword">SELECT</span> TP_GROUP_ID<span class="token punctuation">,</span> <span class="token function">MAX</span><span class="token punctuation">(</span>TP_THREAD_NUMBER<span class="token punctuation">)</span> <span class="token keyword">FROM</span> tp_thread_state <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> TP_GROUP_ID<span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <code class="literal"> EFFECTIVE_MAX_TRANSACTIONS_LIMIT </code> </p> <p> The effective <code class="literal"> max_transactions_limit_per_tg </code> value for the group. </p> </li> <li class="listitem"> <p> <code class="literal"> NUM_QUERY_THREADS </code> </p> <p> The number of worker threads in the group. </p> </li> <li class="listitem"> <p> <code class="literal"> TIME_OF_LAST_THREAD_CREATION </code> </p> <p> The point in time when the thread was last created. </p> </li> <li class="listitem"> <p> <code class="literal"> NUM_CONNECT_HANDLER_THREAD_IN_SLEEP </code> </p> <p> The number of inactive connection handler threads. </p> </li> <li class="listitem"> <p> <code class="literal"> THREADS_BOUND_TO_TRANSACTION </code> </p> <p> The number of threads in an active transaction, which must be less than <code class="literal"> thread_pool_max_transactions_limit </code> ; this is set only when <code class="literal"> thread_pool_max_transactions_limit </code> is not <code class="literal"> 0 </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> QUERY_THREADS_COUNT </code> </p> <p> same as num_query_threads, but used for different purposes? </p> </li> <li class="listitem"> <p> <code class="literal"> TIME_OF_EARLIEST_CON_EXPIRE </code> </p> <p> A timestamp showing the earliest point in time when a connection is expected to expire. </p> </li> </ul> </div> <p> The <a class="link" href="performance-schema-tp-thread-group-state-table.html" title="29.12.16.2 The tp_thread_group_state Table"> <code class="literal"> tp_thread_group_state </code> </a> table has one index; this is a unique index on the <code class="literal"> TP_GROUP_ID </code> column. </p> <p> <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> is not permitted for the <a class="link" href="performance-schema-tp-thread-group-state-table.html" title="29.12.16.2 The tp_thread_group_state Table"> <code class="literal"> tp_thread_group_state </code> </a> table. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-enterprise-backup.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="mysql-enterprise-backup"> </a> 32.1 MySQL Enterprise Backup Overview </h2> </div> </div> </div> <a class="indexterm" name="idm46045060255056"> </a> <a class="indexterm" name="idm46045060254016"> </a> <a class="indexterm" name="idm46045060252944"> </a> <p> MySQL Enterprise Backup performs hot backup operations for MySQL databases. The product is architected for efficient and reliable backups of tables created by the InnoDB storage engine. For completeness, it can also back up tables from MyISAM and other storage engines. </p> <p> The following discussion briefly summarizes MySQL Enterprise Backup. For more information, see the MySQL Enterprise Backup manual, available at <a class="ulink" href="/doc/mysql-enterprise-backup/en/" target="_top"> https://dev.mysql.com/doc/mysql-enterprise-backup/en/ </a> . </p> <p> Hot backups are performed while the database is running and applications are reading and writing to it. This type of backup does not block normal database operations, and it captures even changes that occur while the backup is happening. For these reasons, hot backups are desirable when your database <span class="quote"> “ <span class="quote"> grows up </span> ” </span> -- when the data is large enough that the backup takes significant time, and when your data is important enough to your business that you must capture every last change, without taking your application, website, or web service offline. </p> <p> MySQL Enterprise Backup does a hot backup of all tables that use the InnoDB storage engine. For tables using MyISAM or other non-InnoDB storage engines, it does a <span class="quote"> “ <span class="quote"> warm </span> ” </span> backup, where the database continues to run, but those tables cannot be modified while being backed up. For efficient backup operations, you can designate InnoDB as the default storage engine for new tables, or convert existing tables to use the InnoDB storage engine. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/json-table-functions.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="json-table-functions"> </a> 14.17.6 JSON Table Functions </h3> </div> </div> </div> <p> This section contains information about JSON functions that convert JSON data to tabular data. MySQL 8.4 supports one such function, <code class="literal"> JSON_TABLE() </code> . </p> <p> <a name="function_json-table"> </a> <a class="link" href="json-table-functions.html#function_json-table"> <code class="literal"> JSON_TABLE( <em class="replaceable"> <code> expr </code> </em> , <em class="replaceable"> <code> path </code> </em> COLUMNS ( <em class="replaceable"> <code> column_list </code> </em> ) [AS] <em class="replaceable"> <code> alias </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045194660016"> </a> <p> Extracts data from a JSON document and returns it as a relational table having the specified columns. The complete syntax for this function is shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-clike"><div class="docs-select-all right" id="sa8508545"><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"><span class="token function">JSON_TABLE</span><span class="token punctuation">(</span> <em class="replaceable">expr</em><span class="token punctuation">,</span> <em class="replaceable">path</em> COLUMNS <span class="token punctuation">(</span><em class="replaceable">column_list</em><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">[</span>AS<span class="token punctuation">]</span> <em class="replaceable">alias</em> <em class="replaceable">column_list</em><span class="token punctuation">:</span> <em class="replaceable">column</em><span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">column</em><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span> <em class="replaceable">column</em><span class="token punctuation">:</span> <em class="replaceable">name</em> FOR ORDINALITY <span class="token operator">|</span> <em class="replaceable">name</em> <em class="replaceable">type</em> PATH <em class="replaceable">string path</em> <span class="token punctuation">[</span><em class="replaceable">on_empty</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">on_error</em><span class="token punctuation">]</span> <span class="token operator">|</span> <em class="replaceable">name</em> <em class="replaceable">type</em> EXISTS PATH <em class="replaceable">string path</em> <span class="token operator">|</span> NESTED <span class="token punctuation">[</span>PATH<span class="token punctuation">]</span> <em class="replaceable">path</em> COLUMNS <span class="token punctuation">(</span><em class="replaceable">column_list</em><span class="token punctuation">)</span> <em class="replaceable">on_empty</em><span class="token punctuation">:</span> <span class="token punctuation">{</span>NULL <span class="token operator">|</span> DEFAULT <em class="replaceable">json_string</em> <span class="token operator">|</span> ERROR<span class="token punctuation">}</span> ON EMPTY <em class="replaceable">on_error</em><span class="token punctuation">:</span> <span class="token punctuation">{</span>NULL <span class="token operator">|</span> DEFAULT <em class="replaceable">json_string</em> <span class="token operator">|</span> ERROR<span class="token punctuation">}</span> ON ERROR</code></pre> </div> <p> <em class="replaceable"> <code> expr </code> </em> : This is an expression that returns JSON data. This can be a constant ( <code class="literal"> '{"a":1}' </code> ), a column ( <code class="literal"> t1.json_data </code> , given table <code class="literal"> t1 </code> specified prior to <code class="literal"> JSON_TABLE() </code> in the <code class="literal"> FROM </code> clause), or a function call ( <code class="literal"> JSON_EXTRACT(t1.json_data,'$.post.comments') </code> ). </p> <p> <em class="replaceable"> <code> path </code> </em> : A JSON path expression, which is applied to the data source. We refer to the JSON value matching the path as the <span class="emphasis"> <em> row source </em> </span> ; this is used to generate a row of relational data. The <code class="literal"> COLUMNS </code> clause evaluates the row source, finds specific JSON values within the row source, and returns those JSON values as SQL values in individual columns of a row of relational data. </p> <p> The <em class="replaceable"> <code> alias </code> </em> is required. The usual rules for table aliases apply (see <a class="xref" href="identifiers.html" title="11.2 Schema Object Names"> Section 11.2, “Schema Object Names” </a> ). </p> <p> This function compares column names in case-insensitive fashion. </p> <p> <code class="literal"> JSON_TABLE() </code> supports four types of columns, described in the following list: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> <code class="literal"> <em class="replaceable"> <code> name </code> </em> FOR ORDINALITY </code> : This type enumerates rows in the <code class="literal"> COLUMNS </code> clause; the column named <em class="replaceable"> <code> name </code> </em> is a counter whose type is <code class="literal"> UNSIGNED INT </code> , and whose initial value is 1. This is equivalent to specifying a column as <code class="literal"> AUTO_INCREMENT </code> in a <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> statement, and can be used to distinguish parent rows with the same value for multiple rows generated by a <code class="literal"> NESTED [PATH] </code> clause. </p> </li> <li class="listitem"> <p> <code class="literal"> <em class="replaceable"> <code> name </code> </em> <em class="replaceable"> <code> type </code> </em> PATH <em class="replaceable"> <code> string_path </code> </em> [ <em class="replaceable"> <code> on_empty </code> </em> ] [ <em class="replaceable"> <code> on_error </code> </em> ] </code> : Columns of this type are used to extract values specified by <em class="replaceable"> <code> string_path </code> </em> . <em class="replaceable"> <code> type </code> </em> is a MySQL scalar data type (that is, it cannot be an object or array). <code class="literal"> JSON_TABLE() </code> extracts data as JSON then coerces it to the column type, using the regular automatic type conversion applying to JSON data in MySQL. A missing value triggers the <em class="replaceable"> <code> on_empty </code> </em> clause. Saving an object or array triggers the optional <em class="replaceable"> <code> on error </code> </em> clause; this also occurs when an error takes place during coercion from the value saved as JSON to the table column, such as trying to save the string <code class="literal"> 'asd' </code> to an integer column. </p> </li> <li class="listitem"> <p> <code class="literal"> <em class="replaceable"> <code> name </code> </em> <em class="replaceable"> <code> type </code> </em> EXISTS PATH <em class="replaceable"> <code> path </code> </em> </code> : This column returns 1 if any data is present at the location specified by <em class="replaceable"> <code> path </code> </em> , and 0 otherwise. <em class="replaceable"> <code> type </code> </em> can be any valid MySQL data type, but should normally be specified as some variety of <a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT"> <code class="literal"> INT </code> </a> . </p> </li> <li class="listitem"> <p> <code class="literal"> NESTED [PATH] <em class="replaceable"> <code> path </code> </em> COLUMNS ( <em class="replaceable"> <code> column_list </code> </em> ) </code> : This flattens nested objects or arrays in JSON data into a single row along with the JSON values from the parent object or array. Using multiple <code class="literal"> PATH </code> options allows projection of JSON values from multiple levels of nesting into a single row. </p> <p> The <em class="replaceable"> <code> path </code> </em> is relative to the parent path row path of <code class="literal"> JSON_TABLE() </code> , or the path of the parent <code class="literal"> NESTED [PATH] </code> clause in the event of nested paths. </p> </li> </ol> </div> <p> <em class="replaceable"> <code> on empty </code> </em> , if specified, determines what <code class="literal"> JSON_TABLE() </code> does in the event that data is missing (depending on type). This clause is also triggered on a column in a <code class="literal"> NESTED PATH </code> clause when the latter has no match and a <code class="literal"> NULL </code> complemented row is produced for it. <em class="replaceable"> <code> on empty </code> </em> takes one of the following values: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> NULL ON EMPTY </code> : The column is set to <code class="literal"> NULL </code> ; this is the default behavior. </p> </li> <li class="listitem"> <p> <code class="literal"> DEFAULT <em class="replaceable"> <code> json_string </code> </em> ON EMPTY </code> : the provided <em class="replaceable"> <code> json_string </code> </em> is parsed as JSON, as long as it is valid, and stored instead of the missing value. Column type rules also apply to the default value. </p> </li> <li class="listitem"> <p> <code class="literal"> ERROR ON EMPTY </code> : An error is thrown. </p> </li> </ul> </div> <p> If used, <em class="replaceable"> <code> on_error </code> </em> takes one of the following values with the corresponding result as shown here: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> NULL ON ERROR </code> : The column is set to <code class="literal"> NULL </code> ; this is the default behavior. </p> </li> <li class="listitem"> <p> <code class="literal"> DEFAULT <em class="replaceable"> <code> json string </code> </em> ON ERROR </code> : The <em class="replaceable"> <code> json_string </code> </em> is parsed as JSON (provided that it is valid) and stored instead of the object or array. </p> </li> <li class="listitem"> <p> <code class="literal"> ERROR ON ERROR </code> : An error is thrown. </p> </li> </ul> </div> <p> Specifying <code class="literal"> ON ERROR </code> before <code class="literal"> ON EMPTY </code> is nonstandard and deprecated in MySQL; trying to do so causes the server to issue a warning. Expect support for the nonstandard syntax to be removed in a future version of MySQL. </p> <p> When a value saved to a column is truncated, such as saving 3.14159 in a <a class="link" href="fixed-point-types.html" title="13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC"> <code class="literal"> DECIMAL(10,1) </code> </a> column, a warning is issued independently of any <code class="literal"> ON ERROR </code> option. When multiple values are truncated in a single statement, the warning is issued only once. </p> <p> When the expression and path passed to this function resolve to JSON null, <code class="literal"> JSON_TABLE() </code> returns SQL <code class="literal"> NULL </code> , in accordance with the SQL standard, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59487310"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[ {"c1": null} ]'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token string">'$[*]'</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> c1 <span class="token datatype">INT</span> <span class="token keyword">PATH</span> <span class="token string">'$.c1'</span> <span class="token keyword">ERROR</span> <span class="token keyword">ON</span> <span class="token keyword">ERROR</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">as</span> jt<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> <span class="token output"><span class="token punctuation">|</span> c1 <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> <span class="token output"><span class="token punctuation">|</span> NULL <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> <span class="token output">1 row in set (0.00 sec)</span></code></pre> </div> <p> The following query demonstrates the use of <code class="literal"> ON EMPTY </code> and <code class="literal"> ON ERROR </code> . The row corresponding to <code class="literal"> {"b":1} </code> is empty for the path <code class="literal"> "$.a" </code> , and attempting to save <code class="literal"> [1,2] </code> as a scalar produces an error; these rows are highlighted in the output shown. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa15697702"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[{"a":"3"},{"a":2},{"b":1},{"a":0},{"a":[1,2]}]'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token string">"$[*]"</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> rowid <span class="token keyword">FOR</span> <span class="token keyword">ORDINALITY</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> ac <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">"$.a"</span> <span class="token keyword">DEFAULT</span> <span class="token string">'111'</span> <span class="token keyword">ON</span> <span class="token keyword">EMPTY</span> <span class="token keyword">DEFAULT</span> <span class="token string">'999'</span> <span class="token keyword">ON</span> <span class="token keyword">ERROR</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> aj <span class="token datatype">JSON</span> <span class="token keyword">PATH</span> <span class="token string">"$.a"</span> <span class="token keyword">DEFAULT</span> <span class="token string">'{"x": 333}'</span> <span class="token keyword">ON</span> <span class="token keyword">EMPTY</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> bx <span class="token datatype">INT</span> <span class="token keyword">EXISTS</span> <span class="token keyword">PATH</span> <span class="token string">"$.b"</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">AS</span> tt<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> <span class="token output"><span class="token punctuation">|</span> rowid <span class="token punctuation">|</span> ac <span class="token punctuation">|</span> aj <span class="token punctuation">|</span> bx <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> "3" <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation"></span><em><span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 111 <span class="token punctuation">|</span> {"x": 333} <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></em><span class="token punctuation"></span></span> <span class="token output"><span class="token punctuation">|</span> 4 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation"></span><em><span class="token punctuation">|</span> 5 <span class="token punctuation">|</span> 999 <span class="token punctuation">|</span> [1, 2] <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></em><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> <span class="token output">5 rows in set (0.00 sec)</span></code></pre> </div> <p> Column names are subject to the usual rules and limitations governing table column names. See <a class="xref" href="identifiers.html" title="11.2 Schema Object Names"> Section 11.2, “Schema Object Names” </a> . </p> <p> All JSON and JSON path expressions are checked for validity; an invalid expression of either type causes an error. </p> <p> Each match for the <em class="replaceable"> <code> path </code> </em> preceding the <code class="literal"> COLUMNS </code> keyword maps to an individual row in the result table. For example, the following query gives the result shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84892648"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[{"x":2,"y":"8"},{"x":"3","y":"7"},{"x":"4","y":6}]'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token string">"$[*]"</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> xval <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">"$.x"</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> yval <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">"$.y"</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">AS</span> jt1<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> <span class="token output"><span class="token punctuation">|</span> xval <span class="token punctuation">|</span> yval <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> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 8 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 7 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 4 <span class="token punctuation">|</span> 6 <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></code></pre> </div> <p> The expression <code class="literal"> "$[*]" </code> matches each element of the array. You can filter the rows in the result by modifying the path. For example, using <code class="literal"> "$[1]" </code> limits extraction to the second element of the JSON array used as the source, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa75478032"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[{"x":2,"y":"8"},{"x":"3","y":"7"},{"x":"4","y":6}]'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token string">"$[1]"</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> xval <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">"$.x"</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> yval <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">"$.y"</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">AS</span> jt1<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> <span class="token output"><span class="token punctuation">|</span> xval <span class="token punctuation">|</span> yval <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> <span class="token output"><span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 7 <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></code></pre> </div> <p> Within a column definition, <code class="literal"> "$" </code> passes the entire match to the column; <code class="literal"> "$.x" </code> and <code class="literal"> "$.y" </code> pass only the values corresponding to the keys <code class="literal"> x </code> and <code class="literal"> y </code> , respectively, within that match. For more information, see <a class="xref" href="json.html#json-path-syntax" title="JSON Path Syntax"> JSON Path Syntax </a> . </p> <p> <code class="literal"> NESTED PATH </code> (or simply <code class="literal"> NESTED </code> ; <code class="literal"> PATH </code> is optional) produces a set of records for each match in the <code class="literal"> COLUMNS </code> clause to which it belongs. If there is no match, all columns of the nested path are set to <code class="literal"> NULL </code> . This implements an outer join between the topmost clause and <code class="literal"> NESTED [PATH] </code> . An inner join can be emulated by applying a suitable condition in the <code class="literal"> WHERE </code> clause, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40620500"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[ {"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token string">'$[*]'</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> a <span class="token datatype">INT</span> <span class="token keyword">PATH</span> <span class="token string">'$.a'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">NESTED</span> <span class="token keyword">PATH</span> <span class="token string">'$.b[*]'</span> <span class="token keyword">COLUMNS</span> <span class="token punctuation">(</span>b <span class="token datatype">INT</span> <span class="token keyword">PATH</span> <span class="token string">'$'</span><span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">AS</span> jt <span class="token prompt"> -&gt;</span> <span class="token keyword">WHERE</span> b <span class="token operator">IS</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</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> <span class="token output"><span class="token punctuation">|</span> a <span class="token punctuation">|</span> b <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 11 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 111 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 22 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 222 <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></code></pre> </div> <p> Sibling nested paths—that is, two or more instances of <code class="literal"> NESTED [PATH] </code> in the same <code class="literal"> COLUMNS </code> clause—are processed one after another, one at a time. While one nested path is producing records, columns of any sibling nested path expressions are set to <code class="literal"> NULL </code> . This means that the total number of records for a single match within a single containing <code class="literal"> COLUMNS </code> clause is the sum and not the product of all records produced by <code class="literal"> NESTED [PATH] </code> modifiers, as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa55342212"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}]'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token string">'$[*]'</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> a <span class="token datatype">INT</span> <span class="token keyword">PATH</span> <span class="token string">'$.a'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">NESTED</span> <span class="token keyword">PATH</span> <span class="token string">'$.b[*]'</span> <span class="token keyword">COLUMNS</span> <span class="token punctuation">(</span>b1 <span class="token datatype">INT</span> <span class="token keyword">PATH</span> <span class="token string">'$'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">NESTED</span> <span class="token keyword">PATH</span> <span class="token string">'$.b[*]'</span> <span class="token keyword">COLUMNS</span> <span class="token punctuation">(</span>b2 <span class="token datatype">INT</span> <span class="token keyword">PATH</span> <span class="token string">'$'</span><span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">AS</span> jt<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> <span class="token output"><span class="token punctuation">|</span> a <span class="token punctuation">|</span> b1 <span class="token punctuation">|</span> b2 <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 11 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 111 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 11 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 111 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 22 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 222 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 22 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> 222 <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></code></pre> </div> <p> A <code class="literal"> FOR ORDINALITY </code> column enumerates records produced by the <code class="literal"> COLUMNS </code> clause, and can be used to distinguish parent records of a nested path, especially if values in parent records are the same, as can be seen here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa71578329"><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">SELECT</span> <span class="token operator">*</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> <span class="token prompt"> -&gt;</span> <span class="token string">'[{"a": "a_val", '</span><span class="token operator">&gt;</span> <span class="token string">"b"</span>: <span class="token punctuation">[</span>{<span class="token string">"c"</span>: <span class="token string">"c_val"</span><span class="token punctuation">,</span> <span class="token string">"l"</span>: <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">]</span>}<span class="token punctuation">]</span>}<span class="token punctuation">,</span> <span class="token string">'&gt; {"a": "a_val", '</span><span class="token operator">&gt;</span> <span class="token string">"b"</span>: <span class="token punctuation">[</span>{<span class="token string">"c"</span>: <span class="token string">"c_val"</span><span class="token punctuation">,</span><span class="token string">"l"</span>: <span class="token punctuation">[</span><span class="token number">11</span><span class="token punctuation">]</span>}<span class="token punctuation">,</span> {<span class="token string">"c"</span>: <span class="token string">"c_val"</span><span class="token punctuation">,</span> <span class="token string">"l"</span>: <span class="token punctuation">[</span><span class="token number">22</span><span class="token punctuation">]</span>}<span class="token punctuation">]</span>}<span class="token punctuation">]</span><span class="token string">', -&gt; '</span>$<span class="token punctuation">[</span><span class="token operator">*</span><span class="token punctuation">]</span><span class="token string">' COLUMNS( -&gt; top_ord FOR ORDINALITY, -&gt; apath VARCHAR(10) PATH '</span>$<span class="token punctuation">.</span>a<span class="token string">', -&gt; NESTED PATH '</span>$<span class="token punctuation">.</span>b<span class="token punctuation">[</span><span class="token operator">*</span><span class="token punctuation">]</span><span class="token string">' COLUMNS ( -&gt; bpath VARCHAR(10) PATH '</span>$<span class="token punctuation">.</span>c<span class="token string">', -&gt; ord FOR ORDINALITY, -&gt; NESTED PATH '</span>$<span class="token punctuation">.</span>l<span class="token punctuation">[</span><span class="token operator">*</span><span class="token punctuation">]</span><span class="token string">' COLUMNS (lpath varchar(10) PATH '</span>$'<span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token punctuation">)</span> <span class="token keyword">as</span> jt<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> <span class="token output"><span class="token punctuation">|</span> top_ord <span class="token punctuation">|</span> apath <span class="token punctuation">|</span> bpath <span class="token punctuation">|</span> ord <span class="token punctuation">|</span> lpath <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> a_val <span class="token punctuation">|</span> c_val <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> a_val <span class="token punctuation">|</span> c_val <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> a_val <span class="token punctuation">|</span> c_val <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 11 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> a_val <span class="token punctuation">|</span> c_val <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 22 <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></code></pre> </div> <p> The source document contains an array of two elements; each of these elements produces two rows. The values of <code class="literal"> apath </code> and <code class="literal"> bpath </code> are the same over the entire result set; this means that they cannot be used to determine whether <code class="literal"> lpath </code> values came from the same or different parents. The value of the <code class="literal"> ord </code> column remains the same as the set of records having <code class="literal"> top_ord </code> equal to 1, so these two values are from a single object. The remaining two values are from different objects, since they have different values in the <code class="literal"> ord </code> column. </p> <p> Normally, you cannot join a derived table which depends on columns of preceding tables in the same <code class="literal"> FROM </code> clause. MySQL, per the SQL standard, makes an exception for table functions; these are considered lateral derived tables. This is implicit, and for this reason is not allowed before <code class="literal"> JSON_TABLE() </code> , also according to the standard. </p> <p> Suppose you have a table <code class="literal"> t1 </code> created and populated using the statements shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69359500"><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">TABLE</span> t1 <span class="token punctuation">(</span>c1 <span class="token datatype">INT</span><span class="token punctuation">,</span> c2 <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span> c3 <span class="token datatype">JSON</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t1 <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'z'</span><span class="token punctuation">,</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token number">23</span><span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token number">27</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'y'</span><span class="token punctuation">,</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token number">44</span><span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token number">22</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">'x'</span><span class="token punctuation">,</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">'w'</span><span class="token punctuation">,</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">'v'</span><span class="token punctuation">,</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token number">123</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">,</span> <span class="token number">1111</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">;</span></code></pre> </div> <p> You can then execute joins, such as this one, in which <code class="literal"> JSON_TABLE() </code> acts as a derived table while at the same time it refers to a column in a previously referenced table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa52439386"><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> c1<span class="token punctuation">,</span> c2<span class="token punctuation">,</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span>c3<span class="token punctuation">,</span> <span class="token string">'$.*'</span><span class="token punctuation">)</span> <span class="token keyword">FROM</span> t1 <span class="token keyword">AS</span> m <span class="token keyword">JOIN</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span> m<span class="token punctuation">.</span>c3<span class="token punctuation">,</span> <span class="token string">'$.*'</span> <span class="token keyword">COLUMNS</span><span class="token punctuation">(</span> <span class="token keyword">at</span> <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">'$.a'</span> <span class="token keyword">DEFAULT</span> <span class="token string">'1'</span> <span class="token keyword">ON</span> <span class="token keyword">EMPTY</span><span class="token punctuation">,</span> bt <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">'$.b'</span> <span class="token keyword">DEFAULT</span> <span class="token string">'2'</span> <span class="token keyword">ON</span> <span class="token keyword">EMPTY</span><span class="token punctuation">,</span> ct <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">PATH</span> <span class="token string">'$.c'</span> <span class="token keyword">DEFAULT</span> <span class="token string">'3'</span> <span class="token keyword">ON</span> <span class="token keyword">EMPTY</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token keyword">AS</span> tt <span class="token keyword">ON</span> m<span class="token punctuation">.</span>c1 <span class="token operator">&gt;</span> tt<span class="token punctuation">.</span><span class="token keyword">at</span><span class="token punctuation">;</span></code></pre> </div> <p> Attempting to use the <code class="literal"> LATERAL </code> keyword with this query raises <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_parse_error" target="_top"> <code class="literal"> ER_PARSE_ERROR </code> </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/innodb-performance-ro-txn.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="innodb-performance-ro-txn"> </a> 10.5.3 Optimizing InnoDB Read-Only Transactions </h3> </div> </div> </div> <p> <code class="literal"> InnoDB </code> can avoid the overhead associated with setting up the <a class="link" href="glossary.html#glos_transaction_id" title="transaction ID"> transaction ID </a> ( <code class="literal"> TRX_ID </code> field) for transactions that are known to be read-only. A transaction ID is only needed for a <a class="link" href="glossary.html#glos_transaction" title="transaction"> transaction </a> that might perform write operations or <a class="link" href="glossary.html#glos_locking_read" title="locking read"> locking reads </a> such as <code class="literal"> SELECT ... FOR UPDATE </code> . Eliminating unnecessary transaction IDs reduces the size of internal data structures that are consulted each time a query or data change statement constructs a <a class="link" href="glossary.html#glos_read_view" title="read view"> read view </a> . </p> <p> <code class="literal"> InnoDB </code> detects read-only transactions when: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The transaction is started with the <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements"> <code class="literal"> START TRANSACTION READ ONLY </code> </a> statement. In this case, attempting to make changes to the database (for <code class="literal"> InnoDB </code> , <code class="literal"> MyISAM </code> , or other types of tables) causes an error, and the transaction continues in read-only state: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa37476308"><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-none">ERROR 1792 (25006): Cannot execute statement in a READ ONLY transaction.</code></pre> </div> <p> You can still make changes to session-specific temporary tables in a read-only transaction, or issue locking queries for them, because those changes and locks are not visible to any other transaction. </p> </li> <li class="listitem"> <p> The <a class="link" href="server-system-variables.html#sysvar_autocommit"> <code class="literal"> autocommit </code> </a> setting is turned on, so that the transaction is guaranteed to be a single statement, and the single statement making up the transaction is a <span class="quote"> “ <span class="quote"> non-locking </span> ” </span> <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> statement. That is, a <code class="literal"> SELECT </code> that does not use a <code class="literal"> FOR UPDATE </code> or <code class="literal"> LOCK IN SHARED MODE </code> clause. </p> </li> <li class="listitem"> <p> The transaction is started without the <code class="literal"> READ ONLY </code> option, but no updates or statements that explicitly lock rows have been executed yet. Until updates or explicit locks are required, a transaction stays in read-only mode. </p> </li> </ul> </div> <p> Thus, for a read-intensive application such as a report generator, you can tune a sequence of <code class="literal"> InnoDB </code> queries by grouping them inside <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements"> <code class="literal"> START TRANSACTION READ ONLY </code> </a> and <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements"> <code class="literal"> COMMIT </code> </a> , or by turning on the <a class="link" href="server-system-variables.html#sysvar_autocommit"> <code class="literal"> autocommit </code> </a> setting before running the <code class="literal"> SELECT </code> statements, or simply by avoiding any data change statements interspersed with the queries. </p> <p> For information about <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements"> <code class="literal"> START TRANSACTION </code> </a> and <a class="link" href="server-system-variables.html#sysvar_autocommit"> <code class="literal"> autocommit </code> </a> , see <a class="xref" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements"> Section 15.3.1, “START TRANSACTION, COMMIT, and ROLLBACK Statements” </a> . </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Transactions that qualify as auto-commit, non-locking, and read-only (AC-NL-RO) are kept out of certain internal <code class="literal"> InnoDB </code> data structures and are therefore not listed in <a class="link" href="show-engine.html" title="15.7.7.16 SHOW ENGINE Statement"> <code class="literal"> SHOW ENGINE INNODB STATUS </code> </a> output. </p> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/information-schema-files-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="information-schema-files-table"> </a> 28.3.15 The INFORMATION_SCHEMA FILES Table </h3> </div> </div> </div> <a class="indexterm" name="idm46045079850704"> </a> <a class="indexterm" name="idm46045079849200"> </a> <p> The <code class="literal"> FILES </code> table provides information about the files in which MySQL tablespace data is stored. </p> <p> The <code class="literal"> FILES </code> table provides information about <code class="literal"> InnoDB </code> data files. In NDB Cluster, this table also provides information about the files in which NDB Cluster Disk Data tables are stored. For additional information specific to <code class="literal"> InnoDB </code> , see <a class="xref" href="information-schema-files-table.html#files-table-innodb-notes" title="InnoDB Notes"> InnoDB Notes </a> , later in this section; for additional information specific to NDB Cluster, see <a class="xref" href="information-schema-files-table.html#files-table-ndb-notes" title="NDB Notes"> NDB Notes </a> . </p> <p> The <code class="literal"> FILES </code> table has these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> FILE_ID </code> </p> <p> For <code class="literal"> InnoDB </code> : The tablespace ID, also referred to as the <code class="literal"> space_id </code> or <code class="literal"> fil_space_t::id </code> . </p> <p> For <code class="literal"> NDB </code> : A file identifier. <code class="literal"> FILE_ID </code> column values are auto-generated. </p> </li> <li class="listitem"> <p> <code class="literal"> FILE_NAME </code> </p> <p> For <code class="literal"> InnoDB </code> : The name of the data file. File-per-table and general tablespaces have an <code class="filename"> .ibd </code> file name extension. Undo tablespaces are prefixed by <code class="literal"> undo </code> . The system tablespace is prefixed by <code class="literal"> ibdata </code> . The global temporary tablespace is prefixed by <code class="literal"> ibtmp </code> . The file name includes the file path, which may be relative to the MySQL data directory (the value of the <a class="link" href="server-system-variables.html#sysvar_datadir"> <code class="literal"> datadir </code> </a> system variable). </p> <p> For <code class="literal"> NDB </code> : The name of an undo log file created by <a class="link" href="create-logfile-group.html" title="15.1.16 CREATE LOGFILE GROUP Statement"> <code class="literal"> CREATE LOGFILE GROUP </code> </a> or <a class="link" href="alter-logfile-group.html" title="15.1.6 ALTER LOGFILE GROUP Statement"> <code class="literal"> ALTER LOGFILE GROUP </code> </a> , or of a data file created by <a class="link" href="create-tablespace.html" title="15.1.21 CREATE TABLESPACE Statement"> <code class="literal"> CREATE TABLESPACE </code> </a> or <a class="link" href="alter-tablespace.html" title="15.1.10 ALTER TABLESPACE Statement"> <code class="literal"> ALTER TABLESPACE </code> </a> . In NDB 8.4, the file name is shown with a relative path; for an undo log file, this path is relative to the directory <code class="filename"> <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datadir"> <code class="literal"> DataDir </code> </a> /ndb_ <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-nodeid"> <code class="literal"> NodeId </code> </a> _fs/LG </code> ; for a data file, it is relative to the directory <code class="filename"> <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datadir"> <code class="literal"> DataDir </code> </a> /ndb_ <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-nodeid"> <code class="literal"> NodeId </code> </a> _fs/TS </code> . This means, for example, that the name of a data file created with <code class="literal"> ALTER TABLESPACE ts ADD DATAFILE 'data_2.dat' INITIAL SIZE 256M </code> is shown as <code class="literal"> ./data_2.dat </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> FILE_TYPE </code> </p> <p> For <code class="literal"> InnoDB </code> : The tablespace file type. There are three possible file types for <code class="literal"> InnoDB </code> files. <code class="literal"> TABLESPACE </code> is the file type for any system, general, or file-per-table tablespace file that holds tables, indexes, or other forms of user data. <code class="literal"> TEMPORARY </code> is the file type for temporary tablespaces. <code class="literal"> UNDO LOG </code> is the file type for undo tablespaces, which hold undo records. </p> <p> For <code class="literal"> NDB </code> : One of the values <code class="literal"> UNDO LOG </code> or <code class="literal"> DATAFILE </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> TABLESPACE_NAME </code> </p> <p> The name of the tablespace with which the file is associated. </p> <p> For <code class="literal"> InnoDB </code> : General tablespace names are as specified when created. File-per-table tablespace names are shown in the following format: <code class="literal"> <em class="replaceable"> <code> schema_name </code> </em> / <em class="replaceable"> <code> table_name </code> </em> </code> . The <code class="literal"> InnoDB </code> system tablespace name is <code class="literal"> innodb_system </code> . The global temporary tablespace name is <code class="literal"> innodb_temporary </code> . Default undo tablespace names are <code class="literal"> innodb_undo_001 </code> and <code class="literal"> innodb_undo_002 </code> . User-created undo tablespace names are as specified when created. </p> </li> <li class="listitem"> <p> <code class="literal"> TABLE_CATALOG </code> </p> <p> This value is always empty. </p> </li> <li class="listitem"> <p> <code class="literal"> TABLE_SCHEMA </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> TABLE_NAME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> LOGFILE_GROUP_NAME </code> </p> <p> For <code class="literal"> InnoDB </code> : This is always <code class="literal"> NULL </code> . </p> <p> For <code class="literal"> NDB </code> : The name of the log file group to which the log file or data file belongs. </p> </li> <li class="listitem"> <p> <code class="literal"> LOGFILE_GROUP_NUMBER </code> </p> <p> For <code class="literal"> InnoDB </code> : This is always <code class="literal"> NULL </code> . </p> <p> For <code class="literal"> NDB </code> : For a Disk Data undo log file, the auto-generated ID number of the log file group to which the log file belongs. This is the same as the value shown for the <code class="literal"> id </code> column in the <a class="link" href="mysql-cluster-ndbinfo-dict-obj-info.html" title="25.6.17.25 The ndbinfo dict_obj_info Table"> <code class="literal"> ndbinfo.dict_obj_info </code> </a> table and the <code class="literal"> log_id </code> column in the <a class="link" href="mysql-cluster-ndbinfo-logspaces.html" title="25.6.17.44 The ndbinfo logspaces Table"> <code class="literal"> ndbinfo.logspaces </code> </a> and <a class="link" href="mysql-cluster-ndbinfo-logspaces.html" title="25.6.17.44 The ndbinfo logspaces Table"> <code class="literal"> ndbinfo.logspaces </code> </a> tables for this undo log file. </p> </li> <li class="listitem"> <p> <code class="literal"> ENGINE </code> </p> <p> For <code class="literal"> InnoDB </code> : This value is always <code class="literal"> InnoDB </code> . </p> <p> For <code class="literal"> NDB </code> : This value is always <code class="literal"> ndbcluster </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> FULLTEXT_KEYS </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> DELETED_ROWS </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> UPDATE_COUNT </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> FREE_EXTENTS </code> </p> <p> For <code class="literal"> InnoDB </code> : The number of fully free extents in the current data file. </p> <p> For <code class="literal"> NDB </code> : The number of extents which have not yet been used by the file. </p> </li> <li class="listitem"> <p> <code class="literal"> TOTAL_EXTENTS </code> </p> <p> For <code class="literal"> InnoDB </code> : The number of full extents used in the current data file. Any partial extent at the end of the file is not counted. </p> <p> For <code class="literal"> NDB </code> : The total number of extents allocated to the file. </p> </li> <li class="listitem"> <p> <code class="literal"> EXTENT_SIZE </code> </p> <p> For <code class="literal"> InnoDB </code> : Extent size is 1048576 (1MB) for files with a 4KB, 8KB, or 16KB page size. Extent size is 2097152 bytes (2MB) for files with a 32KB page size, and 4194304 (4MB) for files with a 64KB page size. <a class="link" href="information-schema-files-table.html" title="28.3.15 The INFORMATION_SCHEMA FILES Table"> <code class="literal"> FILES </code> </a> does not report <code class="literal"> InnoDB </code> page size. Page size is defined by the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> system variable. Extent size information can also be retrieved from the <a class="link" href="information-schema-innodb-tablespaces-table.html" title="28.4.24 The INFORMATION_SCHEMA INNODB_TABLESPACES Table"> <code class="literal"> INNODB_TABLESPACES </code> </a> table where <code class="literal"> FILES.FILE_ID = INNODB_TABLESPACES.SPACE </code> . </p> <p> For <code class="literal"> NDB </code> : The size of an extent for the file in bytes. </p> </li> <li class="listitem"> <p> <code class="literal"> INITIAL_SIZE </code> </p> <p> For <code class="literal"> InnoDB </code> : The initial size of the file in bytes. </p> <p> For <code class="literal"> NDB </code> : The size of the file in bytes. This is the same value that was used in the <code class="literal"> INITIAL_SIZE </code> clause of the <a class="link" href="create-logfile-group.html" title="15.1.16 CREATE LOGFILE GROUP Statement"> <code class="literal"> CREATE LOGFILE GROUP </code> </a> , <a class="link" href="alter-logfile-group.html" title="15.1.6 ALTER LOGFILE GROUP Statement"> <code class="literal"> ALTER LOGFILE GROUP </code> </a> , <a class="link" href="create-tablespace.html" title="15.1.21 CREATE TABLESPACE Statement"> <code class="literal"> CREATE TABLESPACE </code> </a> , or <a class="link" href="alter-tablespace.html" title="15.1.10 ALTER TABLESPACE Statement"> <code class="literal"> ALTER TABLESPACE </code> </a> statement used to create the file. </p> </li> <li class="listitem"> <p> <code class="literal"> MAXIMUM_SIZE </code> </p> <p> For <code class="literal"> InnoDB </code> : The maximum number of bytes permitted in the file. The value is <code class="literal"> NULL </code> for all data files except for predefined system tablespace data files. Maximum system tablespace file size is defined by <a class="link" href="innodb-parameters.html#sysvar_innodb_data_file_path"> <code class="literal"> innodb_data_file_path </code> </a> . Maximum global temporary tablespace file size is defined by <a class="link" href="innodb-parameters.html#sysvar_innodb_temp_data_file_path"> <code class="literal"> innodb_temp_data_file_path </code> </a> . A <code class="literal"> NULL </code> value for a predefined system tablespace data file indicates that a file size limit was not defined explicitly. </p> <p> For <code class="literal"> NDB </code> : This value is always the same as the <code class="literal"> INITIAL_SIZE </code> value. </p> </li> <li class="listitem"> <p> <code class="literal"> AUTOEXTEND_SIZE </code> </p> <p> The auto-extend size of the tablespace. For <code class="literal"> NDB </code> , <code class="literal"> AUTOEXTEND_SIZE </code> is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> CREATION_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> LAST_UPDATE_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> LAST_ACCESS_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> RECOVER_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> TRANSACTION_COUNTER </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> VERSION </code> </p> <p> For <code class="literal"> InnoDB </code> : This is always <code class="literal"> NULL </code> . </p> <p> For <code class="literal"> NDB </code> : The version number of the file. </p> </li> <li class="listitem"> <p> <code class="literal"> ROW_FORMAT </code> </p> <p> For <code class="literal"> InnoDB </code> : This is always <code class="literal"> NULL </code> . </p> <p> For <code class="literal"> NDB </code> : One of <code class="literal"> FIXED </code> or <code class="literal"> DYNAMIC </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> TABLE_ROWS </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> AVG_ROW_LENGTH </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> DATA_LENGTH </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> MAX_DATA_LENGTH </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> INDEX_LENGTH </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> DATA_FREE </code> </p> <p> For <code class="literal"> InnoDB </code> : The total amount of free space (in bytes) for the entire tablespace. Predefined system tablespaces, which include the system tablespace and temporary table tablespaces, may have one or more data files. </p> <p> For <code class="literal"> NDB </code> : This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> CREATE_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> UPDATE_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> CHECK_TIME </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> CHECKSUM </code> </p> <p> This is always <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> STATUS </code> </p> <p> For <code class="literal"> InnoDB </code> : This value is <code class="literal"> NORMAL </code> by default. <code class="literal"> InnoDB </code> file-per-table tablespaces may report <code class="literal"> IMPORTING </code> , which indicates that the tablespace is not yet available. </p> <p> For <code class="literal"> NDB </code> : For NDB Cluster Disk Data files, this value is always <code class="literal"> NORMAL </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> EXTRA </code> </p> <p> For <code class="literal"> InnoDB </code> : This is always <code class="literal"> NULL </code> . </p> <p> For <code class="literal"> NDB </code> : For undo log files, this column shows the undo log buffer size; for data files, it is always <span class="emphasis"> <em> NULL </em> </span> . A more detailed explanation is provided in the next few paragraphs. </p> <p> <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> stores a copy of each data file and each undo log file on each data node in the cluster. The <code class="literal"> FILES </code> table contains one row for each such file. Suppose that you run the following two statements on an NDB Cluster with four data nodes: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59001128"><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">LOGFILE</span> <span class="token keyword">GROUP</span> mygroup <span class="token keyword">ADD</span> <span class="token keyword">UNDOFILE</span> <span class="token string">'new_undo.dat'</span> <span class="token keyword">INITIAL_SIZE</span> 2G <span class="token keyword">ENGINE</span> <span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLESPACE</span> myts <span class="token keyword">ADD</span> <span class="token keyword">DATAFILE</span> <span class="token string">'data_1.dat'</span> <span class="token keyword">USE</span> <span class="token keyword">LOGFILE</span> <span class="token keyword">GROUP</span> mygroup <span class="token keyword">INITIAL_SIZE</span> 256M <span class="token keyword">ENGINE</span> <span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span></code></pre> </div> <p> After running these two statements successfully, you should see a result similar to the one shown here for this query against the <a class="link" href="information-schema-files-table.html" title="28.3.15 The INFORMATION_SCHEMA FILES Table"> <code class="literal"> FILES </code> </a> table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49308716"><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">SELECT</span> LOGFILE_GROUP_NAME<span class="token punctuation">,</span> FILE_TYPE<span class="token punctuation">,</span> EXTRA <span class="token prompt"> -&gt;</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>FILES <span class="token prompt"> -&gt;</span> <span class="token keyword">WHERE</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token string">'ndbcluster'</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 class="token punctuation">-</span><span class="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> LOGFILE_GROUP_NAME <span class="token punctuation">|</span> FILE_TYPE <span class="token punctuation">|</span> EXTRA <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 class="token punctuation">-</span><span class="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> mygroup <span class="token punctuation">|</span> UNDO LOG <span class="token punctuation">|</span> UNDO_BUFFER_SIZE=8388608 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> mygroup <span class="token punctuation">|</span> DATAFILE <span class="token punctuation">|</span> NULL <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 class="token punctuation">-</span><span class="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> </li> </ul> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="files-table-notes"> </a> Notes </h4> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="link" href="information-schema-files-table.html" title="28.3.15 The INFORMATION_SCHEMA FILES Table"> <code class="literal"> FILES </code> </a> is a nonstandard <code class="literal"> INFORMATION_SCHEMA </code> table. </p> </li> <li class="listitem"> <p> You must have the <a class="link" href="privileges-provided.html#priv_process"> <code class="literal"> PROCESS </code> </a> privilege to query this table. </p> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="files-table-innodb-notes"> </a> InnoDB Notes </h4> </div> </div> </div> <p> The following notes apply to <code class="literal"> InnoDB </code> data files. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Information reported by <code class="literal"> FILES </code> is obtained from the <code class="literal"> InnoDB </code> in-memory cache for open files, whereas <a class="link" href="information-schema-innodb-datafiles-table.html" title="28.4.10 The INFORMATION_SCHEMA INNODB_DATAFILES Table"> <code class="literal"> INNODB_DATAFILES </code> </a> gets its data from the <code class="literal"> InnoDB </code> <code class="literal"> SYS_DATAFILES </code> internal data dictionary table. </p> </li> <li class="listitem"> <p> The information provided by <code class="literal"> FILES </code> includes global temporary tablespace information which is not available in the <code class="literal"> InnoDB </code> <code class="literal"> SYS_DATAFILES </code> internal data dictionary table, and is therefore not included in <a class="link" href="information-schema-innodb-datafiles-table.html" title="28.4.10 The INFORMATION_SCHEMA INNODB_DATAFILES Table"> <code class="literal"> INNODB_DATAFILES </code> </a> . </p> </li> <li class="listitem"> <p> Undo tablespace information is shown in <code class="literal"> FILES </code> when separate undo tablespaces are present, as they are by default in MySQL 8.4. </p> </li> <li class="listitem"> <p> The following query returns all <code class="literal"> FILES </code> table information relating to <code class="literal"> InnoDB </code> tablespaces. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41197914"><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> FILE_ID<span class="token punctuation">,</span> FILE_NAME<span class="token punctuation">,</span> FILE_TYPE<span class="token punctuation">,</span> TABLESPACE_NAME<span class="token punctuation">,</span> FREE_EXTENTS<span class="token punctuation">,</span> TOTAL_EXTENTS<span class="token punctuation">,</span> <span class="token keyword">EXTENT_SIZE</span><span class="token punctuation">,</span> <span class="token keyword">INITIAL_SIZE</span><span class="token punctuation">,</span> MAXIMUM_SIZE<span class="token punctuation">,</span> <span class="token keyword">AUTOEXTEND_SIZE</span><span class="token punctuation">,</span> DATA_FREE<span class="token punctuation">,</span> <span class="token keyword">STATUS</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>FILES <span class="token keyword">WHERE</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token string">'InnoDB'</span>\G</code></pre> </div> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h4 class="title"> <a name="files-table-ndb-notes"> </a> NDB Notes </h4> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> The <code class="literal"> FILES </code> table provides information about Disk Data <span class="emphasis"> <em> files </em> </span> only; you cannot use it for determining disk space allocation or availability for individual <code class="literal"> NDB </code> tables. However, it is possible to see how much space is allocated for each <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> table having data stored on disk—as well as how much remains available for storage of data on disk for that table—using <a class="link" href="mysql-cluster-programs-ndb-desc.html" title="25.5.9 ndb_desc — Describe NDB Tables"> <span class="command"> <strong> ndb_desc </strong> </span> </a> . </p> </li> <li class="listitem"> <p> Much of the information contained in the <code class="literal"> FILES </code> table can also be found in the <code class="literal"> ndbinfo </code> <a class="link" href="mysql-cluster-ndbinfo-files.html" title="25.6.17.36 The ndbinfo files Table"> <code class="literal"> files </code> </a> table. </p> </li> <li class="listitem"> <p> The <code class="literal"> CREATION_TIME </code> , <code class="literal"> LAST_UPDATE_TIME </code> , and <code class="literal"> LAST_ACCESSED </code> values are as reported by the operating system, and are not supplied by the <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> storage engine. Where no value is provided by the operating system, these columns display <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> The difference between the <code class="literal"> TOTAL EXTENTS </code> and <code class="literal"> FREE_EXTENTS </code> columns is the number of extents currently in use by the file: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70174357"><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> TOTAL_EXTENTS <span class="token operator">-</span> FREE_EXTENTS <span class="token keyword">AS</span> extents_used <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>FILES <span class="token keyword">WHERE</span> FILE_NAME <span class="token operator">=</span> <span class="token string">'./myfile.dat'</span><span class="token punctuation">;</span></code></pre> </div> <p> To approximate the amount of disk space in use by the file, multiply that difference by the value of the <code class="literal"> EXTENT_SIZE </code> column, which gives the size of an extent for the file in bytes: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa80249705"><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> <span class="token punctuation">(</span>TOTAL_EXTENTS <span class="token operator">-</span> FREE_EXTENTS<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token keyword">EXTENT_SIZE</span> <span class="token keyword">AS</span> bytes_used <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>FILES <span class="token keyword">WHERE</span> FILE_NAME <span class="token operator">=</span> <span class="token string">'./myfile.dat'</span><span class="token punctuation">;</span></code></pre> </div> <p> Similarly, you can estimate the amount of space that remains available in a given file by multiplying <code class="literal"> FREE_EXTENTS </code> by <code class="literal"> EXTENT_SIZE </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa6661385"><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> FREE_EXTENTS <span class="token operator">*</span> <span class="token keyword">EXTENT_SIZE</span> <span class="token keyword">AS</span> bytes_free <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>FILES <span class="token keyword">WHERE</span> FILE_NAME <span class="token operator">=</span> <span class="token string">'./myfile.dat'</span><span class="token punctuation">;</span></code></pre> </div> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> The byte values produced by the preceding queries are approximations only, and their precision is inversely proportional to the value of <code class="literal"> EXTENT_SIZE </code> . That is, the larger <code class="literal"> EXTENT_SIZE </code> becomes, the less accurate the approximations are. </p> </div> <p> It is also important to remember that once an extent is used, it cannot be freed again without dropping the data file of which it is a part. This means that deletes from a Disk Data table do <span class="emphasis"> <em> not </em> </span> release disk space. </p> <p> The extent size can be set in a <a class="link" href="create-tablespace.html" title="15.1.21 CREATE TABLESPACE Statement"> <code class="literal"> CREATE TABLESPACE </code> </a> statement. For more information, see <a class="xref" href="create-tablespace.html" title="15.1.21 CREATE TABLESPACE Statement"> Section 15.1.21, “CREATE TABLESPACE Statement” </a> . </p> </li> <li class="listitem"> <p> You can obtain information about Disk Data tablespaces using the <a class="link" href="mysql-cluster-programs-ndb-desc.html" title="25.5.9 ndb_desc — Describe NDB Tables"> <span class="command"> <strong> ndb_desc </strong> </span> </a> utility. For more information, see <a class="xref" href="mysql-cluster-disk-data-objects.html" title="25.6.11.1 NDB Cluster Disk Data Objects"> Section 25.6.11.1, “NDB Cluster Disk Data Objects” </a> , as well as the description of <a class="link" href="mysql-cluster-programs-ndb-desc.html" title="25.5.9 ndb_desc — Describe NDB Tables"> <span class="command"> <strong> ndb_desc </strong> </span> </a> . </p> </li> <li class="listitem"> <p> For additional information, and examples of creating, dropping, and obtaining information about NDB Cluster Disk Data objects, see <a class="xref" href="mysql-cluster-disk-data.html" title="25.6.11 NDB Cluster Disk Data Tables"> Section 25.6.11, “NDB Cluster Disk Data Tables” </a> . </p> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/set-names.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="set-names"> </a> 15.7.6.3 SET NAMES Statement </h4> </div> </div> </div> <a class="indexterm" name="idm46045171340096"> </a> <a class="indexterm" name="idm46045171339024"> </a> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44621320"><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">NAMES</span> {<span class="token string">'<em class="replaceable">charset_name</em>'</span> <span class="token punctuation">[</span><span class="token keyword">COLLATE</span> <span class="token string">'<em class="replaceable">collation_name</em>'</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">DEFAULT</span>}</code></pre> </div> <p> This statement sets the three session system variables <a class="link" href="server-system-variables.html#sysvar_character_set_client"> <code class="literal"> character_set_client </code> </a> , <a class="link" href="server-system-variables.html#sysvar_character_set_connection"> <code class="literal"> character_set_connection </code> </a> , and <a class="link" href="server-system-variables.html#sysvar_character_set_results"> <code class="literal"> character_set_results </code> </a> to the given character set. Setting <a class="link" href="server-system-variables.html#sysvar_character_set_connection"> <code class="literal"> character_set_connection </code> </a> to <code class="literal"> charset_name </code> also sets <a class="link" href="server-system-variables.html#sysvar_collation_connection"> <code class="literal"> collation_connection </code> </a> to the default collation for <code class="literal"> charset_name </code> . See <a class="xref" href="charset-connection.html" title="12.4 Connection Character Sets and Collations"> Section 12.4, “Connection Character Sets and Collations” </a> . </p> <p> The optional <code class="literal"> COLLATE </code> clause may be used to specify a collation explicitly. If given, the collation must one of the permitted collations for <em class="replaceable"> <code> charset_name </code> </em> . </p> <p> <em class="replaceable"> <code> charset_name </code> </em> and <em class="replaceable"> <code> collation_name </code> </em> may be quoted or unquoted. </p> <p> The default mapping can be restored by using a value of <code class="literal"> DEFAULT </code> . The default depends on the server configuration. </p> <p> Some character sets cannot be used as the client character set. Attempting to use them with <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement"> <code class="literal"> SET NAMES </code> </a> produces an error. See <a class="xref" href="charset-connection.html#charset-connection-impermissible-client-charset" title="Impermissible Client Character Sets"> Impermissible Client Character Sets </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/clone-plugin-failure-handling.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="clone-plugin-failure-handling"> </a> 7.6.7.9 Remote Cloning Operation Failure Handling </h4> </div> </div> </div> <a class="indexterm" name="idm46045255340368"> </a> <p> This section describes failure handing at different stages of a cloning operation. </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> Prerequisites are checked (see <a class="xref" href="clone-plugin-remote.html#clone-remote-prerequisites" title="Remote Cloning Prerequisites"> Remote Cloning Prerequisites </a> ). </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If a failure occurs during the prerequisite check, the <a class="link" href="clone.html" title="15.7.5 CLONE Statement"> <code class="literal"> CLONE INSTANCE </code> </a> operation reports an error. </p> </li> </ul> </div> </li> <li class="listitem"> <p> Concurrent DDL on the donor is blocked only if the <a class="link" href="clone-plugin-options-variables.html#sysvar_clone_block_ddl"> <code class="literal"> clone_block_ddl </code> </a> variable is set to <code class="literal"> ON </code> (the default setting is <code class="literal"> OFF </code> ). See <a class="xref" href="clone-plugin-concurrent-ddl.html" title="7.6.7.4 Cloning and Concurrent DDL"> Section 7.6.7.4, “Cloning and Concurrent DDL” </a> . </p> <p> If the cloning operation is unable to obtain a DDL lock within the time limit specified by the <a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ddl_timeout"> <code class="literal"> clone_ddl_timeout </code> </a> variable, an error is reported. </p> </li> <li class="listitem"> <p> User-created data (schemas, tables, tablespaces) and binary logs on the recipient are removed before data is cloned to the recipient data directory. </p> <p> When user-created data and binary logs are removed from the recipient data directory during a remote cloning operation, the data is not saved and may be lost if a failure occurs. If the data is of importance, a backup should be taken before initiating a remote cloning operation. </p> <p> For informational purposes, warnings are printed to the server error log to specify when data removal starts and finishes: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa56265458"><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 punctuation">[</span>Warning<span class="token punctuation">]</span> <span class="token punctuation">[</span>MY-013453<span class="token punctuation">]</span> <span class="token punctuation">[</span>InnoDB<span class="token punctuation">]</span> Clone removing all user data for provisioning<span class="token punctuation">:</span> Started<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">[</span>Warning<span class="token punctuation">]</span> <span class="token punctuation">[</span>MY-013453<span class="token punctuation">]</span> <span class="token punctuation">[</span>InnoDB<span class="token punctuation">]</span> Clone removing all user data for provisioning<span class="token punctuation">:</span> Finished</code></pre> </div> <p> If a failure occurs while removing data, the recipient may be left with a partial set of schemas, tables, and tablespaces that existed before the cloning operation. Any time during the execution of a cloning operation or after a failure, the server is always in a consistent state. </p> </li> <li class="listitem"> <p> Data is cloned from the donor. User-created data, dictionary metadata, and other system data are cloned. </p> <p> If a failure occurs while cloning data, the cloning operation is rolled back and all cloned data removed. At this stage, the previously existing user-created data and binary logs on the recipient have also been removed. </p> <p> Should this scenario occur, you can either rectify the cause of the failure and re-execute the cloning operation, or forgo the cloning operation and restore the recipient data from a backup taken before the cloning operation. </p> </li> <li class="listitem"> <p> The server is restarted automatically (applies to remote cloning operations that do not clone to a named directory). During startup, typical server startup tasks are performed. </p> <p> If the automatic server restart fails, you can restart the server manually to complete the cloning operation. </p> </li> </ol> </div> <p> If a network error occurs during a cloning operation, the operation resumes if the error is resolved within the time specified by the <a class="link" href="clone-plugin-options-variables.html#sysvar_clone_donor_timeout_after_network_failure"> <code class="literal"> clone_donor_timeout_after_network_failure </code> </a> variable defined on the donor instance. The <a class="link" href="clone-plugin-options-variables.html#sysvar_clone_donor_timeout_after_network_failure"> <code class="literal"> clone_donor_timeout_after_network_failure </code> </a> default setting is 5 minutes but a range of 0 to 30 minutes is supported. If the operation does not resume within the allotted time, it aborts and returns an error, and the donor drops the snapshot. A setting of zero causes the donor to drop the snapshot immediately when a network error occurs. Configuring a longer timeout allows more time for resolving network issues but also increases the size of the delta on the donor instance, which increases clone recovery time as well as replication lag in cases where the clone is intended as a replica or replication group member. </p> <p> The Clone idle timeout is set to the default <a class="link" href="server-system-variables.html#sysvar_wait_timeout"> <code class="literal"> wait_timeout </code> </a> setting, which is 28800 seconds (8 hours). </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/outer-join-simplification.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="outer-join-simplification"> </a> 10.2.1.10 Outer Join Simplification </h4> </div> </div> </div> <p> Table expressions in the <code class="literal"> FROM </code> clause of a query are simplified in many cases. </p> <p> At the parser stage, queries with right outer join operations are converted to equivalent queries containing only left join operations. In the general case, the conversion is performed such that this right join: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa71497724"><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 punctuation">(</span>T1<span class="token punctuation">,</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">RIGHT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T2<span class="token punctuation">,</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">ON</span> P<span class="token punctuation">(</span>T1<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">,</span> T2<span class="token punctuation">,</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> Becomes this equivalent left join: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa75153091"><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 punctuation">(</span>T2<span class="token punctuation">,</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">LEFT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T1<span class="token punctuation">,</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">ON</span> P<span class="token punctuation">(</span>T1<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">,</span> T2<span class="token punctuation">,</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> All inner join expressions of the form <code class="literal"> T1 INNER JOIN T2 ON P(T1,T2) </code> are replaced by the list <code class="literal"> T1,T2 </code> , <code class="literal"> P(T1,T2) </code> being joined as a conjunct to the <code class="literal"> WHERE </code> condition (or to the join condition of the embedding join, if there is any). </p> <p> When the optimizer evaluates plans for outer join operations, it takes into consideration only plans where, for each such operation, the outer tables are accessed before the inner tables. The optimizer choices are limited because only such plans enable outer joins to be executed using the nested-loop algorithm. </p> <p> Consider a query of this form, where <code class="literal"> R(T2) </code> greatly narrows the number of matching rows from table <code class="literal"> T2 </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69088826"><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> <span class="token operator">*</span> T1 <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> P1<span class="token punctuation">(</span>T1<span class="token punctuation">,</span>T2<span class="token punctuation">)</span> <span class="token keyword">WHERE</span> P<span class="token punctuation">(</span>T1<span class="token punctuation">,</span>T2<span class="token punctuation">)</span> <span class="token operator">AND</span> R<span class="token punctuation">(</span>T2<span class="token punctuation">)</span></code></pre> </div> <p> If the query is executed as written, the optimizer has no choice but to access the less-restricted table <code class="literal"> T1 </code> before the more-restricted table <code class="literal"> T2 </code> , which may produce a very inefficient execution plan. </p> <p> Instead, MySQL converts the query to a query with no outer join operation if the <code class="literal"> WHERE </code> condition is null-rejected. (That is, it converts the outer join to an inner join.) A condition is said to be null-rejected for an outer join operation if it evaluates to <code class="literal"> FALSE </code> or <code class="literal"> UNKNOWN </code> for any <code class="literal"> NULL </code> -complemented row generated for the operation. </p> <a class="indexterm" name="idm46045229367968"> </a> <a class="indexterm" name="idm46045229366896"> </a> <p> Thus, for this outer join: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa40717270"><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">T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T1<span class="token punctuation">.</span>A<span class="token operator">=</span>T2<span class="token punctuation">.</span>A</code></pre> </div> <p> Conditions such as these are null-rejected because they cannot be true for any <code class="literal"> NULL </code> -complemented row (with <code class="literal"> T2 </code> columns set to <code class="literal"> NULL </code> ): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa20929956"><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">T2<span class="token punctuation">.</span>B <span class="token operator">IS</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> T2<span class="token punctuation">.</span>B <span class="token operator">&gt;</span> <span class="token number">3</span> T2<span class="token punctuation">.</span>C <span class="token operator">&lt;=</span> T1<span class="token punctuation">.</span>C T2<span class="token punctuation">.</span>B <span class="token operator">&lt;</span> <span class="token number">2</span> <span class="token operator">OR</span> T2<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">1</span></code></pre> </div> <p> Conditions such as these are not null-rejected because they might be true for a <code class="literal"> NULL </code> -complemented row: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14993757"><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">T2<span class="token punctuation">.</span>B <span class="token operator">IS</span> <span class="token boolean">NULL</span> T1<span class="token punctuation">.</span>B <span class="token operator">&lt;</span> <span class="token number">3</span> <span class="token operator">OR</span> T2<span class="token punctuation">.</span>B <span class="token operator">IS</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> T1<span class="token punctuation">.</span>B <span class="token operator">&lt;</span> <span class="token number">3</span> <span class="token operator">OR</span> T2<span class="token punctuation">.</span>B <span class="token operator">&gt;</span> <span class="token number">3</span></code></pre> </div> <p> The general rules for checking whether a condition is null-rejected for an outer join operation are simple: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> It is of the form <code class="literal"> A IS NOT NULL </code> , where <code class="literal"> A </code> is an attribute of any of the inner tables </p> </li> <li class="listitem"> <p> It is a predicate containing a reference to an inner table that evaluates to <code class="literal"> UNKNOWN </code> when one of its arguments is <code class="literal"> NULL </code> </p> </li> <li class="listitem"> <p> It is a conjunction containing a null-rejected condition as a conjunct </p> </li> <li class="listitem"> <p> It is a disjunction of null-rejected conditions </p> </li> </ul> </div> <p> A condition can be null-rejected for one outer join operation in a query and not null-rejected for another. In this query, the <code class="literal"> WHERE </code> condition is null-rejected for the second outer join operation but is not null-rejected for the first one: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51634784"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T1<span class="token punctuation">.</span>B <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> If the <code class="literal"> WHERE </code> condition is null-rejected for an outer join operation in a query, the outer join operation is replaced by an inner join operation. </p> <p> For example, in the preceding query, the second outer join is null-rejected and can be replaced by an inner join: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa82962972"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T1<span class="token punctuation">.</span>B <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> For the original query, the optimizer evaluates only plans compatible with the single table-access order <code class="literal"> T1,T2,T3 </code> . For the rewritten query, it additionally considers the access order <code class="literal"> T3,T1,T2 </code> . </p> <p> A conversion of one outer join operation may trigger a conversion of another. Thus, the query: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59083841"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> Is first converted to the query: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17936104"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> Which is equivalent to the query: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60836723"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span>T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A<span class="token punctuation">)</span><span class="token punctuation">,</span> T3 <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">AND</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B</code></pre> </div> <p> The remaining outer join operation can also be replaced by an inner join because the condition <code class="literal"> T3.B=T2.B </code> is null-rejected. This results in a query with no outer joins at all: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25027061"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span>T1 <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> T2 <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A<span class="token punctuation">)</span><span class="token punctuation">,</span> T3 <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">AND</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B</code></pre> </div> <p> Sometimes the optimizer succeeds in replacing an embedded outer join operation, but cannot convert the embedding outer join. The following query: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa37119848"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T2 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B<span class="token punctuation">)</span> <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> Is converted to: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa78604685"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T2 <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B<span class="token punctuation">)</span> <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> That can be rewritten only to the form still containing the embedding outer join operation: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46473180"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T2<span class="token punctuation">,</span>T3<span class="token punctuation">)</span> <span class="token keyword">ON</span> <span class="token punctuation">(</span>T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token operator">AND</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B<span class="token punctuation">)</span> <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>C <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> Any attempt to convert an embedded outer join operation in a query must take into account the join condition for the embedding outer join together with the <code class="literal"> WHERE </code> condition. In this query, the <code class="literal"> WHERE </code> condition is not null-rejected for the embedded outer join, but the join condition of the embedding outer join <code class="literal"> T2.A=T1.A AND T3.C=T1.C </code> is null-rejected: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51078108"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T2 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> T3 <span class="token keyword">ON</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B<span class="token punctuation">)</span> <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token operator">AND</span> T3<span class="token punctuation">.</span>C<span class="token operator">=</span>T1<span class="token punctuation">.</span>C <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>D <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">OR</span> T1<span class="token punctuation">.</span>D <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> <p> Consequently, the query can be converted to: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88925804"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> T1 <span class="token keyword">LEFT</span> <span class="token keyword">JOIN</span> <span class="token punctuation">(</span>T2<span class="token punctuation">,</span> T3<span class="token punctuation">)</span> <span class="token keyword">ON</span> T2<span class="token punctuation">.</span>A<span class="token operator">=</span>T1<span class="token punctuation">.</span>A <span class="token operator">AND</span> T3<span class="token punctuation">.</span>C<span class="token operator">=</span>T1<span class="token punctuation">.</span>C <span class="token operator">AND</span> T3<span class="token punctuation">.</span>B<span class="token operator">=</span>T2<span class="token punctuation">.</span>B <span class="token keyword">WHERE</span> T3<span class="token punctuation">.</span>D <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">OR</span> T1<span class="token punctuation">.</span>D <span class="token operator">&gt;</span> <span class="token number">0</span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-ndbinfo-cpustat-1sec.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="mysql-cluster-ndbinfo-cpustat-1sec"> </a> 25.6.17.21 The ndbinfo cpustat_1sec Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045089881600"> </a> <p> The <code class="literal"> cpustat-1sec </code> table provides raw, per-thread CPU data obtained each second for each thread running in the <code class="literal"> NDB </code> kernel. </p> <p> Like <a class="link" href="mysql-cluster-ndbinfo-cpustat-50ms.html" title="25.6.17.20 The ndbinfo cpustat_50ms Table"> <code class="literal"> cpustat_50ms </code> </a> and <a class="link" href="mysql-cluster-ndbinfo-cpustat-20sec.html" title="25.6.17.22 The ndbinfo cpustat_20sec Table"> <code class="literal"> cpustat_20sec </code> </a> , this table shows 20 measurement sets per thread, each referencing a period of the named duration. Thus, <code class="literal"> cpsustat_1sec </code> provides 20 seconds of history. </p> <p> The <code class="literal"> cpustat_1sec </code> table contains the following columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> node_id </code> </p> <p> ID of the node where the thread is running </p> </li> <li class="listitem"> <p> <code class="literal"> thr_no </code> </p> <p> Thread ID (specific to this node) </p> </li> <li class="listitem"> <p> <code class="literal"> OS_user_time </code> </p> <p> OS user time </p> </li> <li class="listitem"> <p> <code class="literal"> OS_system_time </code> </p> <p> OS system time </p> </li> <li class="listitem"> <p> <code class="literal"> OS_idle_time </code> </p> <p> OS idle time </p> </li> <li class="listitem"> <p> <code class="literal"> exec_time </code> </p> <p> Thread execution time </p> </li> <li class="listitem"> <p> <code class="literal"> sleep_time </code> </p> <p> Thread sleep time </p> </li> <li class="listitem"> <p> <code class="literal"> spin_time </code> </p> <p> Thread spin time </p> </li> <li class="listitem"> <p> <code class="literal"> send_time </code> </p> <p> Thread send time </p> </li> <li class="listitem"> <p> <code class="literal"> buffer_full_time </code> </p> <p> Thread buffer full time </p> </li> <li class="listitem"> <p> <code class="literal"> elapsed_time </code> </p> <p> Elapsed time </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/replication-multi-source-provision-replica.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="replication-multi-source-provision-replica"> </a> 19.1.5.2 Provisioning a Multi-Source Replica for GTID-Based Replication </h4> </div> </div> </div> <a class="indexterm" name="idm46045145289248"> </a> <p> If the sources in the multi-source replication topology have existing data, it can save time to provision the replica with the relevant data before starting replication. In a multi-source replication topology, cloning or copying of the data directory cannot be used to provision the replica with data from all of the sources, and you might also want to replicate only specific databases from each source. The best strategy for provisioning such a replica is therefore to use <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> to create an appropriate dump file on each source, then 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 to import the dump file on the replica. </p> <p> If you are using GTID-based replication, you need to pay attention to the <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement that <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> places in the dump output. This statement transfers the GTIDs for the transactions executed on the source to the replica, and the replica requires this information. However, for any case more complex than provisioning one new, empty replica from one source, you need to check what effect the statement has in the version of MySQL used by the replica, and handle the statement accordingly. The following guidance summarizes suitable actions, but for more details, see the <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> documentation. </p> <p> <code class="literal"> SET @@GLOBAL.gtid_purged </code> adds the GTID set from the dump file to the existing <a class="link" href="replication-options-gtids.html#sysvar_gtid_purged"> <code class="literal"> gtid_purged </code> </a> set on the replica. The statement can therefore potentially be left in the dump output when you replay the dump files on the replica, and the dump files can be replayed at different times. However, it is important to note that the value that is included by <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> for the <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement includes the GTIDs of all transactions in the <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed"> <code class="literal"> gtid_executed </code> </a> set on the source, even those that changed suppressed parts of the database, or other databases on the server that were not included in a partial dump. If you replay a second or subsequent dump file on the replica that contains any of the same GTIDs (for example, another partial dump from the same source, or a dump from another source that has overlapping transactions), any <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement in the second dump file fails, and must therefore be removed from the dump output. </p> <p> As an alternative to removing the <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement, you caninoke <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> with <a class="link" href="mysqldump.html#option_mysqldump_set-gtid-purged"> <code class="option"> --set-gtid-purged=COMMENTED </code> </a> to include the statement encased in SQL comments, so that it is not performed when you load the dump file. If you are provisioning the replica with two partial dumps from the same source, and the GTID set in the second dump is the same as the first (so no new transactions have been executed on the source in between the dumps), you can set <code class="option"> --set-gtid-purged=OFF </code> instead when you export the second dump file, to omit the statement. </p> <p> In the following provisioning example, we assume that the <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement cannot be left in the dump output, and must be removed from the files and handled manually. We also assume that there are no wanted transactions with GTIDs on the replica before provisioning starts. </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> To create dump files for a database named <code class="literal"> db1 </code> on <code class="literal"> source1 </code> and a database named <code class="literal"> db2 </code> on <code class="literal"> source2 </code> , run <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> for <code class="literal"> source1 </code> as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa63011546"><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">mysqldump <span class="token property">-u&lt;<em class="replaceable">user</em>&gt;</span> <span class="token property">-p&lt;<em class="replaceable">password</em>&gt;</span> <span class="token property">--single-transaction</span> <span class="token property">--triggers</span> <span class="token property">--routines</span> <span class="token constant">--set-gtid-purged</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span> <span class="token property">--databases</span> db1 &gt; dumpM1<span class="token punctuation">.</span>sql</code></pre> </div> <p> Then run <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> for <code class="literal"> source2 </code> as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa39049457"><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">mysqldump <span class="token property">-u&lt;<em class="replaceable">user</em>&gt;</span> <span class="token property">-p&lt;<em class="replaceable">password</em>&gt;</span> <span class="token property">--single-transaction</span> <span class="token property">--triggers</span> <span class="token property">--routines</span> <span class="token constant">--set-gtid-purged</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span> <span class="token property">--databases</span> db2 &gt; dumpM2<span class="token punctuation">.</span>sql</code></pre> </div> </li> <li class="listitem"> <p> Record the <a class="link" href="replication-options-gtids.html#sysvar_gtid_purged"> <code class="literal"> gtid_purged </code> </a> value that <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program"> <span class="command"> <strong> mysqldump </strong> </span> </a> added to each of the dump files. You can extract the value like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa32814308"><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-none">cat dumpM1.sql | grep GTID_PURGED | perl -p0 -e 's#/\*.*?\*/##sg' | cut -f2 -d'=' | cut -f2 -d$'\'' cat dumpM2.sql | grep GTID_PURGED | perl -p0 -e 's#/\*.*?\*/##sg' | cut -f2 -d'=' | cut -f2 -d$'\''</code></pre> </div> <p> The result in each case should be a GTID set, for example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa24941290"><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-none">source1: 2174B383-5441-11E8-B90A-C80AA9429562:1-1029 source2: 224DA167-0C0C-11E8-8442-00059A3C7B00:1-2695</code></pre> </div> </li> <li class="listitem"> <p> Remove the line from each dump file that contains the <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa37740470"><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-simple">sed '<span class="token operator">/</span>GTID_PURGED<span class="token operator">/</span>d' dumpM1<span class="token punctuation">.</span>sql <span class="token operator">&gt;</span> dumpM1_nopurge<span class="token punctuation">.</span>sql sed '<span class="token operator">/</span>GTID_PURGED<span class="token operator">/</span>d' dumpM2<span class="token punctuation">.</span>sql <span class="token operator">&gt;</span> dumpM2_nopurge<span class="token punctuation">.</span>sql</code></pre> </div> </li> <li class="listitem"> <p> 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 to import each edited dump file into the replica. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa26763012"><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-simple">mysql <span class="token operator">-</span>u<span class="token operator">&lt;</span><em class="replaceable">user</em><span class="token operator">&gt;</span> <span class="token operator">-</span>p<span class="token operator">&lt;</span><em class="replaceable">password</em><span class="token operator">&gt;</span> <span class="token operator">&lt;</span> dumpM1_nopurge<span class="token punctuation">.</span>sql mysql <span class="token operator">-</span>u<span class="token operator">&lt;</span><em class="replaceable">user</em><span class="token operator">&gt;</span> <span class="token operator">-</span>p<span class="token operator">&lt;</span><em class="replaceable">password</em><span class="token operator">&gt;</span> <span class="token operator">&lt;</span> dumpM2_nopurge<span class="token punctuation">.</span>sql</code></pre> </div> </li> <li class="listitem"> <p> On the replica, issue <a class="link" href="reset-binary-logs-and-gtids.html" title="15.4.1.2 RESET BINARY LOGS AND GTIDS Statement"> <code class="literal"> RESET BINARY LOGS AND GTIDS </code> </a> to clear the GTID execution history (assuming, as explained above, that all the dump files have been imported and that there are no wanted transactions with GTIDs on the replica). Then issue a <code class="literal"> SET @@GLOBAL.gtid_purged </code> statement to set the <a class="link" href="replication-options-gtids.html#sysvar_gtid_purged"> <code class="literal"> gtid_purged </code> </a> value to the union of all the GTID sets from all the dump files, as you recorded in Step 2. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa95261942"><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">RESET</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token operator">AND</span> GTIDS<span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@@GLOBAL.gtid_purged</span> <span class="token operator">=</span> <span class="token string">"2174B383-5441-11E8-B90A-C80AA9429562:1-1029, 224DA167-0C0C-11E8-8442-00059A3C7B00:1-2695"</span><span class="token punctuation">;</span></code></pre> </div> <p> If there are, or might be, overlapping transactions between the GTID sets in the dump files, you can use the stored functions described in <a class="xref" href="replication-gtids-functions.html" title="19.1.3.8 Stored Function Examples to Manipulate GTIDs"> Section 19.1.3.8, “Stored Function Examples to Manipulate GTIDs” </a> to check this beforehand and to calculate the union of all the GTID sets. </p> </li> </ol> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/gis-class-curve.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="gis-class-curve"> </a> 13.4.2.4 Curve Class </h4> </div> </div> </div> <p> A <code class="literal"> Curve </code> is a one-dimensional geometry, usually represented by a sequence of points. Particular subclasses of <code class="literal"> Curve </code> define the type of interpolation between points. <code class="literal"> Curve </code> is a noninstantiable class. </p> <p> <span class="bold"> <strong> <code class="literal"> Curve </code> Properties </strong> </span> </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A <code class="literal"> Curve </code> has the coordinates of its points. </p> </li> <li class="listitem"> <p> A <code class="literal"> Curve </code> is defined as a one-dimensional geometry. </p> </li> <li class="listitem"> <p> A <code class="literal"> Curve </code> is simple if it does not pass through the same point twice, with the exception that a curve can still be simple if the start and end points are the same. </p> </li> <li class="listitem"> <p> A <code class="literal"> Curve </code> is closed if its start point is equal to its endpoint. </p> </li> <li class="listitem"> <p> The boundary of a closed <code class="literal"> Curve </code> is empty. </p> </li> <li class="listitem"> <p> The boundary of a nonclosed <code class="literal"> Curve </code> consists of its two endpoints. </p> </li> <li class="listitem"> <p> A <code class="literal"> Curve </code> that is simple and closed is a <code class="literal"> LinearRing </code> . </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/information-schema-innodb-virtual-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="information-schema-innodb-virtual-table"> </a> 28.4.29 The INFORMATION_SCHEMA INNODB_VIRTUAL Table </h3> </div> </div> </div> <a class="indexterm" name="idm46045076146128"> </a> <p> The <a class="link" href="information-schema-innodb-virtual-table.html" title="28.4.29 The INFORMATION_SCHEMA INNODB_VIRTUAL Table"> <code class="literal"> INNODB_VIRTUAL </code> </a> table provides metadata about <code class="literal"> InnoDB </code> <a class="link" href="glossary.html#glos_virtual_generated_column" title="virtual generated column"> virtual generated columns </a> and columns upon which virtual generated columns are based. </p> <p> A row appears in the <a class="link" href="information-schema-innodb-virtual-table.html" title="28.4.29 The INFORMATION_SCHEMA INNODB_VIRTUAL Table"> <code class="literal"> INNODB_VIRTUAL </code> </a> table for each column upon which a virtual generated column is based. </p> <p> The <a class="link" href="information-schema-innodb-virtual-table.html" title="28.4.29 The INFORMATION_SCHEMA INNODB_VIRTUAL Table"> <code class="literal"> INNODB_VIRTUAL </code> </a> table has these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> TABLE_ID </code> </p> <p> An identifier representing the table associated with the virtual column; the same value as <code class="literal"> INNODB_TABLES.TABLE_ID </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> POS </code> </p> <p> The position value of the <a class="link" href="glossary.html#glos_virtual_generated_column" title="virtual generated column"> virtual generated column </a> . The value is large because it encodes the column sequence number and ordinal position. The formula used to calculate the value uses a bitwise operation: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa9600309"><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-simple"><span class="token punctuation">(</span><span class="token punctuation">(</span><em class="replaceable">n</em>th virtual generated column for the InnoDB instance <span class="token operator">+</span> 1<span class="token punctuation">)</span> <span class="token operator">&lt;&lt;</span> 16<span class="token punctuation">)</span> <span class="token operator">+</span> the ordinal position of the virtual generated column</code></pre> </div> <p> For example, if the first virtual generated column in the <code class="literal"> InnoDB </code> instance is the third column of the table, the formula is <code class="literal"> (0 + 1) &lt;&lt; 16) + 2 </code> . The first virtual generated column in the <code class="literal"> InnoDB </code> instance is always number 0. As the third column in the table, the ordinal position of the virtual generated column is 2. Ordinal positions are counted from 0. </p> </li> <li class="listitem"> <p> <code class="literal"> BASE_POS </code> </p> <p> The ordinal position of the columns upon which a virtual generated column is based. </p> </li> </ul> </div> <h4> <a name="idm46045076125248"> </a> Example </h4> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43141537"><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">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>t1<span class="token punctuation">`</span> <span class="token punctuation">(</span> <span class="token punctuation">`</span>a<span class="token punctuation">`</span> <span class="token datatype">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>b<span class="token punctuation">`</span> <span class="token datatype">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>c<span class="token punctuation">`</span> <span class="token datatype">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">GENERATED</span> <span class="token keyword">ALWAYS</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span>a<span class="token operator">+</span>b<span class="token punctuation">)</span> <span class="token keyword">VIRTUAL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>h<span class="token punctuation">`</span> <span class="token datatype">varchar</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>InnoDB <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4<span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>INNODB_VIRTUAL <span class="token keyword">WHERE</span> TABLE_ID <span class="token keyword">IN</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> TABLE_ID <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>INNODB_TABLES <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">"test/t1"</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> TABLE_ID <span class="token punctuation">|</span> POS <span class="token punctuation">|</span> BASE_POS <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> <span class="token output"><span class="token punctuation">|</span> 98 <span class="token punctuation">|</span> 65538 <span class="token punctuation">|</span> 0 <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 98 <span class="token punctuation">|</span> 65538 <span class="token punctuation">|</span> 1 <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></code></pre> </div> <h4> <a name="idm46045076116320"> </a> Notes </h4> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If a constant value is assigned to a <a class="link" href="glossary.html#glos_virtual_generated_column" title="virtual generated column"> virtual generated column </a> , as in the following table, an entry for the column does not appear in the <code class="literal"> INNODB_VIRTUAL </code> table. For an entry to appear, a virtual generated column must have a base column. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa26535097"><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">TABLE</span> <span class="token punctuation">`</span>t1<span class="token punctuation">`</span> <span class="token punctuation">(</span> <span class="token punctuation">`</span>a<span class="token punctuation">`</span> <span class="token datatype">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>b<span class="token punctuation">`</span> <span class="token datatype">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>c<span class="token punctuation">`</span> <span class="token datatype">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">GENERATED</span> <span class="token keyword">ALWAYS</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token keyword">VIRTUAL</span> <span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>InnoDB <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4<span class="token punctuation">;</span></code></pre> </div> <p> However, metadata for such a column does appear in the <a class="link" href="information-schema-innodb-columns-table.html" title="28.4.9 The INFORMATION_SCHEMA INNODB_COLUMNS Table"> <code class="literal"> INNODB_COLUMNS </code> </a> table. </p> </li> <li class="listitem"> <p> You must have the <a class="link" href="privileges-provided.html#priv_process"> <code class="literal"> PROCESS </code> </a> privilege to query this table. </p> </li> <li class="listitem"> <p> Use the <code class="literal"> INFORMATION_SCHEMA </code> <a class="link" href="information-schema-columns-table.html" title="28.3.8 The INFORMATION_SCHEMA COLUMNS Table"> <code class="literal"> COLUMNS </code> </a> table or the <a class="link" href="show-columns.html" title="15.7.7.6 SHOW COLUMNS Statement"> <code class="literal"> SHOW COLUMNS </code> </a> statement to view additional information about the columns of this table, including data types and default values. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/identifier-qualifiers.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="identifier-qualifiers"> </a> 11.2.2 Identifier Qualifiers </h3> </div> </div> </div> <p> Object names may be unqualified or qualified. An unqualified name is permitted in contexts where interpretation of the name is unambiguous. A qualified name includes at least one qualifier to clarify the interpretive context by overriding a default context or providing missing context. </p> <p> For example, this statement creates a table using the unqualified name <code class="literal"> t1 </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa65330541"><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">TABLE</span> t1 <span class="token punctuation">(</span>i <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> Because <code class="literal"> t1 </code> includes no qualifier to specify a database, the statement creates the table in the default database. If there is no default database, an error occurs. </p> <p> This statement creates a table using the qualified name <code class="literal"> db1.t1 </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa15696632"><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">TABLE</span> db1<span class="token punctuation">.</span>t1 <span class="token punctuation">(</span>i <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> Because <code class="literal"> db1.t1 </code> includes a database qualifier <code class="literal"> db1 </code> , the statement creates <code class="literal"> t1 </code> in the database named <code class="literal"> db1 </code> , regardless of the default database. The qualifier <span class="emphasis"> <em> must </em> </span> be specified if there is no default database. The qualifier <span class="emphasis"> <em> may </em> </span> be specified if there is a default database, to specify a database different from the default, or to make the database explicit if the default is the same as the one specified. </p> <p> Qualifiers have these characteristics: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> An unqualified name consists of a single identifier. A qualified name consists of multiple identifiers. </p> </li> <li class="listitem"> <p> The components of a multiple-part name must be separated by period ( <code class="literal"> . </code> ) characters. The initial parts of a multiple-part name act as qualifiers that affect the context within which to interpret the final identifier. </p> </li> <li class="listitem"> <p> The qualifier character is a separate token and need not be contiguous with the associated identifiers. For example, <em class="replaceable"> <code> tbl_name.col_name </code> </em> and <em class="replaceable"> <code> tbl_name . col_name </code> </em> are equivalent. </p> </li> <li class="listitem"> <p> If any components of a multiple-part name require quoting, quote them individually rather than quoting the name as a whole. For example, write <code class="literal"> `my-table`.`my-column` </code> , not <code class="literal"> `my-table.my-column` </code> . </p> </li> <li class="listitem"> <p> A reserved word that follows a period in a qualified name must be an identifier, so in that context it need not be quoted. </p> </li> </ul> </div> <p> The permitted qualifiers for object names depend on the object type: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A database name is fully qualified and takes no qualifier: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa16482361"><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">DATABASE</span> db1<span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> A table, view, or stored program name may be given a database-name qualifier. Examples of unqualified and qualified names in <code class="literal"> CREATE </code> statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa90218257"><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">TABLE</span> mytable <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">VIEW</span> myview <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> myproc <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">FUNCTION</span> myfunc <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">EVENT</span> myevent <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> mydb<span class="token punctuation">.</span>mytable <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">VIEW</span> mydb<span class="token punctuation">.</span>myview <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> mydb<span class="token punctuation">.</span>myproc <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">FUNCTION</span> mydb<span class="token punctuation">.</span>myfunc <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">EVENT</span> mydb<span class="token punctuation">.</span>myevent <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> A trigger is associated with a table, so any qualifier applies to the table name: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa245474"><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">TRIGGER</span> mytrigger <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">ON</span> mytable <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TRIGGER</span> mytrigger <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">ON</span> mydb<span class="token punctuation">.</span>mytable <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> A column name may be given multiple qualifiers to indicate context in statements that reference it, as shown in the following table. </p> <div class="informaltable"> <table summary="Column reference formats that can be used to refer to table columns."> <colgroup> <col style="width: 35%"/> <col style="width: 65%"/> </colgroup> <thead> <tr> <th> Column Reference </th> <th> Meaning </th> </tr> </thead> <tbody> <tr> <td> <em class="replaceable"> <code> col_name </code> </em> </td> <td> Column <em class="replaceable"> <code> col_name </code> </em> from whichever table used in the statement contains a column of that name </td> </tr> <tr> <td> <em class="replaceable"> <code> tbl_name.col_name </code> </em> </td> <td> Column <em class="replaceable"> <code> col_name </code> </em> from table <em class="replaceable"> <code> tbl_name </code> </em> of the default database </td> </tr> <tr> <td> <em class="replaceable"> <code> db_name.tbl_name.col_name </code> </em> </td> <td> Column <em class="replaceable"> <code> col_name </code> </em> from table <em class="replaceable"> <code> tbl_name </code> </em> of the database <em class="replaceable"> <code> db_name </code> </em> </td> </tr> </tbody> </table> </div> <p> In other words, a column name may be given a table-name qualifier, which itself may be given a database-name qualifier. Examples of unqualified and qualified column references in <code class="literal"> SELECT </code> statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa39650435"><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> c1 <span class="token keyword">FROM</span> mytable <span class="token keyword">WHERE</span> c2 <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span> <span class="token keyword">SELECT</span> mytable<span class="token punctuation">.</span>c1 <span class="token keyword">FROM</span> mytable <span class="token keyword">WHERE</span> mytable<span class="token punctuation">.</span>c2 <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span> <span class="token keyword">SELECT</span> mydb<span class="token punctuation">.</span>mytable<span class="token punctuation">.</span>c1 <span class="token keyword">FROM</span> mydb<span class="token punctuation">.</span>mytable <span class="token keyword">WHERE</span> mydb<span class="token punctuation">.</span>mytable<span class="token punctuation">.</span>c2 <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> You need not specify a qualifier for an object reference in a statement unless the unqualified reference is ambiguous. Suppose that column <code class="literal"> c1 </code> occurs only in table <code class="literal"> t1 </code> , <code class="literal"> c2 </code> only in <code class="literal"> t2 </code> , and <code class="literal"> c </code> in both <code class="literal"> t1 </code> and <code class="literal"> t2 </code> . Any unqualified reference to <code class="literal"> c </code> is ambiguous in a statement that refers to both tables and must be qualified as <code class="literal"> t1.c </code> or <code class="literal"> t2.c </code> to indicate which table you mean: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85257659"><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> c1<span class="token punctuation">,</span> c2<span class="token punctuation">,</span> t1<span class="token punctuation">.</span>c <span class="token keyword">FROM</span> t1 <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> t2 <span class="token keyword">WHERE</span> t2<span class="token punctuation">.</span>c <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> <p> Similarly, to retrieve from a table <code class="literal"> t </code> in database <code class="literal"> db1 </code> and from a table <code class="literal"> t </code> in database <code class="literal"> db2 </code> in the same statement, you must qualify the table references: For references to columns in those tables, qualifiers are required only for column names that appear in both tables. Suppose that column <code class="literal"> c1 </code> occurs only in table <code class="literal"> db1.t </code> , <code class="literal"> c2 </code> only in <code class="literal"> db2.t </code> , and <code class="literal"> c </code> in both <code class="literal"> db1.t </code> and <code class="literal"> db2.t </code> . In this case, <code class="literal"> c </code> is ambiguous and must be qualified but <code class="literal"> c1 </code> and <code class="literal"> c2 </code> need not be: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa48686383"><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> c1<span class="token punctuation">,</span> c2<span class="token punctuation">,</span> db1<span class="token punctuation">.</span>t<span class="token punctuation">.</span>c <span class="token keyword">FROM</span> db1<span class="token punctuation">.</span>t <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> db2<span class="token punctuation">.</span>t <span class="token keyword">WHERE</span> db2<span class="token punctuation">.</span>t<span class="token punctuation">.</span>c <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> <p> Table aliases enable qualified column references to be written more simply: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51250567"><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> c1<span class="token punctuation">,</span> c2<span class="token punctuation">,</span> t1<span class="token punctuation">.</span>c <span class="token keyword">FROM</span> db1<span class="token punctuation">.</span>t <span class="token keyword">AS</span> t1 <span class="token keyword">INNER</span> <span class="token keyword">JOIN</span> db2<span class="token punctuation">.</span>t <span class="token keyword">AS</span> t2 <span class="token keyword">WHERE</span> t2<span class="token punctuation">.</span>c <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/other-administrative-statements.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="other-administrative-statements"> </a> 15.7.8 Other Administrative Statements </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="binlog.html"> 15.7.8.1 BINLOG Statement </a> </span> </dt> <dt> <span class="section"> <a href="cache-index.html"> 15.7.8.2 CACHE INDEX Statement </a> </span> </dt> <dt> <span class="section"> <a href="flush.html"> 15.7.8.3 FLUSH Statement </a> </span> </dt> <dt> <span class="section"> <a href="kill.html"> 15.7.8.4 KILL Statement </a> </span> </dt> <dt> <span class="section"> <a href="load-index.html"> 15.7.8.5 LOAD INDEX INTO CACHE Statement </a> </span> </dt> <dt> <span class="section"> <a href="reset.html"> 15.7.8.6 RESET Statement </a> </span> </dt> <dt> <span class="section"> <a href="reset-persist.html"> 15.7.8.7 RESET PERSIST Statement </a> </span> </dt> <dt> <span class="section"> <a href="restart.html"> 15.7.8.8 RESTART Statement </a> </span> </dt> <dt> <span class="section"> <a href="shutdown.html"> 15.7.8.9 SHUTDOWN Statement </a> </span> </dt> </dl> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/show-create-database.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="show-create-database"> </a> 15.7.7.7 SHOW CREATE DATABASE Statement </h4> </div> </div> </div> <a class="indexterm" name="idm46045170960544"> </a> <a class="indexterm" name="idm46045170959488"> </a> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa39712200"><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">SHOW</span> <span class="token keyword">CREATE</span> {<span class="token keyword">DATABASE</span> <span class="token operator">|</span> <span class="token keyword">SCHEMA</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> <em class="replaceable">db_name</em></code></pre> </div> <p> Shows the <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement"> <code class="literal"> CREATE DATABASE </code> </a> statement that creates the named database. If the <code class="literal"> SHOW </code> statement includes an <code class="literal"> IF NOT EXISTS </code> clause, the output too includes such a clause. <a class="link" href="show-create-database.html" title="15.7.7.7 SHOW CREATE DATABASE Statement"> <code class="literal"> SHOW CREATE SCHEMA </code> </a> is a synonym for <a class="link" href="show-create-database.html" title="15.7.7.7 SHOW CREATE DATABASE Statement"> <code class="literal"> SHOW CREATE DATABASE </code> </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa39707235"><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">CREATE</span> <span class="token keyword">DATABASE</span> test\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> Database<span class="token punctuation">:</span> test Create Database<span class="token punctuation">:</span> CREATE DATABASE `test` /<span class="token punctuation">*</span>!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci <span class="token punctuation">*</span>/ /<span class="token punctuation">*</span>!80014 DEFAULT ENCRYPTION='N' <span class="token punctuation">*</span>/ </span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">CREATE</span> <span class="token keyword">SCHEMA</span> test\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> Database<span class="token punctuation">:</span> test Create Database<span class="token punctuation">:</span> CREATE DATABASE `test` /<span class="token punctuation">*</span>!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci <span class="token punctuation">*</span>/ /<span class="token punctuation">*</span>!80014 DEFAULT ENCRYPTION='N' <span class="token punctuation">*</span>/</span></code></pre> </div> <p> <a class="link" href="show-create-database.html" title="15.7.7.7 SHOW CREATE DATABASE Statement"> <code class="literal"> SHOW CREATE DATABASE </code> </a> quotes table and column names according to the value of the <a class="link" href="server-system-variables.html#sysvar_sql_quote_show_create"> <code class="literal"> sql_quote_show_create </code> </a> option. See <a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables"> Section 7.1.8, “Server System Variables” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/workbench.html
<div id="docs-body"> <div class="chapter"> <div class="titlepage"> <div> <div> <h1 class="title"> <a name="workbench"> </a> Chapter 33 MySQL Workbench </h1> </div> </div> </div> <p> MySQL Workbench provides a graphical tool for working with MySQL servers and databases. MySQL Workbench fully supports MySQL versions 5.5 and higher. </p> <p> The following discussion briefly describes MySQL Workbench capabilities. For more information, see the MySQL Workbench manual, available at <a class="ulink" href="/doc/workbench/en/" target="_top"> https://dev.mysql.com/doc/workbench/en/ </a> . </p> <p> MySQL Workbench provides five main areas of functionality: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <span class="bold"> <strong> SQL Development </strong> </span> : Enables you to create and manage connections to database servers. As well as enabling you to configure connection parameters, MySQL Workbench provides the capability to execute SQL queries on the database connections using the built-in SQL Editor. This functionality replaces that previously provided by the Query Browser standalone application. </p> </li> <li class="listitem"> <p> <span class="bold"> <strong> Data Modeling </strong> </span> : Enables you to create models of your database schema graphically, reverse and forward engineer between a schema and a live database, and edit all aspects of your database using the comprehensive Table Editor. The Table Editor provides easy-to-use facilities for editing Tables, Columns, Indexes, Triggers, Partitioning, Options, Inserts and Privileges, Routines and Views. </p> </li> <li class="listitem"> <p> <span class="bold"> <strong> Server Administration </strong> </span> : Enables you to create and administer server instances. </p> </li> <li class="listitem"> <p> <span class="bold"> <strong> Data Migration </strong> </span> : Allows you to migrate from Microsoft SQL Server, Sybase ASE, SQLite, SQL Anywhere, PostreSQL, and other RDBMS tables, objects and data to MySQL. Migration also supports migrating from earlier versions of MySQL to the latest releases. </p> </li> <li class="listitem"> <p> <span class="bold"> <strong> MySQL Enterprise Support </strong> </span> : Support for Enterprise products such as MySQL Enterprise Backup and MySQL Audit. </p> </li> </ul> </div> <p> MySQL Workbench is available in two editions, the Community Edition and the Commercial Edition. The Community Edition is available free of charge. The Commercial Edition provides additional Enterprise features, such as database documentation generation, at low cost. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/optimizer-trace-testing.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="optimizer-trace-testing"> </a> 10.15.15 Testing Optimizer Trace </h3> </div> </div> </div> <p> This feature is tested in <code class="filename"> mysql-test/suite/opt_trace </code> and <code class="filename"> unittest/gunit/opt_trace-t </code> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/macos-installation.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="macos-installation"> </a> 2.4 Installing MySQL on macOS </h2> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="macos-installation-notes.html"> 2.4.1 General Notes on Installing MySQL on macOS </a> </span> </dt> <dt> <span class="section"> <a href="macos-installation-pkg.html"> 2.4.2 Installing MySQL on macOS Using Native Packages </a> </span> </dt> <dt> <span class="section"> <a href="macos-installation-launchd.html"> 2.4.3 Installing and Using the MySQL Launch Daemon </a> </span> </dt> <dt> <span class="section"> <a href="macos-installation-prefpane.html"> 2.4.4 Installing and Using the MySQL Preference Pane </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045331698080"> </a> <a class="indexterm" name="idm46045331696624"> </a> <p> For a list of macOS versions that the MySQL server supports, see <a class="ulink" href="https://www.mysql.com/support/supportedplatforms/database.html" target="_blank"> https://www.mysql.com/support/supportedplatforms/database.html </a> . </p> <p> MySQL for macOS is available in a number of different forms: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Native Package Installer, which uses the native macOS installer (DMG) to walk you through the installation of MySQL. For more information, see <a class="xref" href="macos-installation-pkg.html" title="2.4.2 Installing MySQL on macOS Using Native Packages"> Section 2.4.2, “Installing MySQL on macOS Using Native Packages” </a> . You can use the package installer with macOS. The user you use to perform the installation must have administrator privileges. </p> </li> <li class="listitem"> <p> Compressed TAR archive, which uses a file packaged using the Unix <span class="command"> <strong> tar </strong> </span> and <span class="command"> <strong> gzip </strong> </span> commands. To use this method, you need to open a <span class="command"> <strong> Terminal </strong> </span> window. You do not need administrator privileges using this method; you can install the MySQL server anywhere using this method. For more information on using this method, you can use the generic instructions for using a tarball, <a class="xref" href="binary-installation.html" title="2.2 Installing MySQL on Unix/Linux Using Generic Binaries"> Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries” </a> . </p> <p> In addition to the core installation, the Package Installer also includes <a class="xref" href="macos-installation-launchd.html" title="2.4.3 Installing and Using the MySQL Launch Daemon"> Section 2.4.3, “Installing and Using the MySQL Launch Daemon” </a> and <a class="xref" href="macos-installation-prefpane.html" title="2.4.4 Installing and Using the MySQL Preference Pane"> Section 2.4.4, “Installing and Using the MySQL Preference Pane” </a> to simplify the management of your installation. </p> </li> </ul> </div> <p> For additional information on using MySQL on macOS, see <a class="xref" href="macos-installation-notes.html" title="2.4.1 General Notes on Installing MySQL on macOS"> Section 2.4.1, “General Notes on Installing MySQL on macOS” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-session-account-connect-attrs-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="performance-schema-session-account-connect-attrs-table"> </a> 29.12.9.1 The session_account_connect_attrs Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045071848976"> </a> <a class="indexterm" name="idm46045071847472"> </a> <p> Application programs can provide key-value connection attributes to be passed to the server at connect time. For descriptions of common attributes, see <a class="xref" href="performance-schema-connection-attribute-tables.html" title="29.12.9 Performance Schema Connection Attribute Tables"> Section 29.12.9, “Performance Schema Connection Attribute Tables” </a> . </p> <p> The <a class="link" href="performance-schema-session-account-connect-attrs-table.html" title="29.12.9.1 The session_account_connect_attrs Table"> <code class="literal"> session_account_connect_attrs </code> </a> table contains connection attributes only for the current session, and other sessions associated with the session account. To see connection attributes for all sessions, use the <a class="link" href="performance-schema-session-connect-attrs-table.html" title="29.12.9.2 The session_connect_attrs Table"> <code class="literal"> session_connect_attrs </code> </a> table. </p> <p> The <a class="link" href="performance-schema-session-account-connect-attrs-table.html" title="29.12.9.1 The session_account_connect_attrs Table"> <code class="literal"> session_account_connect_attrs </code> </a> table has these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> PROCESSLIST_ID </code> </p> <p> The connection identifier for the session. </p> </li> <li class="listitem"> <p> <code class="literal"> ATTR_NAME </code> </p> <p> The attribute name. </p> </li> <li class="listitem"> <p> <code class="literal"> ATTR_VALUE </code> </p> <p> The attribute value. </p> </li> <li class="listitem"> <p> <code class="literal"> ORDINAL_POSITION </code> </p> <p> The order in which the attribute was added to the set of connection attributes. </p> </li> </ul> </div> <p> The <a class="link" href="performance-schema-session-account-connect-attrs-table.html" title="29.12.9.1 The session_account_connect_attrs Table"> <code class="literal"> session_account_connect_attrs </code> </a> table has these indexes: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Primary key on ( <code class="literal"> PROCESSLIST_ID </code> , <code class="literal"> ATTR_NAME </code> ) </p> </li> </ul> </div> <p> <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> is not permitted for the <a class="link" href="performance-schema-session-account-connect-attrs-table.html" title="29.12.9.1 The session_account_connect_attrs Table"> <code class="literal"> session_account_connect_attrs </code> </a> table. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/group-replication-deploying-in-multi-primary-or-single-primary-mode.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="group-replication-deploying-in-multi-primary-or-single-primary-mode"> </a> 20.1.3 Multi-Primary and Single-Primary Modes </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="group-replication-single-primary-mode.html"> 20.1.3.1 Single-Primary Mode </a> </span> </dt> <dt> <span class="section"> <a href="group-replication-multi-primary-mode.html"> 20.1.3.2 Multi-Primary Mode </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045134507856"> </a> <a class="indexterm" name="idm46045134506352"> </a> <a class="indexterm" name="idm46045134504864"> </a> <p> Group Replication operates either in single-primary mode or in multi-primary mode. The group's mode is a group-wide configuration setting, specified by the <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_single_primary_mode"> <code class="literal"> group_replication_single_primary_mode </code> </a> system variable, which must be the same on all members. <code class="literal"> ON </code> means single-primary mode, which is the default mode, and <code class="literal"> OFF </code> means multi-primary mode. It is not possible to have members of the group deployed in different modes, for example one member configured in multi-primary mode while another member is in single-primary mode. </p> <p> You cannot change the value of <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_single_primary_mode"> <code class="literal"> group_replication_single_primary_mode </code> </a> manually while Group Replication is running. You can use the <a class="link" href="group-replication-functions-for-mode.html#function_group-replication-switch-to-single-primary-mode"> <code class="literal"> group_replication_switch_to_single_primary_mode() </code> </a> and <a class="link" href="group-replication-functions-for-mode.html#function_group-replication-switch-to-multi-primary-mode"> <code class="literal"> group_replication_switch_to_multi_primary_mode() </code> </a> functions to move a group from one mode to another while Group Replication is still running. These functions manage the process of changing the group's mode and ensure the safety and consistency of your data. In earlier releases, to change the group's mode you must stop Group Replication and change the value of <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_single_primary_mode"> <code class="literal"> group_replication_single_primary_mode </code> </a> on all members. Then carry out a full reboot of the group (a bootstrap by a server with <a class="link" href="group-replication-system-variables.html#sysvar_group_replication_bootstrap_group"> <code class="literal"> group_replication_bootstrap_group=ON </code> </a> ) to implement the change to the new operating configuration. You do not need to restart the servers. </p> <p> Regardless of the deployed mode, Group Replication does not handle client-side failover. That must be handled by a middleware framework such as <a class="ulink" href="/doc/mysql-router/8.4/en/" target="_top"> MySQL Router 8.4 </a> , a proxy, a connector, or the application itself. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/gis-linestring-property-functions.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="gis-linestring-property-functions"> </a> 14.16.7.3 LineString and MultiLineString Property Functions </h4> </div> </div> </div> <p> A <code class="literal"> LineString </code> consists of <code class="literal"> Point </code> values. You can extract particular points of a <code class="literal"> LineString </code> , count the number of points that it contains, or obtain its length. </p> <p> Some functions in this section also work for <code class="literal"> MultiLineString </code> values. </p> <p> Unless otherwise specified, functions in this section handle their geometry arguments as follows: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If any argument is <code class="literal"> NULL </code> or any geometry argument is an empty geometry, the return value is <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> If any geometry argument is not a syntactically well-formed geometry, an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_gis_invalid_data" target="_top"> <code class="literal"> ER_GIS_INVALID_DATA </code> </a> error occurs. </p> </li> <li class="listitem"> <p> If any geometry argument is a syntactically well-formed geometry in an undefined spatial reference system (SRS), an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_srs_not_found" target="_top"> <code class="literal"> ER_SRS_NOT_FOUND </code> </a> error occurs. </p> </li> <li class="listitem"> <p> Otherwise, the return value is non- <code class="literal"> NULL </code> . </p> </li> </ul> </div> <p> These functions are available for obtaining linestring properties: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <a name="function_st-endpoint"> </a> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-endpoint"> <code class="literal"> ST_EndPoint( <em class="replaceable"> <code> ls </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045197305024"> </a> <p> Returns the <code class="literal"> Point </code> that is the endpoint of the <code class="literal"> LineString </code> value <em class="replaceable"> <code> ls </code> </em> . </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-endpoint"> <code class="literal"> ST_EndPoint() </code> </a> handles its arguments as described in the introduction to this section. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa79717437"><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> <span class="token variable">@ls</span> <span class="token operator">=</span> <span class="token string">'LineString(1 1,2 2,3 3)'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_AsText</span><span class="token punctuation">(</span><span class="token function">ST_EndPoint</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_AsText(ST_EndPoint(ST_GeomFromText(@ls))) <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> <span class="token output"><span class="token punctuation">|</span> POINT(3 3) <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></code></pre> </div> </li> <li class="listitem"> <a name="function_st-isclosed"> </a> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-isclosed"> <code class="literal"> ST_IsClosed( <em class="replaceable"> <code> ls </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045197291424"> </a> <p> For a <code class="literal"> LineString </code> value <em class="replaceable"> <code> ls </code> </em> , <a class="link" href="gis-linestring-property-functions.html#function_st-isclosed"> <code class="literal"> ST_IsClosed() </code> </a> returns 1 if <em class="replaceable"> <code> ls </code> </em> is closed (that is, its <a class="link" href="gis-linestring-property-functions.html#function_st-startpoint"> <code class="literal"> ST_StartPoint() </code> </a> and <a class="link" href="gis-linestring-property-functions.html#function_st-endpoint"> <code class="literal"> ST_EndPoint() </code> </a> values are the same). </p> <p> For a <code class="literal"> MultiLineString </code> value <em class="replaceable"> <code> ls </code> </em> , <a class="link" href="gis-linestring-property-functions.html#function_st-isclosed"> <code class="literal"> ST_IsClosed() </code> </a> returns 1 if <em class="replaceable"> <code> ls </code> </em> is closed (that is, the <a class="link" href="gis-linestring-property-functions.html#function_st-startpoint"> <code class="literal"> ST_StartPoint() </code> </a> and <a class="link" href="gis-linestring-property-functions.html#function_st-endpoint"> <code class="literal"> ST_EndPoint() </code> </a> values are the same for each <code class="literal"> LineString </code> in <em class="replaceable"> <code> ls </code> </em> ). </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-isclosed"> <code class="literal"> ST_IsClosed() </code> </a> returns 0 if <em class="replaceable"> <code> ls </code> </em> is not closed, and <code class="literal"> NULL </code> if <em class="replaceable"> <code> ls </code> </em> is <code class="literal"> NULL </code> . </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-isclosed"> <code class="literal"> ST_IsClosed() </code> </a> handles its arguments as described in the introduction to this section, with this exception: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> If the geometry has an SRID value for a geographic spatial reference system (SRS), an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_not_implemented_for_geographic_srs" target="_top"> <code class="literal"> ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS </code> </a> error occurs. </p> </li> </ul> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89716030"><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> <span class="token variable">@ls1</span> <span class="token operator">=</span> <span class="token string">'LineString(1 1,2 2,3 3,2 2)'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@ls2</span> <span class="token operator">=</span> <span class="token string">'LineString(1 1,2 2,3 3,1 1)'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_IsClosed</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls1</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_IsClosed(ST_GeomFromText(@ls1)) <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> <span class="token output"><span class="token punctuation">|</span> 0 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_IsClosed</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls2</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_IsClosed(ST_GeomFromText(@ls2)) <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> <span class="token output"><span class="token punctuation">|</span> 1 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@ls3</span> <span class="token operator">=</span> <span class="token string">'MultiLineString((1 1,2 2,3 3),(4 4,5 5))'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_IsClosed</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls3</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_IsClosed(ST_GeomFromText(@ls3)) <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> <span class="token output"><span class="token punctuation">|</span> 0 <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></code></pre> </div> </li> <li class="listitem"> <a name="function_st-length"> </a> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-length"> <code class="literal"> ST_Length( <em class="replaceable"> <code> ls </code> </em> [, <em class="replaceable"> <code> unit </code> </em> ]) </code> </a> </p> <a class="indexterm" name="idm46045197256848"> </a> <p> Returns a double-precision number indicating the length of the <code class="literal"> LineString </code> or <code class="literal"> MultiLineString </code> value <em class="replaceable"> <code> ls </code> </em> in its associated spatial reference system. The length of a <code class="literal"> MultiLineString </code> value is equal to the sum of the lengths of its elements. </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-length"> <code class="literal"> ST_Length() </code> </a> computes a result as follows: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> If the geometry is a valid <code class="literal"> LineString </code> in a Cartesian SRS, the return value is the Cartesian length of the geometry. </p> </li> <li class="listitem"> <p> If the geometry is a valid <code class="literal"> MultiLineString </code> in a Cartesian SRS, the return value is the sum of the Cartesian lengths of its elements. </p> </li> <li class="listitem"> <p> If the geometry is a valid <code class="literal"> LineString </code> in a geographic SRS, the return value is the geodetic length of the geometry in that SRS, in meters. </p> </li> <li class="listitem"> <p> If the geometry is a valid <code class="literal"> MultiLineString </code> in a geographic SRS, the return value is the sum of the geodetic lengths of its elements in that SRS, in meters. </p> </li> </ul> </div> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-length"> <code class="literal"> ST_Length() </code> </a> handles its arguments as described in the introduction to this section, with these exceptions: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> If the geometry is not a <code class="literal"> LineString </code> or <code class="literal"> MultiLineString </code> , the return value is <code class="literal"> NULL </code> . </p> </li> <li class="listitem"> <p> If the geometry is geometrically invalid, either the result is an undefined length (that is, it can be any number), or an error occurs. </p> </li> <li class="listitem"> <p> If the length computation result is <code class="literal"> +inf </code> , an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_data_out_of_range" target="_top"> <code class="literal"> ER_DATA_OUT_OF_RANGE </code> </a> error occurs. </p> </li> <li class="listitem"> <p> If the geometry has a geographic SRS with a longitude or latitude that is out of range, an error occurs: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: square; "> <li class="listitem"> <p> If a longitude value is not in the range (−180, 180], an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_geometry_param_longitude_out_of_range" target="_top"> <code class="literal"> ER_GEOMETRY_PARAM_LONGITUDE_OUT_OF_RANGE </code> </a> error occurs. </p> </li> <li class="listitem"> <p> If a latitude value is not in the range [−90, 90], an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_geometry_param_latitude_out_of_range" target="_top"> <code class="literal"> ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE </code> </a> error occurs. </p> </li> </ul> </div> <p> Ranges shown are in degrees. The exact range limits deviate slightly due to floating-point arithmetic. </p> </li> </ul> </div> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-length"> <code class="literal"> ST_Length() </code> </a> permits an optional <em class="replaceable"> <code> unit </code> </em> argument that specifies the linear unit for the returned length value. These rules apply: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> If a unit is specified but not supported by MySQL, an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_unit_not_found" target="_top"> <code class="literal"> ER_UNIT_NOT_FOUND </code> </a> error occurs. </p> </li> <li class="listitem"> <p> If a supported linear unit is specified and the SRID is 0, an <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_geometry_in_unknown_length_unit" target="_top"> <code class="literal"> ER_GEOMETRY_IN_UNKNOWN_LENGTH_UNIT </code> </a> error occurs. </p> </li> <li class="listitem"> <p> If a supported linear unit is specified and the SRID is not 0, the result is in that unit. </p> </li> <li class="listitem"> <p> If a unit is not specified, the result is in the unit of the SRS of the geometries, whether Cartesian or geographic. Currently, all MySQL SRSs are expressed in meters. </p> </li> </ul> </div> <p> A unit is supported if it is found in the <code class="literal"> INFORMATION_SCHEMA </code> <a class="link" href="information-schema-st-units-of-measure-table.html" title="28.3.37 The INFORMATION_SCHEMA ST_UNITS_OF_MEASURE Table"> <code class="literal"> ST_UNITS_OF_MEASURE </code> </a> table. See <a class="xref" href="information-schema-st-units-of-measure-table.html" title="28.3.37 The INFORMATION_SCHEMA ST_UNITS_OF_MEASURE Table"> Section 28.3.37, “The INFORMATION_SCHEMA ST_UNITS_OF_MEASURE Table” </a> . </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa82227910"><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> <span class="token variable">@ls</span> <span class="token operator">=</span> <span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token string">'LineString(1 1,2 2,3 3)'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_Length</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_Length(@ls) <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> <span class="token output"><span class="token punctuation">|</span> 2.8284271247461903 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@mls</span> <span class="token operator">=</span> <span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token string">'MultiLineString((1 1,2 2,3 3),(4 4,5 5))'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_Length</span><span class="token punctuation">(</span><span class="token variable">@mls</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_Length(@mls) <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> <span class="token output"><span class="token punctuation">|</span> 4.242640687119286 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@ls</span> <span class="token operator">=</span> <span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token string">'LineString(1 1,2 2,3 3)'</span><span class="token punctuation">,</span> <span class="token number">4326</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_Length</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_Length(@ls) <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> <span class="token output"><span class="token punctuation">|</span> 313701.9623204328 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_Length</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">,</span> <span class="token string">'metre'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_Length(@ls, 'metre') <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> <span class="token output"><span class="token punctuation">|</span> 313701.9623204328 <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> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_Length</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">,</span> <span class="token string">'foot'</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_Length(@ls, 'foot') <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> <span class="token output"><span class="token punctuation">|</span> 1029205.9131247795 <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></code></pre> </div> </li> <li class="listitem"> <a name="function_st-numpoints"> </a> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-numpoints"> <code class="literal"> ST_NumPoints( <em class="replaceable"> <code> ls </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045197202464"> </a> <p> Returns the number of <code class="literal"> Point </code> objects in the <code class="literal"> LineString </code> value <em class="replaceable"> <code> ls </code> </em> . </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-numpoints"> <code class="literal"> ST_NumPoints() </code> </a> handles its arguments as described in the introduction to this section. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa30300123"><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> <span class="token variable">@ls</span> <span class="token operator">=</span> <span class="token string">'LineString(1 1,2 2,3 3)'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_NumPoints</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_NumPoints(ST_GeomFromText(@ls)) <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> <span class="token output"><span class="token punctuation">|</span> 3 <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></code></pre> </div> </li> <li class="listitem"> <a name="function_st-pointn"> </a> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-pointn"> <code class="literal"> ST_PointN( <em class="replaceable"> <code> ls </code> </em> , <em class="replaceable"> <code> N </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045197188512"> </a> <p> Returns the <em class="replaceable"> <code> N </code> </em> -th <code class="literal"> Point </code> in the <code class="literal"> Linestring </code> value <em class="replaceable"> <code> ls </code> </em> . Points are numbered beginning with 1. </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-pointn"> <code class="literal"> ST_PointN() </code> </a> handles its arguments as described in the introduction to this section. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59191454"><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> <span class="token variable">@ls</span> <span class="token operator">=</span> <span class="token string">'LineString(1 1,2 2,3 3)'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_AsText</span><span class="token punctuation">(</span><span class="token function">ST_PointN</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_AsText(ST_PointN(ST_GeomFromText(@ls),2)) <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> <span class="token output"><span class="token punctuation">|</span> POINT(2 2) <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></code></pre> </div> </li> <li class="listitem"> <a name="function_st-startpoint"> </a> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-startpoint"> <code class="literal"> ST_StartPoint( <em class="replaceable"> <code> ls </code> </em> ) </code> </a> </p> <a class="indexterm" name="idm46045197174480"> </a> <p> Returns the <code class="literal"> Point </code> that is the start point of the <code class="literal"> LineString </code> value <em class="replaceable"> <code> ls </code> </em> . </p> <p> <a class="link" href="gis-linestring-property-functions.html#function_st-startpoint"> <code class="literal"> ST_StartPoint() </code> </a> handles its arguments as described in the introduction to this section. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa8042608"><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> <span class="token variable">@ls</span> <span class="token operator">=</span> <span class="token string">'LineString(1 1,2 2,3 3)'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ST_AsText</span><span class="token punctuation">(</span><span class="token function">ST_StartPoint</span><span class="token punctuation">(</span><span class="token function">ST_GeomFromText</span><span class="token punctuation">(</span><span class="token variable">@ls</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> ST_AsText(ST_StartPoint(ST_GeomFromText(@ls))) <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> <span class="token output"><span class="token punctuation">|</span> POINT(1 1) <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></code></pre> </div> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/innodb-deadlocks-handling.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="innodb-deadlocks-handling"> </a> 17.7.5.3 How to Minimize and Handle Deadlocks </h4> </div> </div> </div> <p> This section builds on the conceptual information about deadlocks in <a class="xref" href="innodb-deadlock-detection.html" title="17.7.5.2 Deadlock Detection"> Section 17.7.5.2, “Deadlock Detection” </a> . It explains how to organize database operations to minimize deadlocks and the subsequent error handling required in applications. </p> <p> <a class="link" href="glossary.html#glos_deadlock" title="deadlock"> Deadlocks </a> are a classic problem in transactional databases, but they are not dangerous unless they are so frequent that you cannot run certain transactions at all. Normally, you must write your applications so that they are always prepared to re-issue a transaction if it gets rolled back because of a deadlock. </p> <p> <code class="literal"> InnoDB </code> uses automatic row-level locking. You can get deadlocks even in the case of transactions that just insert or delete a single row. That is because these operations are not really <span class="quote"> “ <span class="quote"> atomic </span> ” </span> ; they automatically set locks on the (possibly several) index records of the row inserted or deleted. </p> <p> You can cope with deadlocks and reduce the likelihood of their occurrence with the following techniques: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> At any time, issue <a class="link" href="show-engine.html" title="15.7.7.16 SHOW ENGINE Statement"> <code class="literal"> SHOW ENGINE INNODB STATUS </code> </a> to determine the cause of the most recent deadlock. That can help you to tune your application to avoid deadlocks. </p> </li> <li class="listitem"> <p> If frequent deadlock warnings cause concern, collect more extensive debugging information by enabling the <a class="link" href="innodb-parameters.html#sysvar_innodb_print_all_deadlocks"> <code class="literal"> innodb_print_all_deadlocks </code> </a> variable. Information about each deadlock, not just the latest one, is recorded in the MySQL <a class="link" href="glossary.html#glos_error_log" title="error log"> error log </a> . Disable this option when you are finished debugging. </p> </li> <li class="listitem"> <p> Always be prepared to re-issue a transaction if it fails due to deadlock. Deadlocks are not dangerous. Just try again. </p> </li> <li class="listitem"> <p> Keep transactions small and short in duration to make them less prone to collision. </p> </li> <li class="listitem"> <p> Commit transactions immediately after making a set of related changes to make them less prone to collision. In particular, do not leave an interactive <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client"> <span class="command"> <strong> mysql </strong> </span> </a> session open for a long time with an uncommitted transaction. </p> </li> <li class="listitem"> <p> If you use <a class="link" href="glossary.html#glos_locking_read" title="locking read"> locking reads </a> ( <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT ... FOR UPDATE </code> </a> or <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT ... FOR SHARE </code> </a> ), try using a lower isolation level such as <a class="link" href="innodb-transaction-isolation-levels.html#isolevel_read-committed"> <code class="literal"> READ COMMITTED </code> </a> . </p> </li> <li class="listitem"> <p> When modifying multiple tables within a transaction, or different sets of rows in the same table, do those operations in a consistent order each time. Then transactions form well-defined queues and do not deadlock. For example, organize database operations into functions within your application, or call stored routines, rather than coding multiple similar sequences of <code class="literal"> INSERT </code> , <code class="literal"> UPDATE </code> , and <code class="literal"> DELETE </code> statements in different places. </p> </li> <li class="listitem"> <p> Add well-chosen indexes to your tables so that your queries scan fewer index records and set fewer locks. Use <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN SELECT </code> </a> to determine which indexes the MySQL server regards as the most appropriate for your queries. </p> </li> <li class="listitem"> <p> Use less locking. If you can afford to permit a <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> to return data from an old snapshot, do not add a <code class="literal"> FOR UPDATE </code> or <code class="literal"> FOR SHARE </code> clause to it. Using the <a class="link" href="innodb-transaction-isolation-levels.html#isolevel_read-committed"> <code class="literal"> READ COMMITTED </code> </a> isolation level is good here, because each consistent read within the same transaction reads from its own fresh snapshot. </p> </li> <li class="listitem"> <p> If nothing else helps, serialize your transactions with table-level locks. The correct way to use <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements"> <code class="literal"> LOCK TABLES </code> </a> with transactional tables, such as <code class="literal"> InnoDB </code> tables, is to begin a transaction with <code class="literal"> SET autocommit = 0 </code> (not <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements"> <code class="literal"> START TRANSACTION </code> </a> ) followed by <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements"> <code class="literal"> LOCK TABLES </code> </a> , and to not call <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements"> <code class="literal"> UNLOCK TABLES </code> </a> until you commit the transaction explicitly. For example, if you need to write to table <code class="literal"> t1 </code> and read from table <code class="literal"> t2 </code> , you can do this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa28768858"><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> autocommit<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span> <span class="token keyword">LOCK</span> <span class="token keyword">TABLES</span> t1 <span class="token keyword">WRITE</span><span class="token punctuation">,</span> t2 <span class="token keyword">READ</span><span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">;</span> <span class="token punctuation"></span><em class="replaceable"><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">do</span> something <span class="token keyword">with</span> <span class="token keyword">tables</span> t1 <span class="token operator">and</span> t2 here <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></em><span class="token punctuation"></span> <span class="token keyword">COMMIT</span><span class="token punctuation">;</span> <span class="token keyword">UNLOCK</span> <span class="token keyword">TABLES</span><span class="token punctuation">;</span></code></pre> </div> <p> Table-level locks prevent concurrent updates to the table, avoiding deadlocks at the expense of less responsiveness for a busy system. </p> </li> <li class="listitem"> <p> Another way to serialize transactions is to create an auxiliary <span class="quote"> “ <span class="quote"> semaphore </span> ” </span> table that contains just a single row. Have each transaction update that row before accessing other tables. In that way, all transactions happen in a serial fashion. Note that the <code class="literal"> InnoDB </code> instant deadlock detection algorithm also works in this case, because the serializing lock is a row-level lock. With MySQL table-level locks, the timeout method must be used to resolve deadlocks. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/test-pluggable-authentication.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="test-pluggable-authentication"> </a> 8.4.1.12 Test Pluggable Authentication </h4> </div> </div> </div> <a class="indexterm" name="idm46045243849488"> </a> <a class="indexterm" name="idm46045243848384"> </a> <a class="indexterm" name="idm46045243846896"> </a> <a class="indexterm" name="idm46045243845808"> </a> <p> MySQL includes a test plugin that checks account credentials and logs success or failure to the server error log. This is a loadable plugin (not built in) and must be installed prior to use. </p> <p> The test plugin source code is separate from the server source, unlike the built-in native plugin, so it can be examined as a relatively simple example demonstrating how to write a loadable authentication plugin. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> This plugin is intended for testing and development purposes, and is not for use in production environments or on servers that are exposed to public networks. </p> </div> <p> The following table shows the plugin and library file names. The file name suffix might differ on your system. The file must be located in the directory named by the <a class="link" href="server-system-variables.html#sysvar_plugin_dir"> <code class="literal"> plugin_dir </code> </a> system variable. </p> <div class="table"> <a name="idm46045243840224"> </a> <p class="title"> <b> Table 8.27 Plugin and Library Names for Test Authentication </b> </p> <div class="table-contents"> <table summary="Names for the plugins and library file used for test password authentication."> <colgroup> <col style="width: 30%"/> <col style="width: 70%"/> </colgroup> <thead> <tr> <th> Plugin or File </th> <th> Plugin or File Name </th> </tr> </thead> <tbody> <tr> <td> Server-side plugin </td> <td> <code class="literal"> test_plugin_server </code> </td> </tr> <tr> <td> Client-side plugin </td> <td> <code class="literal"> auth_test_plugin </code> </td> </tr> <tr> <td> Library file </td> <td> <code class="filename"> auth_test_plugin.so </code> </td> </tr> </tbody> </table> </div> </div> <br class="table-break"/> <p> The following sections provide installation and usage information specific to test pluggable authentication: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="test-pluggable-authentication.html#test-pluggable-authentication-installation" title="Installing Test Pluggable Authentication"> Installing Test Pluggable Authentication </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="test-pluggable-authentication.html#test-pluggable-authentication-uninstallation" title="Uninstalling Test Pluggable Authentication"> Uninstalling Test Pluggable Authentication </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="test-pluggable-authentication.html#test-pluggable-authentication-usage" title="Using Test Pluggable Authentication"> Using Test Pluggable Authentication </a> </p> </li> </ul> </div> <p> For general information about pluggable authentication in MySQL, see <a class="xref" href="pluggable-authentication.html" title="8.2.17 Pluggable Authentication"> Section 8.2.17, “Pluggable Authentication” </a> . </p> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="test-pluggable-authentication-installation"> </a> Installing Test Pluggable Authentication </h5> </div> </div> </div> <p> This section describes how to install the server-side test authentication plugin. For general information about installing plugins, see <a class="xref" href="plugin-loading.html" title="7.6.1 Installing and Uninstalling Plugins"> Section 7.6.1, “Installing and Uninstalling Plugins” </a> . </p> <p> To be usable by the server, the plugin library file must be located in the MySQL plugin directory (the directory named by the <a class="link" href="server-system-variables.html#sysvar_plugin_dir"> <code class="literal"> plugin_dir </code> </a> system variable). If necessary, configure the plugin directory location by setting the value of <a class="link" href="server-system-variables.html#sysvar_plugin_dir"> <code class="literal"> plugin_dir </code> </a> at server startup. </p> <p> To load the plugin at server startup, use the <a class="link" href="server-options.html#option_mysqld_plugin-load-add"> <code class="option"> --plugin-load-add </code> </a> option to name the library file that contains it. With this plugin-loading method, the option must be given each time the server starts. For example, put these lines in the server <code class="filename"> my.cnf </code> file, adjusting the <code class="filename"> .so </code> suffix for your platform as necessary: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa93798454"><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-ini"><span class="token selector">[mysqld]</span> <span class="token constant">plugin-load-add</span><span class="token attr-value"><span class="token punctuation">=</span>auth_test_plugin.so</span></code></pre> </div> <p> After modifying <code class="filename"> my.cnf </code> , restart the server to cause the new settings to take effect. </p> <p> Alternatively, to load the plugin at runtime, use this statement, adjusting the <code class="filename"> .so </code> suffix for your platform as necessary: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa11745489"><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">INSTALL</span> <span class="token keyword">PLUGIN</span> test_plugin_server <span class="token keyword">SONAME</span> <span class="token string">'auth_test_plugin.so'</span><span class="token punctuation">;</span></code></pre> </div> <p> <a class="link" href="install-plugin.html" title="15.7.4.4 INSTALL PLUGIN Statement"> <code class="literal"> INSTALL PLUGIN </code> </a> loads the plugin immediately, and also registers it in the <code class="literal"> mysql.plugins </code> system table to cause the server to load it for each subsequent normal startup without the need for <a class="link" href="server-options.html#option_mysqld_plugin-load-add"> <code class="option"> --plugin-load-add </code> </a> . </p> <p> To verify plugin installation, examine the Information Schema <a class="link" href="information-schema-plugins-table.html" title="28.3.22 The INFORMATION_SCHEMA PLUGINS Table"> <code class="literal"> PLUGINS </code> </a> table or use the <a class="link" href="show-plugins.html" title="15.7.7.27 SHOW PLUGINS Statement"> <code class="literal"> SHOW PLUGINS </code> </a> statement (see <a class="xref" href="obtaining-plugin-information.html" title="7.6.2 Obtaining Server Plugin Information"> Section 7.6.2, “Obtaining Server Plugin Information” </a> ). For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44337853"><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">SELECT</span> PLUGIN_NAME<span class="token punctuation">,</span> PLUGIN_STATUS <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span><span class="token keyword">PLUGINS</span> <span class="token keyword">WHERE</span> PLUGIN_NAME <span class="token operator">LIKE</span> <span class="token string">'%test_plugin%'</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> <span class="token output"><span class="token punctuation">|</span> PLUGIN_NAME <span class="token punctuation">|</span> PLUGIN_STATUS <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> <span class="token output"><span class="token punctuation">|</span> test_plugin_server <span class="token punctuation">|</span> ACTIVE <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></code></pre> </div> <p> If the plugin fails to initialize, check the server error log for diagnostic messages. </p> <p> To associate MySQL accounts with the test plugin, see <a class="xref" href="test-pluggable-authentication.html#test-pluggable-authentication-usage" title="Using Test Pluggable Authentication"> Using Test Pluggable Authentication </a> . </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="test-pluggable-authentication-uninstallation"> </a> Uninstalling Test Pluggable Authentication </h5> </div> </div> </div> <p> The method used to uninstall the test authentication plugin depends on how you installed it: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If you installed the plugin at server startup using a <a class="link" href="server-options.html#option_mysqld_plugin-load-add"> <code class="option"> --plugin-load-add </code> </a> option, restart the server without the option. </p> </li> <li class="listitem"> <p> If you installed the plugin at runtime using an <a class="link" href="install-plugin.html" title="15.7.4.4 INSTALL PLUGIN Statement"> <code class="literal"> INSTALL PLUGIN </code> </a> statement, it remains installed across server restarts. To uninstall it, use <a class="link" href="uninstall-plugin.html" title="15.7.4.6 UNINSTALL PLUGIN Statement"> <code class="literal"> UNINSTALL PLUGIN </code> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa9991986"><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">UNINSTALL</span> <span class="token keyword">PLUGIN</span> test_plugin_server<span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="test-pluggable-authentication-usage"> </a> Using Test Pluggable Authentication </h5> </div> </div> </div> <p> To use the test authentication plugin, create an account and name that plugin in the <code class="literal"> IDENTIFIED WITH </code> clause: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44256260"><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">'testuser'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> test_plugin_server <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">testpassword</em>'</span><span class="token punctuation">;</span></code></pre> </div> <p> The test authentication plugin also requires creating a proxy user as follows: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa91352052"><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> testpassword<span class="token variable">@localhost</span><span class="token punctuation">;</span> <span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> testpassword<span class="token variable">@localhost</span> <span class="token keyword">TO</span> testuser<span class="token variable">@localhost</span><span class="token punctuation">;</span></code></pre> </div> <p> Then provide the <a class="link" href="connection-options.html#option_general_user"> <code class="option"> --user </code> </a> and <a class="link" href="connection-options.html#option_general_password"> <code class="option"> --password </code> </a> options for that account when you connect to the server. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa55961003"><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 constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>testuser</span> <span class="token property">--password</span> Enter password<span class="token punctuation">:</span> <em class="replaceable">testpassword</em></code></pre> </div> <p> The plugin fetches the password as received from the client and compares it with the value stored in the <code class="literal"> authentication_string </code> column of the account row in the <code class="literal"> mysql.user </code> system table. If the two values match, the plugin returns the <code class="literal"> authentication_string </code> value as the new effective user ID. </p> <p> You can look in the server error log for a message indicating whether authentication succeeded (notice that the password is reported as the <span class="quote"> “ <span class="quote"> user </span> ” </span> ): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa65096543"><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-none">[Note] Plugin test_plugin_server reported: 'successfully authenticated user <em class="replaceable">testpassword</em>'</code></pre> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/innodb-compression-usage.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="innodb-compression-usage"> </a> 17.9.1.2 Creating Compressed Tables </h4> </div> </div> </div> <a class="indexterm" name="idm46045161724704"> </a> <a class="indexterm" name="idm46045161723216"> </a> <a class="indexterm" name="idm46045161722144"> </a> <a class="indexterm" name="idm46045161720656"> </a> <a class="indexterm" name="idm46045161719584"> </a> <p> Compressed tables can be created in <a class="link" href="glossary.html#glos_file_per_table" title="file-per-table"> file-per-table </a> tablespaces or in <a class="link" href="glossary.html#glos_general_tablespace" title="general tablespace"> general tablespaces </a> . Table compression is not available for the InnoDB <a class="link" href="glossary.html#glos_system_tablespace" title="system tablespace"> system tablespace </a> . The system tablespace (space 0, the <a class="link" href="glossary.html#glos_ibd_file" title=".ibd file"> .ibdata files </a> ) can contain user-created tables, but it also contains internal system data, which is never compressed. Thus, compression applies only to tables (and indexes) stored in file-per-table or general tablespaces. </p> <h5> <a name="idm46045161713952"> </a> Creating a Compressed Table in File-Per-Table Tablespace </h5> <p> To create a compressed table in a file-per-table tablespace, <a class="link" href="innodb-parameters.html#sysvar_innodb_file_per_table"> <code class="literal"> innodb_file_per_table </code> </a> must be enabled (the default). You can set this parameter in the MySQL configuration file ( <code class="filename"> my.cnf </code> or <code class="filename"> my.ini </code> ) or dynamically, using a <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment"> <code class="literal"> SET </code> </a> statement. </p> <p> After the <a class="link" href="innodb-parameters.html#sysvar_innodb_file_per_table"> <code class="literal"> innodb_file_per_table </code> </a> option is configured, specify the <code class="literal"> ROW_FORMAT=COMPRESSED </code> clause or <code class="literal"> KEY_BLOCK_SIZE </code> clause, or both, in a <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> or <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement to create a compressed table in a file-per-table tablespace. </p> <p> For example, you might use the following statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65922435"><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">GLOBAL</span> innodb_file_per_table<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1 <span class="token punctuation">(</span>c1 <span class="token datatype">INT</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">)</span> <span class="token keyword">ROW_FORMAT</span><span class="token operator">=</span><span class="token keyword">COMPRESSED</span> <span class="token keyword">KEY_BLOCK_SIZE</span><span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">;</span></code></pre> </div> <h5> <a name="idm46045161701472"> </a> Creating a Compressed Table in a General Tablespace </h5> <p> To create a compressed table in a general tablespace, <code class="literal"> FILE_BLOCK_SIZE </code> must be defined for the general tablespace, which is specified when the tablespace is created. The <code class="literal"> FILE_BLOCK_SIZE </code> value must be a valid compressed page size in relation to the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> value, and the page size of the compressed table, defined by the <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> or <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> <code class="literal"> KEY_BLOCK_SIZE </code> clause, must be equal to <code class="literal"> FILE_BLOCK_SIZE/1024 </code> . For example, if <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size=16384 </code> </a> and <code class="literal"> FILE_BLOCK_SIZE=8192 </code> , the <code class="literal"> KEY_BLOCK_SIZE </code> of the table must be 8. For more information, see <a class="xref" href="general-tablespaces.html" title="17.6.3.3 General Tablespaces"> Section 17.6.3.3, “General Tablespaces” </a> . </p> <p> The following example demonstrates creating a general tablespace and adding a compressed table. The example assumes a default <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> of 16K. The <code class="literal"> FILE_BLOCK_SIZE </code> of 8192 requires that the compressed table have a <code class="literal"> KEY_BLOCK_SIZE </code> of 8. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa5060560"><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">CREATE</span> <span class="token keyword">TABLESPACE</span> <span class="token punctuation">`</span>ts2<span class="token punctuation">`</span> <span class="token keyword">ADD</span> <span class="token keyword">DATAFILE</span> <span class="token string">'ts2.ibd'</span> <span class="token keyword">FILE_BLOCK_SIZE</span> <span class="token operator">=</span> <span class="token number">8192</span> <span class="token keyword">Engine</span><span class="token operator">=</span>InnoDB<span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t4 <span class="token punctuation">(</span>c1 <span class="token datatype">INT</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">)</span> <span class="token keyword">TABLESPACE</span> ts2 <span class="token keyword">ROW_FORMAT</span><span class="token operator">=</span><span class="token keyword">COMPRESSED</span> <span class="token keyword">KEY_BLOCK_SIZE</span><span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">;</span></code></pre> </div> <h5> <a name="idm46045161684320"> </a> Notes </h5> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> As of MySQL 8.4, the tablespace file for a compressed table is created using the physical page size instead of the <code class="literal"> InnoDB </code> page size, which makes the initial size of a tablespace file for an empty compressed table smaller than in previous MySQL releases. </p> </li> <li class="listitem"> <p> If you specify <code class="literal"> ROW_FORMAT=COMPRESSED </code> , you can omit <code class="literal"> KEY_BLOCK_SIZE </code> ; the <code class="literal"> KEY_BLOCK_SIZE </code> setting defaults to half the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> value. </p> </li> <li class="listitem"> <p> If you specify a valid <code class="literal"> KEY_BLOCK_SIZE </code> value, you can omit <code class="literal"> ROW_FORMAT=COMPRESSED </code> ; compression is enabled automatically. </p> </li> <li class="listitem"> <p> To determine the best value for <code class="literal"> KEY_BLOCK_SIZE, </code> typically you create several copies of the same table with different values for this clause, then measure the size of the resulting <code class="filename"> .ibd </code> files and see how well each performs with a realistic <a class="link" href="glossary.html#glos_workload" title="workload"> workload </a> . For general tablespaces, keep in mind that dropping a table does not reduce the size of the general tablespace <code class="filename"> .ibd </code> file, nor does it return disk space to the operating system. For more information, see <a class="xref" href="general-tablespaces.html" title="17.6.3.3 General Tablespaces"> Section 17.6.3.3, “General Tablespaces” </a> . </p> </li> <li class="listitem"> <p> The <code class="literal"> KEY_BLOCK_SIZE </code> value is treated as a hint; a different size could be used by <code class="literal"> InnoDB </code> if necessary. For file-per-table tablespaces, the <code class="literal"> KEY_BLOCK_SIZE </code> can only be less than or equal to the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> value. If you specify a value greater than the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> value, the specified value is ignored, a warning is issued, and <code class="literal"> KEY_BLOCK_SIZE </code> is set to half of the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> value. If <code class="literal"> innodb_strict_mode=ON </code> , specifying an invalid <code class="literal"> KEY_BLOCK_SIZE </code> value returns an error. For general tablespaces, valid <code class="literal"> KEY_BLOCK_SIZE </code> values depend on the <code class="literal"> FILE_BLOCK_SIZE </code> setting of the tablespace. For more information, see <a class="xref" href="general-tablespaces.html" title="17.6.3.3 General Tablespaces"> Section 17.6.3.3, “General Tablespaces” </a> . </p> </li> <li class="listitem"> <p> <code class="literal"> InnoDB </code> supports 32KB and 64KB page sizes but these page sizes do not support compression. For more information, refer to the <a class="link" href="innodb-parameters.html#sysvar_innodb_page_size"> <code class="literal"> innodb_page_size </code> </a> documentation. </p> </li> <li class="listitem"> <p> The default uncompressed size of <code class="literal"> InnoDB </code> data <a class="link" href="glossary.html#glos_page" title="page"> pages </a> is 16KB. Depending on the combination of option values, MySQL uses a page size of 1KB, 2KB, 4KB, 8KB, or 16KB for the tablespace data file ( <code class="filename"> .ibd </code> file). The actual compression algorithm is not affected by the <code class="literal"> KEY_BLOCK_SIZE </code> value; the value determines how large each compressed chunk is, which in turn affects how many rows can be packed into each compressed page. </p> </li> <li class="listitem"> <p> When creating a compressed table in a file-per-table tablespace, setting <code class="literal"> KEY_BLOCK_SIZE </code> equal to the <code class="literal"> InnoDB </code> <a class="link" href="glossary.html#glos_page_size" title="page size"> page size </a> does not typically result in much compression. For example, setting <code class="literal"> KEY_BLOCK_SIZE=16 </code> typically would not result in much compression, since the normal <code class="literal"> InnoDB </code> page size is 16KB. This setting may still be useful for tables with many long <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> , <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> or <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> columns, because such values often do compress well, and might therefore require fewer <a class="link" href="glossary.html#glos_overflow_page" title="overflow page"> overflow pages </a> as described in <a class="xref" href="innodb-compression-internals.html" title="17.9.1.5 How Compression Works for InnoDB Tables"> Section 17.9.1.5, “How Compression Works for InnoDB Tables” </a> . For general tablespaces, a <code class="literal"> KEY_BLOCK_SIZE </code> value equal to the <code class="literal"> InnoDB </code> page size is not permitted. For more information, see <a class="xref" href="general-tablespaces.html" title="17.6.3.3 General Tablespaces"> Section 17.6.3.3, “General Tablespaces” </a> . </p> </li> <li class="listitem"> <p> All indexes of a table (including the <a class="link" href="glossary.html#glos_clustered_index" title="clustered index"> clustered index </a> ) are compressed using the same page size, as specified in the <code class="literal"> CREATE TABLE </code> or <code class="literal"> ALTER TABLE </code> statement. Table attributes such as <code class="literal"> ROW_FORMAT </code> and <code class="literal"> KEY_BLOCK_SIZE </code> are not part of the <code class="literal"> CREATE INDEX </code> syntax for <code class="literal"> InnoDB </code> tables, and are ignored if they are specified (although, if specified, they appear in the output of the <a class="link" href="show-create-table.html" title="15.7.7.11 SHOW CREATE TABLE Statement"> <code class="literal"> SHOW CREATE TABLE </code> </a> statement). </p> </li> <li class="listitem"> <p> For performance-related configuration options, see <a class="xref" href="innodb-compression-tuning.html" title="17.9.1.3 Tuning Compression for InnoDB Tables"> Section 17.9.1.3, “Tuning Compression for InnoDB Tables” </a> . </p> </li> </ul> </div> <h5> <a name="idm46045161629520"> </a> Restrictions on Compressed Tables </h5> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Compressed tables cannot be stored in the <code class="literal"> InnoDB </code> system tablespace. </p> </li> <li class="listitem"> <p> General tablespaces can contain multiple tables, but compressed and uncompressed tables cannot coexist within the same general tablespace. </p> </li> <li class="listitem"> <p> Compression applies to an entire table and all its associated indexes, not to individual rows, despite the clause name <code class="literal"> ROW_FORMAT </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> InnoDB </code> does not support compressed temporary tables. When <a class="link" href="innodb-parameters.html#sysvar_innodb_strict_mode"> <code class="literal"> innodb_strict_mode </code> </a> is enabled (the default), <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TEMPORARY TABLE </code> </a> returns errors if <code class="literal"> ROW_FORMAT=COMPRESSED </code> or <code class="literal"> KEY_BLOCK_SIZE </code> is specified. If <a class="link" href="innodb-parameters.html#sysvar_innodb_strict_mode"> <code class="literal"> innodb_strict_mode </code> </a> is disabled, warnings are issued and the temporary table is created using a non-compressed row format. The same restrictions apply to <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operations on temporary tables. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/csv-storage-engine.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="csv-storage-engine"> </a> 18.4 The CSV Storage Engine </h2> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="se-csv-repair.html"> 18.4.1 Repairing and Checking CSV Tables </a> </span> </dt> <dt> <span class="section"> <a href="se-csv-limitations.html"> 18.4.2 CSV Limitations </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045147736576"> </a> <a class="indexterm" name="idm46045147735504"> </a> <p> The <code class="literal"> CSV </code> storage engine stores data in text files using comma-separated values format. </p> <p> The <code class="literal"> CSV </code> storage engine is always compiled into the MySQL server. </p> <p> To examine the source for the <code class="literal"> CSV </code> engine, look in the <code class="filename"> storage/csv </code> directory of a MySQL source distribution. </p> <p> When you create a <code class="literal"> CSV </code> table, the server creates a plain text data file having a name that begins with the table name and has a <code class="filename"> .CSV </code> extension. When you store data into the table, the storage engine saves it into the data file in comma-separated values format. </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33649344"><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">CREATE</span> <span class="token keyword">TABLE</span> test <span class="token punctuation">(</span>i <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> c <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> CSV<span class="token punctuation">;</span> <span class="token output">Query OK, 0 rows affected (0.06 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> test <span class="token prompt"> -&gt;</span> <span class="token keyword">VALUES</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">'record one'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">'record two'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token output">Query OK, 2 rows affected (0.05 sec)</span> <span class="token output">Records: 2 Duplicates: 0 Warnings: 0</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> test<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> <span class="token output"><span class="token punctuation">|</span> i <span class="token punctuation">|</span> c <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> record one <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> record two <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> <span class="token output">2 rows in set (0.00 sec)</span></code></pre> </div> <p> Creating a <code class="literal"> CSV </code> table also creates a corresponding metafile that stores the state of the table and the number of rows that exist in the table. The name of this file is the same as the name of the table with the extension <code class="filename"> CSM </code> . </p> <p> If you examine the <code class="filename"> test.CSV </code> file in the database directory created by executing the preceding statements, its contents should look like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa79140145"><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-none">"1","record one" "2","record two"</code></pre> </div> <p> This format can be read, and even written, by spreadsheet applications such as Microsoft Excel. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-build-configuration.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="performance-schema-build-configuration"> </a> 29.2 Performance Schema Build Configuration </h2> </div> </div> </div> <p> The Performance Schema is mandatory and always compiled in. It is possible to exclude certain parts of the Performance Schema instrumentation. For example, to exclude stage and statement instrumentation, do this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa33568553"><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">cmake</span> <span class="token punctuation">.</span> \ <span class="token constant">-DDISABLE_PSI_STAGE</span><span class="token attr-value"><span class="token punctuation">=</span>1</span> \ <span class="token constant">-DDISABLE_PSI_STATEMENT</span><span class="token attr-value"><span class="token punctuation">=</span>1</span></code></pre> </div> <p> For more information, see the descriptions of the <code class="literal"> DISABLE_PSI_ <em class="replaceable"> <code> XXX </code> </em> </code> <span class="command"> <strong> CMake </strong> </span> options in <a class="xref" href="source-configuration-options.html" title="2.8.7 MySQL Source-Configuration Options"> Section 2.8.7, “MySQL Source-Configuration Options” </a> . </p> <p> If you install MySQL over a previous installation that was configured without the Performance Schema (or with an older version of the Performance Schema that has missing or out-of-date tables). One indication of this issue is the presence of messages such as the following in the error log: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa56732322"><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-none">[ERROR] Native table 'performance_schema'.'events_waits_history' has the wrong structure [ERROR] Native table 'performance_schema'.'events_waits_history_long' has the wrong structure ...</code></pre> </div> <p> To correct that problem, 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> <p> Because the Performance Schema is configured into the server at build time, a row for <a class="link" href="performance-schema.html" title="Chapter 29 MySQL Performance Schema"> <code class="literal"> PERFORMANCE_SCHEMA </code> </a> appears in the output from <a class="link" href="show-engines.html" title="15.7.7.17 SHOW ENGINES Statement"> <code class="literal"> SHOW ENGINES </code> </a> . This means that the Performance Schema is available, not that it is enabled. To enable it, you must do so at server startup, as described in the next section. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-oci-marketplace-deploy.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="mysql-oci-marketplace-deploy"> </a> 34.2 Deploying MySQL EE on Oracle Cloud Infrastructure </h2> </div> </div> </div> <p> To deploy MySQL EE on Oracle Cloud Infrastructure, do the following: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> Open the OCI Marketplace and search for <span class="guilabel"> MySQL </span> . </p> <p> The <span class="guilabel"> MySQL </span> listings are displayed. </p> </li> <li class="listitem"> <p> Select <span class="guilabel"> MySQL Enterprise Edition </span> . </p> <p> The <span class="guilabel"> MySQL Enterprise Edition </span> overview is displaed. </p> </li> <li class="listitem"> <p> Click <span class="guilabel"> Launch Instance </span> to begin the application launch process. </p> <p> The <span class="guilabel"> Create Compute Instance </span> dialog is displayed. </p> <p> See <a class="ulink" href="https://docs.cloud.oracle.com/iaas/Content/Compute/Tasks/launchinginstance.htm" target="_blank"> To create a Linux instance </a> for information on how to complete the fields. </p> </li> </ol> </div> <p> By default, the MySQL server listens on port 3306 and is configured with a single user, root. </p> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> When the deployment is complete, and the MySQL server is started, you must connect to the compute instance and retrieve the default root password which was written to the MySQL log file. </p> <p> See <a class="xref" href="mysql-oci-marketplace-connecting.html#mysql-oci-marketplace-connecting-ssh" title="Connecting with SSH"> Connecting with SSH </a> for more information. </p> </div> <p> The following MySQL software is installed: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> MySQL Server EE </p> </li> <li class="listitem"> <p> MySQL Enterprise Backup </p> </li> <li class="listitem"> <p> MySQL Shell </p> </li> <li class="listitem"> <p> MySQL Router </p> </li> </ul> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h3 class="title"> <a name="idm46045060103392"> </a> MySQL Configuration </h3> </div> </div> </div> <p> For security, the following are enabled: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> SELinux: for more information, see <a class="ulink" href="https://docs.oracle.com/en/operating-systems/oracle-linux/7/admin/ol7-s1-syssec.html" target="_blank"> Configuring and Using SELinux </a> </p> </li> <li class="listitem"> <p> <code class="filename"> firewalld </code> : for more information, see <a class="ulink" href="https://docs.oracle.com/en/operating-systems/oracle-linux/7/security/ol7-implement-sec.html#ol7-firewalld-cfg" target="_blank"> Controlling the firewalld Firewall Service </a> </p> </li> </ul> </div> <p> The following MySQL plugins are enabled: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="filename"> thread_pool </code> </p> </li> <li class="listitem"> <p> <code class="filename"> validate_password </code> </p> </li> </ul> </div> <p> On startup, the following occurs: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> MySQL Server reads <code class="filename"> /etc/my.cnf </code> and all files named <code class="filename"> <em class="replaceable"> <code> * </code> </em> .cnf </code> in <code class="filename"> /etc/my.cnf.d/ </code> . </p> </li> <li class="listitem"> <p> <code class="filename"> /etc/my.cnf.d/perf-tuning.cnf </code> is created by <code class="filename"> /usr/bin/mkcnf </code> based on the selected OCI shape. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> To disable this mechanism, remove <code class="filename"> /etc/systemd/system/mysqld.service.d/perf-tuning.conf </code> . </p> </div> <p> Performance tuning is configured for the following shapes: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> VM.Standard2.1 </p> </li> <li class="listitem"> <p> VM.Standard2.2 </p> </li> <li class="listitem"> <p> VM.Standard2.4 </p> </li> <li class="listitem"> <p> VM.Standard2.8 </p> </li> <li class="listitem"> <p> VM.Standard2.16 </p> </li> <li class="listitem"> <p> VM.Standard2.24 </p> </li> <li class="listitem"> <p> VM.Standard.E2.1 </p> </li> <li class="listitem"> <p> VM.Standard.E2.2 </p> </li> <li class="listitem"> <p> VM.Standard.E2.4 </p> </li> <li class="listitem"> <p> VM.Standard.E2.8 </p> </li> <li class="listitem"> <p> VM.Standard.E3.Flex </p> </li> <li class="listitem"> <p> VM.Standard.E4.Flex </p> </li> <li class="listitem"> <p> BM.Standard2.52 </p> </li> </ul> </div> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> For all other shapes, the tuning for VM.Standard2.1 is used. </p> </div> </li> </ul> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/identifiers.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="identifiers"> </a> 11.2 Schema Object Names </h2> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="identifier-length.html"> 11.2.1 Identifier Length Limits </a> </span> </dt> <dt> <span class="section"> <a href="identifier-qualifiers.html"> 11.2.2 Identifier Qualifiers </a> </span> </dt> <dt> <span class="section"> <a href="identifier-case-sensitivity.html"> 11.2.3 Identifier Case Sensitivity </a> </span> </dt> <dt> <span class="section"> <a href="identifier-mapping.html"> 11.2.4 Mapping of Identifiers to File Names </a> </span> </dt> <dt> <span class="section"> <a href="function-resolution.html"> 11.2.5 Function Name Parsing and Resolution </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045220079968"> </a> <a class="indexterm" name="idm46045220078896"> </a> <a class="indexterm" name="idm46045220077824"> </a> <a class="indexterm" name="idm46045220076752"> </a> <a class="indexterm" name="idm46045220075264"> </a> <a class="indexterm" name="idm46045220073776"> </a> <a class="indexterm" name="idm46045220072288"> </a> <a class="indexterm" name="idm46045220070800"> </a> <a class="indexterm" name="idm46045220069312"> </a> <p> Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, resource group and other object names are known as identifiers. This section describes the permissible syntax for identifiers in MySQL. <a class="xref" href="identifier-length.html" title="11.2.1 Identifier Length Limits"> Section 11.2.1, “Identifier Length Limits” </a> , indicates the maximum length of each type of identifier. <a class="xref" href="identifier-case-sensitivity.html" title="11.2.3 Identifier Case Sensitivity"> Section 11.2.3, “Identifier Case Sensitivity” </a> , describes which types of identifiers are case-sensitive and under what conditions. </p> <a class="indexterm" name="idm46045220065408"> </a> <a class="indexterm" name="idm46045220063920"> </a> <a class="indexterm" name="idm46045220062848"> </a> <a class="indexterm" name="idm46045220061808"> </a> <p> An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you <span class="emphasis"> <em> must </em> </span> quote it whenever you refer to it. (Exception: A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted.) Reserved words are listed at <a class="xref" href="keywords.html" title="11.3 Keywords and Reserved Words"> Section 11.3, “Keywords and Reserved Words” </a> . </p> <p> Internally, identifiers are converted to and are stored as Unicode (UTF-8). The permissible Unicode characters in identifiers are those in the Basic Multilingual Plane (BMP). Supplementary characters are not permitted. Identifiers thus may contain these characters: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Permitted characters in unquoted identifiers: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore) </p> </li> <li class="listitem"> <p> Extended: U+0080 .. U+FFFF </p> </li> </ul> </div> </li> <li class="listitem"> <p> Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> ASCII: U+0001 .. U+007F </p> </li> <li class="listitem"> <p> Extended: U+0080 .. U+FFFF </p> </li> </ul> </div> </li> <li class="listitem"> <p> ASCII NUL (U+0000) and supplementary characters (U+10000 and higher) are not permitted in quoted or unquoted identifiers. </p> </li> <li class="listitem"> <p> Identifiers may begin with a digit but unless quoted may not consist solely of digits. </p> </li> <li class="listitem"> <p> Database, table, and column names cannot end with space characters. </p> </li> <li class="listitem"> <p> Use of the dollar sign as the first character in the unquoted name of a database, table, view, column, stored program, or alias is deprecated, including such names used with qualifiers (see <a class="xref" href="identifier-qualifiers.html" title="11.2.2 Identifier Qualifiers"> Section 11.2.2, “Identifier Qualifiers” </a> ). An unquoted identifier beginning with a dollar sign cannot contain any additional dollar sign characters. Otherwise, the leading dollar sign is permitted but triggers a deprecation warning. </p> <p> The dollar sign can still be used as the leading character of such an identifier without producing the warning, when it is quoted according to the rules given later in this section. </p> </li> </ul> </div> <p> The identifier quote character is the backtick ( <code class="literal"> ` </code> ): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa37468240"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> <span class="token punctuation">`</span><span class="token keyword">select</span><span class="token punctuation">`</span> <span class="token keyword">WHERE</span> <span class="token punctuation">`</span><span class="token keyword">select</span><span class="token punctuation">`</span><span class="token punctuation">.</span>id <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre> </div> <p> If the <a class="link" href="sql-mode.html#sqlmode_ansi_quotes"> <code class="literal"> ANSI_QUOTES </code> </a> SQL mode is enabled, it is also permissible to quote identifiers within double quotation marks: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21759660"><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">CREATE</span> <span class="token keyword">TABLE</span> <span class="token string">"test"</span> <span class="token punctuation">(</span>col <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token output">ERROR 1064<span class="token punctuation">:</span> You have an error in your SQL syntax...</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> sql_mode<span class="token operator">=</span><span class="token string">'ANSI_QUOTES'</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token string">"test"</span> <span class="token punctuation">(</span>col <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token output">Query OK, 0 rows affected (0.00 sec)</span></code></pre> </div> <p> The <a class="link" href="sql-mode.html#sqlmode_ansi_quotes"> <code class="literal"> ANSI_QUOTES </code> </a> mode causes the server to interpret double-quoted strings as identifiers. Consequently, when this mode is enabled, string literals must be enclosed within single quotation marks. They cannot be enclosed within double quotation marks. The server SQL mode is controlled as described in <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes"> Section 7.1.11, “Server SQL Modes” </a> . </p> <p> Identifier quote characters can be included within an identifier if you quote the identifier. If the character to be included within the identifier is the same as that used to quote the identifier itself, then you need to double the character. The following statement creates a table named <code class="literal"> a`b </code> that contains a column named <code class="literal"> c"d </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa95046516"><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">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>a<span class="token punctuation">`</span><span class="token punctuation">`</span>b<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>c"d<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <a class="indexterm" name="idm46045220032272"> </a> <a class="indexterm" name="idm46045220030784"> </a> <p> In the select list of a query, a quoted column alias can be specified using identifier or string quoting characters: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65397435"><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">SELECT</span> <span class="token number">1</span> <span class="token keyword">AS</span> <span class="token punctuation">`</span><span class="token keyword">one</span><span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token keyword">AS</span> <span class="token string">'two'</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> <span class="token output"><span class="token punctuation">|</span> one <span class="token punctuation">|</span> two <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 2 <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></code></pre> </div> <p> Elsewhere in the statement, quoted references to the alias must use identifier quoting or the reference is treated as a string literal. </p> <p> It is recommended that you do not use names that begin with <code class="literal"> <em class="replaceable"> <code> M </code> </em> e </code> or <code class="literal"> <em class="replaceable"> <code> M </code> </em> e <em class="replaceable"> <code> N </code> </em> </code> , where <em class="replaceable"> <code> M </code> </em> and <em class="replaceable"> <code> N </code> </em> are integers. For example, avoid using <code class="literal"> 1e </code> as an identifier, because an expression such as <code class="literal"> 1e+3 </code> is ambiguous. Depending on context, it might be interpreted as the expression <code class="literal"> 1e + 3 </code> or as the number <code class="literal"> 1e+3 </code> . </p> <p> Be careful when using <a class="link" href="encryption-functions.html#function_md5"> <code class="literal"> MD5() </code> </a> to produce table names because it can produce names in illegal or ambiguous formats such as those just described. </p> <p> It is also recommended that you do not use column names that begin with <code class="literal"> !hidden! </code> to ensure that new names do not collide with names used by existing hidden columns for functional indexes. </p> <p> A user variable cannot be used directly in an SQL statement as an identifier or as part of an identifier. See <a class="xref" href="user-variables.html" title="11.4 User-Defined Variables"> Section 11.4, “User-Defined Variables” </a> , for more information and examples of workarounds. </p> <p> Special characters in database and table names are encoded in the corresponding file system names as described in <a class="xref" href="identifier-mapping.html" title="11.2.4 Mapping of Identifiers to File Names"> Section 11.2.4, “Mapping of Identifiers to File Names” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/group-replication-enterprise-backup.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="group-replication-enterprise-backup"> </a> 20.5.6 Using MySQL Enterprise Backup with Group Replication </h3> </div> </div> </div> <a class="indexterm" name="idm46045132831264"> </a> <a class="indexterm" name="idm46045132829776"> </a> <p> <a class="link" href="mysql-enterprise-backup.html" title="32.1 MySQL Enterprise Backup Overview"> MySQL Enterprise Backup </a> is a commercially-licensed backup utility for MySQL Server, available with <a class="ulink" href="https://www.mysql.com/products/enterprise/" target="_blank"> MySQL Enterprise Edition </a> . This section explains how to back up and subsequently restore a Group Replication member using MySQL Enterprise Backup. The same technique can be used to quickly add a new member to a group. </p> <h4> <a name="idm46045132826080"> </a> Backing up a Group Replication Member Using MySQL Enterprise Backup </h4> <p> Backing up a Group Replication member is similar to backing up a stand-alone MySQL instance. The following instructions assume that you are already familiar with how to use MySQL Enterprise Backup to perform a backup; if that is not the case, please review <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/backing-up.html" target="_top"> Backing Up a Database Server </a> . Also note the requirements described in <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/mysqlbackup.privileges.html" target="_top"> Grant MySQL Privileges to Backup Administrator </a> and <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/meb-group-replication.html" target="_top"> Using MySQL Enterprise Backup with Group Replication </a> . </p> <p> Consider the following group with three members, <code class="literal"> s1 </code> , <code class="literal"> s2 </code> , and <code class="literal"> s3 </code> , running on hosts with the same names: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10563960"><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">SELECT</span> member_host<span class="token punctuation">,</span> member_port<span class="token punctuation">,</span> member_state <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>replication_group_members<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> <span class="token output"><span class="token punctuation">|</span> member_host <span class="token punctuation">|</span> member_port <span class="token punctuation">|</span> member_state <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> <span class="token output"><span class="token punctuation">|</span> s1 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s2 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s3 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <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></code></pre> </div> <p> Using MySQL Enterprise Backup, create a backup of <code class="literal"> s2 </code> by issuing on its host, for example, the following command: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa55389885"><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">s2&gt; mysqlbackup <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>/etc/my.cnf</span> <span class="token constant">--backup-image</span><span class="token attr-value"><span class="token punctuation">=</span>/backups/my.mbi_`date</span> +%d%m_%H%M` \ <span class="token constant">--backup-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/backups/backup_`date</span> +%d%m_%H%M` <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>root</span> <span class="token property">-p</span> \ <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span>127.0.0.1</span> backup-to-image</code></pre> </div> <h4> <a name="group-replication-restore-failed-member"> </a> Restoring a Failed Member </h4> <p> Assume one of the members ( <code class="literal"> s3 </code> in the following example) is irreconcilably corrupted. The most recent backup of group member <code class="literal"> s2 </code> can be used to restore <code class="literal"> s3 </code> . Here are the steps for performing the restore: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> <span class="emphasis"> <em> Copy the backup of s2 onto the host for s3. </em> </span> The exact way to copy the backup depends on the operating system and tools available to you. In this example, we assume the hosts are both Linux servers and use SCP to copy the files between them: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa37970269"><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">s2/backups&gt; scp my<span class="token punctuation">.</span>mbi_2206_1429 s3<span class="token punctuation">:</span>/backups</code></pre> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restore the backup. </em> </span> Connect to the target host (the host for <code class="literal"> s3 </code> in this case), and restore the backup using MySQL Enterprise Backup. Here are the steps: </p> <div class="orderedlist"> <ol class="orderedlist" type="a"> <li class="listitem"> <p> Stop the corrupted server, if it is still running. For example, on Linux distributions that use systemd: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa30376371"><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-simple">s3<span class="token operator">&gt;</span> systemctl stop mysqld</code></pre> </div> </li> <li class="listitem"> <p> Preserve the two configuration files in the corrupted server's data directory, <code class="filename"> auto.cnf </code> and <code class="filename"> mysqld-auto.cnf </code> (if it exists), by copying them to a safe location outside of the data directory. This is for preserving the <a class="link" href="replication-options.html#sysvar_server_uuid"> server's UUID </a> and <a class="xref" href="persisted-system-variables.html" title="7.1.9.3 Persisted System Variables"> Section 7.1.9.3, “Persisted System Variables” </a> (if used), which are needed in the steps below. </p> </li> <li class="listitem"> <p> Delete all contents in the data directory of <code class="literal"> s3 </code> . For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa69151254"><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">s3&gt; rm <span class="token property">-rf</span> /var/lib/mysql/*</code></pre> </div> <p> If the system variables <a class="link" href="innodb-parameters.html#sysvar_innodb_data_home_dir"> <code class="literal"> innodb_data_home_dir </code> </a> , <a class="link" href="innodb-parameters.html#sysvar_innodb_log_group_home_dir"> <code class="literal"> innodb_log_group_home_dir </code> </a> , and <a class="link" href="innodb-parameters.html#sysvar_innodb_undo_directory"> <code class="literal"> innodb_undo_directory </code> </a> point to any directories other than the data directory, they should also be made empty; otherwise, the restore operation fails. </p> </li> <li class="listitem"> <p> Restore backup of <code class="literal"> s2 </code> onto the host for <code class="literal"> s3 </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa65955596"><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">s3&gt; mysqlbackup <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>/etc/my.cnf</span> \ <span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \ <span class="token constant">--backup-image</span><span class="token attr-value"><span class="token punctuation">=</span>/backups/my.mbi_2206_1429</span> \ <span class="token constant">--backup-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/tmp/restore_`date</span> +%d%m_%H%M` copy-back-and-apply-log</code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> The command above assumes that the binary logs and relay logs on <code class="literal"> s2 </code> and <code class="literal"> s3 </code> have the same base name and are at the same location on the two servers. If these conditions are not met, you should use the <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/server-repository-options.html#option_meb_log-bin" target="_top"> <code class="option"> --log-bin </code> </a> and <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/server-repository-options.html#option_meb_relay-log" target="_top"> <code class="option"> --relay-log </code> </a> options to restore the binary log and relay log to their original file paths on <code class="literal"> s3 </code> . For example, if you know that on <code class="literal"> s3 </code> the binary log's base name is <code class="literal"> s3-bin </code> and the relay-log's base name is <code class="literal"> s3-relay-bin </code> , your restore command should look like: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa31323067"><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">mysqlbackup <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>/etc/my.cnf</span> \ <span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \ <span class="token constant">--backup-image</span><span class="token attr-value"><span class="token punctuation">=</span>/backups/my.mbi_2206_1429</span> \ <span class="token constant">--log-bin</span><span class="token attr-value"><span class="token punctuation">=</span>s3-bin</span> <span class="token constant">--relay-log</span><span class="token attr-value"><span class="token punctuation">=</span>s3-relay-bin</span> \ <span class="token constant">--backup-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/tmp/restore_`date</span> +%d%m_%H%M` copy-back-and-apply-log</code></pre> </div> <p> Being able to restore the binary log and relay log to the right file paths makes the restore process easier; if that is impossible for some reason, see <a class="xref" href="group-replication-enterprise-backup.html#group-replication-rebuild-member" title="Rebuild the Failed Member to Rejoin as a New Member"> Rebuild the Failed Member to Rejoin as a New Member </a> . </p> </div> </li> </ol> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restore the <code class="filename"> auto.cnf </code> file for s3. </em> </span> To rejoin the replication group, the restored member <span class="emphasis"> <em> must </em> </span> have the same <a class="link" href="replication-options.html#sysvar_server_uuid"> <code class="literal"> server_uuid </code> </a> it used to join the group before. Supply the old server UUID by copying the <code class="filename"> auto.cnf </code> file preserved in step 2 above into the data directory of the restored member. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If you cannot supply the failed member's original <a class="link" href="replication-options.html#sysvar_server_uuid"> <code class="literal"> server_uuid </code> </a> to the restored member by restoring its old <code class="filename"> auto.cnf </code> file, you must let the restored member join the group as a new member; see instructions in <a class="xref" href="group-replication-enterprise-backup.html#group-replication-rebuild-member" title="Rebuild the Failed Member to Rejoin as a New Member"> Rebuild the Failed Member to Rejoin as a New Member </a> below on how to do that. </p> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restore the <code class="filename"> mysqld-auto.cnf </code> file for s3 (only required if s3 used persistent system variables). </em> </span> The settings for the <a class="xref" href="persisted-system-variables.html" title="7.1.9.3 Persisted System Variables"> Section 7.1.9.3, “Persisted System Variables” </a> that were used to configure the failed member must be provided to the restored member. These settings are to be found in the <code class="filename"> mysqld-auto.cnf </code> file of the failed server, which you should have preserved in step 2 above. Restore the file to the data directory of the restored server. See <a class="xref" href="group-replication-enterprise-backup.html#group-replication-meb-restore-persisted-variables" title="Restoring Persisted System Variables"> Restoring Persisted System Variables </a> on what to do if you do not have a copy of the file. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Start the restored server. </em> </span> For example, on Linux distributions that use systemd: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa87433591"><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">systemctl start mysqld</code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If the server you are restoring is a primary member, perform the steps described in <a class="xref" href="group-replication-enterprise-backup.html#group-replication-meb-restore-primary" title="Restoring a Primary Member"> Restoring a Primary Member </a> <span class="emphasis"> <em> before starting the restored server </em> </span> . </p> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restart Group Replication. </em> </span> Connect to the restarted <code class="literal"> s3 </code> using, for example, a <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, and issue the following statement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa72156766"><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">START</span> <span class="token keyword">GROUP_REPLICATION</span><span class="token punctuation">;</span></code></pre> </div> <p> Before the restored instance can become an online member of the group, it needs to apply any transactions that have happened to the group after the backup was taken; this is achieved using Group Replication's <a class="link" href="group-replication-distributed-recovery.html" title="20.5.4 Distributed Recovery"> distributed recovery </a> mechanism, and the process starts after the <a class="link" href="start-group-replication.html" title="15.4.3.1 START GROUP_REPLICATION Statement"> START GROUP_REPLICATION </a> statement has been issued. To check the member status of the restored instance, issue: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa62306035"><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">SELECT</span> member_host<span class="token punctuation">,</span> member_port<span class="token punctuation">,</span> member_state <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>replication_group_members<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> <span class="token output"><span class="token punctuation">|</span> member_host <span class="token punctuation">|</span> member_port <span class="token punctuation">|</span> member_state <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> <span class="token output"><span class="token punctuation">|</span> s1 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s2 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s3 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> RECOVERING <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></code></pre> </div> <p> This shows that <code class="literal"> s3 </code> is applying transactions to catch up with the group. Once it has caught up with the rest of the group, its <code class="literal"> member_state </code> changes to <code class="literal"> ONLINE </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa12565947"><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">SELECT</span> member_host<span class="token punctuation">,</span> member_port<span class="token punctuation">,</span> member_state <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>replication_group_members<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> <span class="token output"><span class="token punctuation">|</span> member_host <span class="token punctuation">|</span> member_port <span class="token punctuation">|</span> member_state <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> <span class="token output"><span class="token punctuation">|</span> s1 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s2 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s3 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <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></code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If the server you are restoring is a primary member, once it has gained synchrony with the group and become <code class="literal"> ONLINE </code> , perform the steps described at the end of <a class="xref" href="group-replication-enterprise-backup.html#group-replication-meb-restore-primary" title="Restoring a Primary Member"> Restoring a Primary Member </a> to revert the configuration changes you had made to the server before you started it. </p> </div> </li> </ol> </div> <p> The member has now been fully restored from the backup and functions as a regular member of the group. </p> <h4> <a name="group-replication-rebuild-member"> </a> Rebuild the Failed Member to Rejoin as a New Member </h4> <p> Sometimes, the steps outlined above in <a class="xref" href="group-replication-enterprise-backup.html#group-replication-restore-failed-member" title="Restoring a Failed Member"> Restoring a Failed Member </a> cannot be carried out because, for example, the binary log or relay log is corrupted, or it is just missing from the backup. In such a situation, use the backup to rebuild the member, and then add it to the group as a new member. In the steps below, we assume the rebuilt member is named <code class="literal"> s3 </code> , like the failed member, and that it runs on the same host as <code class="literal"> s3 </code> : </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> <span class="emphasis"> <em> Copy the backup of s2 onto the host for s3 . </em> </span> The exact way to copy the backup depends on the operating system and tools available to you. In this example we assume the hosts are both Linux servers and use SCP to copy the files between them: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa34876704"><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">s2/backups&gt; scp my<span class="token punctuation">.</span>mbi_2206_1429 s3<span class="token punctuation">:</span>/backups</code></pre> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restore the backup. </em> </span> Connect to the target host (the host for <code class="literal"> s3 </code> in this case), and restore the backup using MySQL Enterprise Backup. Here are the steps: </p> <div class="orderedlist"> <ol class="orderedlist" type="a"> <li class="listitem"> <p> Stop the corrupted server, if it is still running. For example, on Linux distributions that use systemd: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa12324338"><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-simple">s3<span class="token operator">&gt;</span> systemctl stop mysqld</code></pre> </div> </li> <li class="listitem"> <p> Preserve the configuration file <code class="filename"> mysqld-auto.cnf </code> , if it is found in the corrupted server's data directory, by copying it to a safe location outside of the data directory. This is for preserving the server's <a class="xref" href="persisted-system-variables.html" title="7.1.9.3 Persisted System Variables"> Section 7.1.9.3, “Persisted System Variables” </a> , which are needed later. </p> </li> <li class="listitem"> <p> Delete all contents in the data directory of <code class="literal"> s3 </code> . For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa89115807"><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">s3&gt; rm <span class="token property">-rf</span> /var/lib/mysql/*</code></pre> </div> <p> If the system variables <a class="link" href="innodb-parameters.html#sysvar_innodb_data_home_dir"> <code class="literal"> innodb_data_home_dir </code> </a> , <a class="link" href="innodb-parameters.html#sysvar_innodb_log_group_home_dir"> <code class="literal"> innodb_log_group_home_dir </code> </a> , and <a class="link" href="innodb-parameters.html#sysvar_innodb_undo_directory"> <code class="literal"> innodb_undo_directory </code> </a> point to any directories other than the data directory, they should also be made empty; otherwise, the restore operation fails. </p> </li> <li class="listitem"> <p> Restore the backup of <code class="literal"> s2 </code> onto the host of <code class="literal"> s3 </code> . With this approach, we are rebuilding <code class="literal"> <code class="literal"> s3 </code> </code> as a new member, for which we do not need or do not want to use the old binary and relay logs in the backup; therefore, if these logs have been included in your backup, exclude them using the <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/backup-capacity-options.html#option_meb_skip-binlog" target="_top"> <code class="option"> --skip-binlog </code> </a> and <a class="ulink" href="/doc/mysql-enterprise-backup/8.4/en/backup-capacity-options.html#option_meb_skip-relaylog" target="_top"> <code class="option"> --skip-relaylog </code> </a> options: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa73627464"><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">s3&gt; mysqlbackup <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>/etc/my.cnf</span> \ <span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/var/lib/mysql</span> \ <span class="token constant">--backup-image</span><span class="token attr-value"><span class="token punctuation">=</span>/backups/my.mbi_2206_1429</span> \ <span class="token constant">--backup-dir</span><span class="token attr-value"><span class="token punctuation">=</span>/tmp/restore_`date</span> +%d%m_%H%M` \ <span class="token property">--skip-binlog</span> <span class="token property">--skip-relaylog</span> \ copy-back-and-apply-log</code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If you have healthy binary log and relay logs in the backup that you can transfer onto the target host with no issues, you are recommended to follow the easier procedure as described in <a class="xref" href="group-replication-enterprise-backup.html#group-replication-restore-failed-member" title="Restoring a Failed Member"> Restoring a Failed Member </a> above. </p> </div> </li> </ol> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restore the <code class="filename"> mysqld-auto.cnf </code> file for s3 (only required if s3 used persistent system variables). </em> </span> The settings for the <a class="xref" href="persisted-system-variables.html" title="7.1.9.3 Persisted System Variables"> Section 7.1.9.3, “Persisted System Variables” </a> that were used to configure the failed member must be provided to the restored server. These settings are to be found in the <code class="filename"> mysqld-auto.cnf </code> file of the failed server, which you should have preserved in step 2 above. Restore the file to the data directory of the restored server. See <a class="xref" href="group-replication-enterprise-backup.html#group-replication-meb-restore-persisted-variables" title="Restoring Persisted System Variables"> Restoring Persisted System Variables </a> on what to do if you do not have a copy of the file. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Do NOT restore the corrupted server's <code class="filename"> auto.cnf </code> file to the data directory of the new member—when the rebuilt <code class="literal"> s3 </code> joins the group as a new member, it is going to be assigned a new server UUID. </p> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Start the restored server. </em> </span> For example, on Linux distributions that use systemd: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa95482513"><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">systemctl start mysqld</code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If the server you are restoring is a primary member, perform the steps described in <a class="xref" href="group-replication-enterprise-backup.html#group-replication-meb-restore-primary" title="Restoring a Primary Member"> Restoring a Primary Member </a> <span class="emphasis"> <em> before starting the restored server </em> </span> . </p> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Reconfigure the restored member to join Group Replication. </em> </span> Connect to the restored server with a <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 and reset the source and replica information with the following statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34867085"><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">RESET</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token operator">AND</span> GTIDS<span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">RESET</span> <span class="token keyword">REPLICA</span> <span class="token keyword">ALL</span><span class="token punctuation">;</span></code></pre> </div> <p> For the restored server to be able to recover automatically using Group Replication's built-in mechanism for <a class="link" href="group-replication-distributed-recovery.html" title="20.5.4 Distributed Recovery"> distributed recovery </a> , configure the server's <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed"> <code class="literal"> gtid_executed </code> </a> variable. To do this, use the <code class="filename"> backup_gtid_executed.sql </code> file included in the backup of <code class="literal"> s2 </code> , which is usually restored under the restored member's data directory. Disable binary logging, use the <code class="filename"> backup_gtid_executed.sql </code> file to configure <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed"> <code class="literal"> gtid_executed </code> </a> , and then re-enable binary logging by issuing the following statements with your <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: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36626696"><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> SQL_LOG_BIN<span class="token operator">=</span><span class="token keyword">OFF</span><span class="token punctuation">;</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SOURCE</span> <em class="replaceable">datadir</em><span class="token operator">/</span>backup_gtid_executed<span class="token punctuation">.</span><span class="token keyword">sql</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> SQL_LOG_BIN<span class="token operator">=</span><span class="token keyword">ON</span><span class="token punctuation">;</span></code></pre> </div> <p> Then, configure the <a class="link" href="group-replication-user-credentials.html" title="20.2.1.3 User Credentials For Distributed Recovery"> Group Replication user credentials </a> on the member using the SQL statements shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa546456"><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">CHANGE</span> <span class="token keyword">REPLICATION</span> <span class="token keyword">SOURCE</span> <span class="token keyword">TO</span> <span class="token keyword">SOURCE_USER</span><span class="token operator">=</span><span class="token string">'<em class="replaceable">rpl_user</em>'</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">SOURCE_PASSWORD</span><span class="token operator">=</span><span class="token string">'<em class="replaceable">password</em>'</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">'group_replication_recovery'</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Restart Group Replication. </em> </span> Issue the following statement to the restored server with your <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: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa31682683"><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">START</span> <span class="token keyword">GROUP_REPLICATION</span><span class="token punctuation">;</span></code></pre> </div> <p> Before the restored instance can become an online member of the group, it needs to apply any transactions that have happened to the group after the backup was taken; this is achieved using Group Replication's <a class="link" href="group-replication-distributed-recovery.html" title="20.5.4 Distributed Recovery"> distributed recovery </a> mechanism, and the process starts after the <a class="link" href="start-group-replication.html" title="15.4.3.1 START GROUP_REPLICATION Statement"> START GROUP_REPLICATION </a> statement has been issued. To check the member status of the restored instance, issue: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa8444444"><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">SELECT</span> member_host<span class="token punctuation">,</span> member_port<span class="token punctuation">,</span> member_state <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>replication_group_members<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> <span class="token output"><span class="token punctuation">|</span> member_host <span class="token punctuation">|</span> member_port <span class="token punctuation">|</span> member_state <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> <span class="token output"><span class="token punctuation">|</span> s3 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> RECOVERING <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s2 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s1 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <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></code></pre> </div> <p> This shows that <code class="literal"> s3 </code> is applying transactions to catch up with the group. Once it has caught up with the rest of the group, its <code class="literal"> member_state </code> changes to <code class="literal"> ONLINE </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10403582"><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">SELECT</span> member_host<span class="token punctuation">,</span> member_port<span class="token punctuation">,</span> member_state <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>replication_group_members<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> <span class="token output"><span class="token punctuation">|</span> member_host <span class="token punctuation">|</span> member_port <span class="token punctuation">|</span> member_state <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> <span class="token output"><span class="token punctuation">|</span> s3 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s2 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> s1 <span class="token punctuation">|</span> 3306 <span class="token punctuation">|</span> ONLINE <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></code></pre> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If the server you are restoring is a primary member, once it has gained synchrony with the group and become <code class="literal"> ONLINE </code> , perform the steps described at the end of <a class="xref" href="group-replication-enterprise-backup.html#group-replication-meb-restore-primary" title="Restoring a Primary Member"> Restoring a Primary Member </a> to revert the configuration changes you had made to the server before you started it. </p> </div> </li> </ol> </div> <p> The member has now been restored to the group as a new member. </p> <p> <a name="group-replication-meb-restore-persisted-variables"> </a> <b> Restoring Persisted System Variables. </b> <span class="command"> <strong> mysqlbackup </strong> </span> does not provide support for backing up or preserving <a class="xref" href="persisted-system-variables.html" title="7.1.9.3 Persisted System Variables"> Section 7.1.9.3, “Persisted System Variables” </a> —the file <code class="filename"> mysqld-auto.cnf </code> is not included in a backup. To start the restored member with its persisted variable settings, you need to do one of the following: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Preserve a copy of the <code class="filename"> mysqld-auto.cnf </code> file from the corrupted server, and copy it to the restored server's data directory. </p> </li> <li class="listitem"> <p> Copy the <code class="filename"> mysqld-auto.cnf </code> file from another member of the group into the restored server's data directory, if that member has the same persisted system variable settings as the corrupted member. </p> </li> <li class="listitem"> <p> After the restored server is started and before you restart Group Replication, set all the system variables manually to their persisted values through a <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. </p> </li> </ul> </div> <p> <a name="group-replication-meb-restore-primary"> </a> <b> Restoring a Primary Member. </b> If the restored member is a primary in the group, care must be taken to prevent writes to the restored database during the Group Replication distributed recovery process. Depending on how the group is accessed by clients, there is a possibility of DML statements being executed on the restored member once it becomes accessible on the network, prior to the member finishing its catch-up on the activities it has missed while off the group. To avoid this, <span class="emphasis"> <em> before starting the restored server </em> </span> , configure the following system variables in the server option file: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa40131917"><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-ini"><span class="token constant">group_replication_start_on_boot</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span> <span class="token constant">super_read_only</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span> <span class="token constant">event_scheduler</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span></code></pre> </div> <p> These settings ensure that the member becomes read-only at startup, and that the event scheduler is turned off while the member catches up with the group during the distributed recovery process. Adequate error handling must also be provided for on the clients, since they are unable to perform DML operations during this period on the member being restored. </p> <p> Once the restoration process is fully completed and the restored member is synchronized with the rest of the group, you can revert these changes. First, restart the event scheduler using the statement shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa65183805"><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> <span class="token keyword">global</span> event_scheduler<span class="token operator">=</span><span class="token keyword">ON</span><span class="token punctuation">;</span></code></pre> </div> <p> After this, you should set the following system variables in the member's option file, so that they have the necessary values for the next time that the member is started: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa43412420"><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-ini"><span class="token constant">group_replication_start_on_boot</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span> <span class="token constant">super_read_only</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span> <span class="token constant">event_scheduler</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/sys-ps-setup-show-disabled-consumers.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="sys-ps-setup-show-disabled-consumers"> </a> 30.4.4.16 The ps_setup_show_disabled_consumers() Procedure </h4> </div> </div> </div> <a class="indexterm" name="idm46045061360688"> </a> <a class="indexterm" name="idm46045061359168"> </a> <p> Displays all currently disabled Performance Schema consumers. </p> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="sys-ps-setup-show-disabled-consumers-parameters"> </a> Parameters </h5> </div> </div> </div> <p> None. </p> </div> <div class="simplesect"> <div class="titlepage"> <div> <div class="simple"> <h5 class="title"> <a name="sys-ps-setup-show-disabled-consumers-example"> </a> Example </h5> </div> </div> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51239372"><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">CALL</span> sys<span class="token punctuation">.</span>ps_setup_show_disabled_consumers<span class="token punctuation">(</span><span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> disabled_consumers <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> <span class="token output"><span class="token punctuation">|</span> events_stages_current <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_stages_history <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_stages_history_long <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_statements_history <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_statements_history_long <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_transactions_history <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_transactions_history_long <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_waits_current <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_waits_history <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> events_waits_history_long <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></code></pre> </div> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/derived-tables.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="derived-tables"> </a> 15.2.15.8 Derived Tables </h4> </div> </div> </div> <a class="indexterm" name="idm46045179768640"> </a> <a class="indexterm" name="idm46045179767568"> </a> <a class="indexterm" name="idm46045179765664"> </a> <p> This section discusses general characteristics of derived tables. For information about lateral derived tables preceded by the <code class="literal"> LATERAL </code> keyword, see <a class="xref" href="lateral-derived-tables.html" title="15.2.15.9 Lateral Derived Tables"> Section 15.2.15.9, “Lateral Derived Tables” </a> . </p> <p> A derived table is an expression that generates a table within the scope of a query <code class="literal"> FROM </code> clause. For example, a subquery in a <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> statement <code class="literal"> FROM </code> clause is a derived table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa98808507"><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> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span><em class="replaceable">subquery</em><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token keyword">AS</span><span class="token punctuation">]</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre> </div> <p> The <a class="link" href="json-table-functions.html#function_json-table"> <code class="literal"> JSON_TABLE() </code> </a> function generates a table and provides another way to create a derived table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa99731472"><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> <span class="token operator">*</span> <span class="token keyword">FROM</span> <span class="token keyword">JSON_TABLE</span><span class="token punctuation">(</span><em class="replaceable">arg_list</em><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token keyword">AS</span><span class="token punctuation">]</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre> </div> <p> The <code class="literal"> [AS] <em class="replaceable"> <code> tbl_name </code> </em> </code> clause is mandatory because every table in a <code class="literal"> FROM </code> clause must have a name. Any columns in the derived table must have unique names. Alternatively, <em class="replaceable"> <code> tbl_name </code> </em> may be followed by a parenthesized list of names for the derived table columns: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa15777972"><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> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span><em class="replaceable">subquery</em><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token keyword">AS</span><span class="token punctuation">]</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">(</span><em class="replaceable">col_list</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 number of column names must be the same as the number of table columns. </p> <p> For the sake of illustration, assume that you have this table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa14370418"><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">TABLE</span> t1 <span class="token punctuation">(</span>s1 <span class="token datatype">INT</span><span class="token punctuation">,</span> s2 <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> s3 <span class="token datatype">FLOAT</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> </div> <p> Here is how to use a subquery in the <code class="literal"> FROM </code> clause, using the example table: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16086259"><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">INSERT</span> <span class="token keyword">INTO</span> t1 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">'1'</span><span class="token punctuation">,</span><span class="token number">1.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t1 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">'2'</span><span class="token punctuation">,</span><span class="token number">2.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">SELECT</span> sb1<span class="token punctuation">,</span>sb2<span class="token punctuation">,</span>sb3 <span class="token keyword">FROM</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> s1 <span class="token keyword">AS</span> sb1<span class="token punctuation">,</span> s2 <span class="token keyword">AS</span> sb2<span class="token punctuation">,</span> s3<span class="token operator">*</span><span class="token number">2</span> <span class="token keyword">AS</span> sb3 <span class="token keyword">FROM</span> t1<span class="token punctuation">)</span> <span class="token keyword">AS</span> sb <span class="token keyword">WHERE</span> sb1 <span class="token operator">&gt;</span> <span class="token number">1</span><span class="token punctuation">;</span></code></pre> </div> <p> Result: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa26829867"><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-none">+------+------+------+ | sb1 | sb2 | sb3 | +------+------+------+ | 2 | 2 | 4 | +------+------+------+</code></pre> </div> <p> Here is another example: Suppose that you want to know the average of a set of sums for a grouped table. This does not work: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa82399139"><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> <span class="token function">AVG</span><span class="token punctuation">(</span><span class="token function">SUM</span><span class="token punctuation">(</span>column1<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">FROM</span> t1 <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> column1<span class="token punctuation">;</span></code></pre> </div> <p> However, this query provides the desired information: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86667387"><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> <span class="token function">AVG</span><span class="token punctuation">(</span>sum_column1<span class="token punctuation">)</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> <span class="token function">SUM</span><span class="token punctuation">(</span>column1<span class="token punctuation">)</span> <span class="token keyword">AS</span> sum_column1 <span class="token keyword">FROM</span> t1 <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> column1<span class="token punctuation">)</span> <span class="token keyword">AS</span> t1<span class="token punctuation">;</span></code></pre> </div> <p> Notice that the column name used within the subquery ( <code class="literal"> sum_column1 </code> ) is recognized in the outer query. </p> <p> The column names for a derived table come from its select list: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa93620597"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> dt<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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 4 <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 4 <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></code></pre> </div> <p> To provide column names explicitly, follow the derived table name with a parenthesized list of column names: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10167363"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> dt <span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">,</span> d<span class="token punctuation">)</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> <span class="token output"><span class="token punctuation">|</span> a <span class="token punctuation">|</span> b <span class="token punctuation">|</span> c <span class="token punctuation">|</span> d <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> <span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 4 <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></code></pre> </div> <p> A derived table can return a scalar, column, row, or table. </p> <p> Derived tables are subject to these restrictions: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> A derived table cannot contain references to other tables of the same <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> (use a <code class="literal"> LATERAL </code> derived table for that; see <a class="xref" href="lateral-derived-tables.html" title="15.2.15.9 Lateral Derived Tables"> Section 15.2.15.9, “Lateral Derived Tables” </a> ). </p> </li> </ul> </div> <p> The optimizer determines information about derived tables in such a way that <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN </code> </a> does not need to materialize them. See <a class="xref" href="derived-table-optimization.html" title="10.2.2.4 Optimizing Derived Tables, View References, and Common Table Expressions with Merging or Materialization"> Section 10.2.2.4, “Optimizing Derived Tables, View References, and Common Table Expressions with Merging or Materialization” </a> . </p> <p> It is possible under certain circumstances that using <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN SELECT </code> </a> modifies table data. This can occur if the outer query accesses any tables and an inner query invokes a stored function that changes one or more rows of a table. Suppose that there are two tables <code class="literal"> t1 </code> and <code class="literal"> t2 </code> in database <code class="literal"> d1 </code> , and a stored function <code class="literal"> f1 </code> that modifies <code class="literal"> t2 </code> , created as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22767578"><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">DATABASE</span> d1<span class="token punctuation">;</span> <span class="token keyword">USE</span> d1<span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1 <span class="token punctuation">(</span>c1 <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t2 <span class="token punctuation">(</span>c1 <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">CREATE</span> <span class="token keyword">FUNCTION</span> f1<span class="token punctuation">(</span>p1 <span class="token datatype">INT</span><span class="token punctuation">)</span> <span class="token keyword">RETURNS</span> <span class="token datatype">INT</span> <span class="token keyword">BEGIN</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t2 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span>p1<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">RETURN</span> p1<span class="token punctuation">;</span> <span class="token keyword">END</span><span class="token punctuation">;</span></code></pre> </div> <p> Referencing the function directly in an <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN SELECT </code> </a> has no effect on <code class="literal"> t2 </code> , as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16846145"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t2<span class="token punctuation">;</span> <span class="token output">Empty set (0.02 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">EXPLAIN</span> <span class="token keyword">SELECT</span> f1<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</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> id<span class="token punctuation">:</span> 1 select_type<span class="token punctuation">:</span> SIMPLE table<span class="token punctuation">:</span> NULL partitions<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> NULL possible_keys<span class="token punctuation">:</span> NULL key<span class="token punctuation">:</span> NULL key_len<span class="token punctuation">:</span> NULL ref<span class="token punctuation">:</span> NULL rows<span class="token punctuation">:</span> NULL filtered<span class="token punctuation">:</span> NULL Extra<span class="token punctuation">:</span> No tables used </span><span class="token output">1 row in set (0.01 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t2<span class="token punctuation">;</span> <span class="token output">Empty set (0.01 sec)</span></code></pre> </div> <p> This is because the <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> statement did not reference any tables, as can be seen in the <code class="literal"> table </code> and <code class="literal"> Extra </code> columns of the output. This is also true of the following nested <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29875391"><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">EXPLAIN</span> <span class="token keyword">SELECT</span> <span class="token function">NOW</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> a1<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> f1<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> a2\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> id<span class="token punctuation">:</span> 1 select_type<span class="token punctuation">:</span> PRIMARY table<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> NULL possible_keys<span class="token punctuation">:</span> NULL key<span class="token punctuation">:</span> NULL key_len<span class="token punctuation">:</span> NULL ref<span class="token punctuation">:</span> NULL rows<span class="token punctuation">:</span> NULL filtered<span class="token punctuation">:</span> NULL Extra<span class="token punctuation">:</span> No tables used </span><span class="token output">1 row in set, 1 warning (0.00 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</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 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> Level <span class="token punctuation">|</span> Code <span class="token punctuation">|</span> Message <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 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> Note <span class="token punctuation">|</span> 1249 <span class="token punctuation">|</span> Select 2 was reduced during optimization <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span> <span class="token output">1 row in set (0.00 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t2<span class="token punctuation">;</span> <span class="token output">Empty set (0.00 sec)</span></code></pre> </div> <p> However, if the outer <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> references any tables, the optimizer executes the statement in the subquery as well, with the result that <code class="literal"> t2 </code> is modified: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69583569"><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">EXPLAIN</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t1 <span class="token keyword">AS</span> a1<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> f1<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> a2\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> id<span class="token punctuation">:</span> 1 select_type<span class="token punctuation">:</span> PRIMARY table<span class="token punctuation">:</span> &lt;derived2&gt; partitions<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> system possible_keys<span class="token punctuation">:</span> NULL key<span class="token punctuation">:</span> NULL key_len<span class="token punctuation">:</span> NULL ref<span class="token punctuation">:</span> NULL rows<span class="token punctuation">:</span> 1 filtered<span class="token punctuation">:</span> 100.00 Extra<span class="token punctuation">:</span> NULL <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 2. 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> id<span class="token punctuation">:</span> 1 select_type<span class="token punctuation">:</span> PRIMARY table<span class="token punctuation">:</span> a1 partitions<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> ALL possible_keys<span class="token punctuation">:</span> NULL key<span class="token punctuation">:</span> NULL key_len<span class="token punctuation">:</span> NULL ref<span class="token punctuation">:</span> NULL rows<span class="token punctuation">:</span> 1 filtered<span class="token punctuation">:</span> 100.00 Extra<span class="token punctuation">:</span> NULL <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 3. 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> id<span class="token punctuation">:</span> 2 select_type<span class="token punctuation">:</span> DERIVED table<span class="token punctuation">:</span> NULL partitions<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> NULL possible_keys<span class="token punctuation">:</span> NULL key<span class="token punctuation">:</span> NULL key_len<span class="token punctuation">:</span> NULL ref<span class="token punctuation">:</span> NULL rows<span class="token punctuation">:</span> NULL filtered<span class="token punctuation">:</span> NULL Extra<span class="token punctuation">:</span> No tables used </span><span class="token output">3 rows in set (0.00 sec)</span> <span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t2<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> <span class="token output"><span class="token punctuation">|</span> c1 <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> <span class="token output"><span class="token punctuation">|</span> 5 <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> <span class="token output">1 row in set (0.00 sec)</span></code></pre> </div> <p> The derived table optimization can also be employed with many correlated (scalar) subqueries. For more information and examples, see <a class="xref" href="correlated-subqueries.html" title="15.2.15.7 Correlated Subqueries"> Section 15.2.15.7, “Correlated Subqueries” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="alter-table"> </a> 15.1.9 ALTER TABLE Statement </h3> </div> </div> </div> <div class="toc"> <dl class="toc"> <dt> <span class="section"> <a href="alter-table-partition-operations.html"> 15.1.9.1 ALTER TABLE Partition Operations </a> </span> </dt> <dt> <span class="section"> <a href="alter-table-generated-columns.html"> 15.1.9.2 ALTER TABLE and Generated Columns </a> </span> </dt> <dt> <span class="section"> <a href="alter-table-examples.html"> 15.1.9.3 ALTER TABLE Examples </a> </span> </dt> </dl> </div> <a class="indexterm" name="idm46045189579920"> </a> <a class="indexterm" name="idm46045189578848"> </a> <a class="indexterm" name="idm46045189577360"> </a> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70194336"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">[</span><em class="replaceable">alter_option</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">alter_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">partition_options</em><span class="token punctuation">]</span> <em class="replaceable">alter_option</em>: { <em class="replaceable">table_options</em> <span class="token operator">|</span> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">COLUMN</span><span class="token punctuation">]</span> <em class="replaceable">col_name</em> <em class="replaceable">column_definition</em> <span class="token punctuation">[</span><span class="token keyword">FIRST</span> <span class="token operator">|</span> <span class="token keyword">AFTER</span> <em class="replaceable">col_name</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">COLUMN</span><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">col_name</em> <em class="replaceable">column_definition</em><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token keyword">ADD</span> {<span class="token keyword">INDEX</span> <span class="token operator">|</span> <span class="token keyword">KEY</span>} <span class="token punctuation">[</span><em class="replaceable">index_name</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">index_type</em><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">key_part</em><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token punctuation">[</span><em class="replaceable">index_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token operator">|</span> <span class="token keyword">ADD</span> {<span class="token keyword">FULLTEXT</span> <span class="token operator">|</span> <span class="token keyword">SPATIAL</span>} <span class="token punctuation">[</span><span class="token keyword">INDEX</span> <span class="token operator">|</span> <span class="token keyword">KEY</span><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">index_name</em><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">key_part</em><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token punctuation">[</span><em class="replaceable">index_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token operator">|</span> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">CONSTRAINT</span> <span class="token punctuation">[</span><em class="replaceable">symbol</em><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">[</span><em class="replaceable">index_type</em><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">key_part</em><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token punctuation">[</span><em class="replaceable">index_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token operator">|</span> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">CONSTRAINT</span> <span class="token punctuation">[</span><em class="replaceable">symbol</em><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token keyword">UNIQUE</span> <span class="token punctuation">[</span><span class="token keyword">INDEX</span> <span class="token operator">|</span> <span class="token keyword">KEY</span><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">index_name</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">index_type</em><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">key_part</em><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token punctuation">[</span><em class="replaceable">index_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token operator">|</span> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">CONSTRAINT</span> <span class="token punctuation">[</span><em class="replaceable">symbol</em><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">[</span><em class="replaceable">index_name</em><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">col_name</em><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <em class="replaceable">reference_definition</em> <span class="token operator">|</span> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">CONSTRAINT</span> <span class="token punctuation">[</span><em class="replaceable">symbol</em><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token keyword">CHECK</span> <span class="token punctuation">(</span><em class="replaceable">expr</em><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">ENFORCED</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">DROP</span> {<span class="token keyword">CHECK</span> <span class="token operator">|</span> <span class="token keyword">CONSTRAINT</span>} <em class="replaceable">symbol</em> <span class="token operator">|</span> <span class="token keyword">ALTER</span> {<span class="token keyword">CHECK</span> <span class="token operator">|</span> <span class="token keyword">CONSTRAINT</span>} <em class="replaceable">symbol</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">ENFORCED</span> <span class="token operator">|</span> <span class="token keyword">ALGORITHM</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> INSTANT <span class="token operator">|</span> <span class="token keyword">INPLACE</span> <span class="token operator">|</span> <span class="token keyword">COPY</span>} <span class="token operator">|</span> <span class="token keyword">ALTER</span> <span class="token punctuation">[</span><span class="token keyword">COLUMN</span><span class="token punctuation">]</span> <em class="replaceable">col_name</em> { <span class="token keyword">SET</span> <span class="token keyword">DEFAULT</span> {<em class="replaceable">literal</em> <span class="token operator">|</span> <span class="token punctuation">(</span><em class="replaceable">expr</em><span class="token punctuation">)</span>} <span class="token operator">|</span> <span class="token keyword">SET</span> {<span class="token keyword">VISIBLE</span> <span class="token operator">|</span> <span class="token keyword">INVISIBLE</span>} <span class="token operator">|</span> <span class="token keyword">DROP</span> <span class="token keyword">DEFAULT</span> } <span class="token operator">|</span> <span class="token keyword">ALTER</span> <span class="token keyword">INDEX</span> <em class="replaceable">index_name</em> {<span class="token keyword">VISIBLE</span> <span class="token operator">|</span> <span class="token keyword">INVISIBLE</span>} <span class="token operator">|</span> <span class="token keyword">CHANGE</span> <span class="token punctuation">[</span><span class="token keyword">COLUMN</span><span class="token punctuation">]</span> <em class="replaceable">old_col_name</em> <em class="replaceable">new_col_name</em> <em class="replaceable">column_definition</em> <span class="token punctuation">[</span><span class="token keyword">FIRST</span> <span class="token operator">|</span> <span class="token keyword">AFTER</span> <em class="replaceable">col_name</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span><span class="token punctuation">]</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">charset_name</em> <span class="token punctuation">[</span><span class="token keyword">COLLATE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">collation_name</em><span class="token punctuation">]</span> <span class="token operator">|</span> CONVERT <span class="token keyword">TO</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <em class="replaceable">charset_name</em> <span class="token punctuation">[</span><span class="token keyword">COLLATE</span> <em class="replaceable">collation_name</em><span class="token punctuation">]</span> <span class="token operator">|</span> {<span class="token keyword">DISABLE</span> <span class="token operator">|</span> <span class="token keyword">ENABLE</span>} <span class="token keyword">KEYS</span> <span class="token operator">|</span> {<span class="token keyword">DISCARD</span> <span class="token operator">|</span> <span class="token keyword">IMPORT</span>} <span class="token keyword">TABLESPACE</span> <span class="token operator">|</span> <span class="token keyword">DROP</span> <span class="token punctuation">[</span><span class="token keyword">COLUMN</span><span class="token punctuation">]</span> <em class="replaceable">col_name</em> <span class="token operator">|</span> <span class="token keyword">DROP</span> {<span class="token keyword">INDEX</span> <span class="token operator">|</span> <span class="token keyword">KEY</span>} <em class="replaceable">index_name</em> <span class="token operator">|</span> <span class="token keyword">DROP</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token operator">|</span> <span class="token keyword">DROP</span> <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <em class="replaceable">fk_symbol</em> <span class="token operator">|</span> <span class="token keyword">FORCE</span> <span class="token operator">|</span> <span class="token keyword">LOCK</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <span class="token keyword">NONE</span> <span class="token operator">|</span> <span class="token keyword">SHARED</span> <span class="token operator">|</span> <span class="token keyword">EXCLUSIVE</span>} <span class="token operator">|</span> <span class="token keyword">MODIFY</span> <span class="token punctuation">[</span><span class="token keyword">COLUMN</span><span class="token punctuation">]</span> <em class="replaceable">col_name</em> <em class="replaceable">column_definition</em> <span class="token punctuation">[</span><span class="token keyword">FIRST</span> <span class="token operator">|</span> <span class="token keyword">AFTER</span> <em class="replaceable">col_name</em><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> <em class="replaceable">col_name</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">col_name</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token operator">|</span> <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> <em class="replaceable">old_col_name</em> <span class="token keyword">TO</span> <em class="replaceable">new_col_name</em> <span class="token operator">|</span> <span class="token keyword">RENAME</span> {<span class="token keyword">INDEX</span> <span class="token operator">|</span> <span class="token keyword">KEY</span>} <em class="replaceable">old_index_name</em> <span class="token keyword">TO</span> <em class="replaceable">new_index_name</em> <span class="token operator">|</span> <span class="token keyword">RENAME</span> <span class="token punctuation">[</span><span class="token keyword">TO</span> <span class="token operator">|</span> <span class="token keyword">AS</span><span class="token punctuation">]</span> <em class="replaceable">new_tbl_name</em> <span class="token operator">|</span> {<span class="token keyword">WITHOUT</span> <span class="token operator">|</span> <span class="token keyword">WITH</span>} <span class="token keyword">VALIDATION</span> } <em class="replaceable">partition_options</em>: <em class="replaceable">partition_option</em> <span class="token punctuation">[</span><em class="replaceable">partition_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <em class="replaceable">partition_option</em>: { <span class="token keyword">ADD</span> <span class="token keyword">PARTITION</span> <span class="token punctuation">(</span><em class="replaceable">partition_definition</em><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token keyword">DROP</span> <span class="token keyword">PARTITION</span> <em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">DISCARD</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token keyword">TABLESPACE</span> <span class="token operator">|</span> <span class="token keyword">IMPORT</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token keyword">TABLESPACE</span> <span class="token operator">|</span> <span class="token keyword">TRUNCATE</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token operator">|</span> <span class="token keyword">COALESCE</span> <span class="token keyword">PARTITION</span> <span class="token keyword"><em class="replaceable">number</em></span> <span class="token operator">|</span> <span class="token keyword">REORGANIZE</span> <span class="token keyword">PARTITION</span> <em class="replaceable">partition_names</em> <span class="token keyword">INTO</span> <span class="token punctuation">(</span><em class="replaceable">partition_definitions</em><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token keyword">EXCHANGE</span> <span class="token keyword">PARTITION</span> <em class="replaceable">partition_name</em> <span class="token keyword">WITH</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">[</span>{<span class="token keyword">WITH</span> <span class="token operator">|</span> <span class="token keyword">WITHOUT</span>} <span class="token keyword">VALIDATION</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">ANALYZE</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token operator">|</span> <span class="token keyword">CHECK</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token operator">|</span> <span class="token keyword">OPTIMIZE</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token operator">|</span> <span class="token keyword">REBUILD</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token operator">|</span> <span class="token keyword">REPAIR</span> <span class="token keyword">PARTITION</span> {<em class="replaceable">partition_names</em> <span class="token operator">|</span> <span class="token keyword">ALL</span>} <span class="token operator">|</span> <span class="token keyword">REMOVE</span> <span class="token keyword">PARTITIONING</span> } <em class="replaceable">key_part</em>: {<em class="replaceable">col_name</em> <span class="token punctuation">[</span><span class="token punctuation">(</span><em class="replaceable">length</em><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token punctuation">(</span><em class="replaceable">expr</em><span class="token punctuation">)</span>} <span class="token punctuation">[</span><span class="token keyword">ASC</span> <span class="token operator">|</span> <span class="token keyword">DESC</span><span class="token punctuation">]</span> <em class="replaceable">index_type</em>: <span class="token keyword">USING</span> {<span class="token keyword">BTREE</span> <span class="token operator">|</span> <span class="token keyword">HASH</span>} <em class="replaceable">index_option</em>: { <span class="token keyword">KEY_BLOCK_SIZE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <em class="replaceable">index_type</em> <span class="token operator">|</span> <span class="token keyword">WITH</span> <span class="token keyword">PARSER</span> <em class="replaceable">parser_name</em> <span class="token operator">|</span> <span class="token keyword">COMMENT</span> <span class="token string">'<em class="replaceable">string</em>'</span> <span class="token operator">|</span> {<span class="token keyword">VISIBLE</span> <span class="token operator">|</span> <span class="token keyword">INVISIBLE</span>} } <em class="replaceable">table_options</em>: <em class="replaceable">table_option</em> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token punctuation">,</span><span class="token punctuation">]</span> <em class="replaceable">table_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <em class="replaceable">table_option</em>: { <span class="token keyword">AUTOEXTEND_SIZE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token keyword">AVG_ROW_LENGTH</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span><span class="token punctuation">]</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">charset_name</em> <span class="token operator">|</span> <span class="token keyword">CHECKSUM</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token number">0</span> <span class="token operator">|</span> <span class="token number">1</span>} <span class="token operator">|</span> <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span><span class="token punctuation">]</span> <span class="token keyword">COLLATE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">collation_name</em> <span class="token operator">|</span> <span class="token keyword">COMMENT</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token string">'<em class="replaceable">string</em>'</span> <span class="token operator">|</span> <span class="token keyword">COMPRESSION</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token string">'ZLIB'</span> <span class="token operator">|</span> <span class="token string">'LZ4'</span> <span class="token operator">|</span> <span class="token string">'NONE'</span>} <span class="token operator">|</span> <span class="token keyword">CONNECTION</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token string">'<em class="replaceable">connect_string</em>'</span> <span class="token operator">|</span> {<span class="token keyword">DATA</span> <span class="token operator">|</span> <span class="token keyword">INDEX</span>} <span class="token keyword">DIRECTORY</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token string">'<em class="replaceable">absolute path to directory</em>'</span> <span class="token operator">|</span> <span class="token keyword">DELAY_KEY_WRITE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token number">0</span> <span class="token operator">|</span> <span class="token number">1</span>} <span class="token operator">|</span> <span class="token keyword">ENCRYPTION</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token string">'Y'</span> <span class="token operator">|</span> <span class="token string">'N'</span>} <span class="token operator">|</span> <span class="token keyword">ENGINE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">engine_name</em> <span class="token operator">|</span> <span class="token keyword">ENGINE_ATTRIBUTE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token string">'<em class="replaceable">string</em>'</span> <span class="token operator">|</span> <span class="token keyword">INSERT_METHOD</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> { <span class="token keyword">NO</span> <span class="token operator">|</span> <span class="token keyword">FIRST</span> <span class="token operator">|</span> <span class="token keyword">LAST</span> } <span class="token operator">|</span> <span class="token keyword">KEY_BLOCK_SIZE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token keyword">MAX_ROWS</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token keyword">MIN_ROWS</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token keyword">PACK_KEYS</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token number">0</span> <span class="token operator">|</span> <span class="token number">1</span> <span class="token operator">|</span> <span class="token keyword">DEFAULT</span>} <span class="token operator">|</span> <span class="token keyword">PASSWORD</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token string">'<em class="replaceable">string</em>'</span> <span class="token operator">|</span> <span class="token keyword">ROW_FORMAT</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <span class="token keyword">DYNAMIC</span> <span class="token operator">|</span> <span class="token keyword">FIXED</span> <span class="token operator">|</span> <span class="token keyword">COMPRESSED</span> <span class="token operator">|</span> <span class="token keyword">REDUNDANT</span> <span class="token operator">|</span> <span class="token keyword">COMPACT</span>} <span class="token operator">|</span> <span class="token keyword">SECONDARY_ENGINE_ATTRIBUTE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token string">'<em class="replaceable">string</em>'</span> <span class="token operator">|</span> <span class="token keyword">STATS_AUTO_RECALC</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <span class="token number">0</span> <span class="token operator">|</span> <span class="token number">1</span>} <span class="token operator">|</span> <span class="token keyword">STATS_PERSISTENT</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token keyword">DEFAULT</span> <span class="token operator">|</span> <span class="token number">0</span> <span class="token operator">|</span> <span class="token number">1</span>} <span class="token operator">|</span> <span class="token keyword">STATS_SAMPLE_PAGES</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">value</em></span> <span class="token operator">|</span> <span class="token keyword">TABLESPACE</span> <em class="replaceable">tablespace_name</em> <span class="token punctuation">[</span><span class="token keyword">STORAGE</span> {<span class="token keyword">DISK</span> <span class="token operator">|</span> <span class="token keyword">MEMORY</span>}<span class="token punctuation">]</span> <span class="token operator">|</span> <span class="token keyword">UNION</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <span class="token punctuation">(</span><em class="replaceable">tbl_name</em><span class="token punctuation">[</span><span class="token punctuation">,</span><em class="replaceable">tbl_name</em><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> } <em class="replaceable">partition_options</em>: <span class="token punctuation">(</span>see <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token keyword">options</span><span class="token punctuation">)</span></code></pre> </div> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> changes the structure of a table. For example, you can add or delete columns, create or destroy indexes, change the type of existing columns, or rename columns or the table itself. You can also change characteristics such as the storage engine used for the table or the table comment. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> To use <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> , you need <a class="link" href="privileges-provided.html#priv_alter"> <code class="literal"> ALTER </code> </a> , <a class="link" href="privileges-provided.html#priv_create"> <code class="literal"> CREATE </code> </a> , and <a class="link" href="privileges-provided.html#priv_insert"> <code class="literal"> INSERT </code> </a> privileges for the table. Renaming a table requires <a class="link" href="privileges-provided.html#priv_alter"> <code class="literal"> ALTER </code> </a> and <a class="link" href="privileges-provided.html#priv_drop"> <code class="literal"> DROP </code> </a> on the old table, <a class="link" href="privileges-provided.html#priv_alter"> <code class="literal"> ALTER </code> </a> , <a class="link" href="privileges-provided.html#priv_create"> <code class="literal"> CREATE </code> </a> , and <a class="link" href="privileges-provided.html#priv_insert"> <code class="literal"> INSERT </code> </a> on the new table. </p> </li> <li class="listitem"> <p> Following the table name, specify the alterations to be made. If none are given, <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> does nothing. </p> </li> <li class="listitem"> <p> The syntax for many of the permissible alterations is similar to clauses of the <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> statement. <em class="replaceable"> <code> column_definition </code> </em> clauses use the same syntax for <code class="literal"> ADD </code> and <code class="literal"> CHANGE </code> as for <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> . For more information, see <a class="xref" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> Section 15.1.20, “CREATE TABLE Statement” </a> . </p> </li> <li class="listitem"> <p> The word <code class="literal"> COLUMN </code> is optional and can be omitted, except for <code class="literal"> RENAME COLUMN </code> (to distinguish a column-renaming operation from the <code class="literal"> RENAME </code> table-renaming operation). </p> </li> <li class="listitem"> <p> Multiple <code class="literal"> ADD </code> , <code class="literal"> ALTER </code> , <code class="literal"> DROP </code> , and <code class="literal"> CHANGE </code> clauses are permitted in a single <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement, separated by commas. This is a MySQL extension to standard SQL, which permits only one of each clause per <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement. For example, to drop multiple columns in a single statement, do this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa72565496"><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">ALTER</span> <span class="token keyword">TABLE</span> t2 <span class="token keyword">DROP</span> <span class="token keyword">COLUMN</span> c<span class="token punctuation">,</span> <span class="token keyword">DROP</span> <span class="token keyword">COLUMN</span> d<span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> If a storage engine does not support an attempted <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation, a warning may result. Such warnings can be displayed with <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement"> <code class="literal"> SHOW WARNINGS </code> </a> . See <a class="xref" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement"> Section 15.7.7.42, “SHOW WARNINGS Statement” </a> . For information on troubleshooting <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> , see <a class="xref" href="alter-table-problems.html" title="B.3.6.1 Problems with ALTER TABLE"> Section B.3.6.1, “Problems with ALTER TABLE” </a> . </p> </li> <li class="listitem"> <p> For information about generated columns, see <a class="xref" href="alter-table-generated-columns.html" title="15.1.9.2 ALTER TABLE and Generated Columns"> Section 15.1.9.2, “ALTER TABLE and Generated Columns” </a> . </p> </li> <li class="listitem"> <p> For usage examples, see <a class="xref" href="alter-table-examples.html" title="15.1.9.3 ALTER TABLE Examples"> Section 15.1.9.3, “ALTER TABLE Examples” </a> . </p> </li> <li class="listitem"> <p> <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine"> <code class="literal"> InnoDB </code> </a> supports addition of multi-valued indexes on JSON columns using a <em class="replaceable"> <code> key_part </code> </em> specification can take the form <code class="literal"> (CAST <em class="replaceable"> <code> json_path </code> </em> AS <em class="replaceable"> <code> type </code> </em> ARRAY) </code> . See <a class="xref" href="create-index.html#create-index-multi-valued" title="Multi-Valued Indexes"> Multi-Valued Indexes </a> , for detailed information regarding multi-valued index creation and usage of, as well as restrictions and limitations on multi-valued indexes. </p> </li> <li class="listitem"> <p> With the <a class="ulink" href="/doc/c-api/8.4/en/mysql-info.html" target="_top"> <code class="literal"> mysql_info() </code> </a> C API function, you can find out how many rows were copied by <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> . See <a class="ulink" href="/doc/c-api/8.4/en/mysql-info.html" target="_top"> mysql_info() </a> . </p> <a class="indexterm" name="idm46045189467616"> </a> </li> </ul> </div> <p> There are several additional aspects to the <code class="literal"> ALTER TABLE </code> statement, described under the following topics in this section: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-options" title="Table Options"> Table Options </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-performance" title="Performance and Space Requirements"> Performance and Space Requirements </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-concurrency" title="Concurrency Control"> Concurrency Control </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-add-drop-column" title="Adding and Dropping Columns"> Adding and Dropping Columns </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-redefine-column" title="Renaming, Redefining, and Reordering Columns"> Renaming, Redefining, and Reordering Columns </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-index" title="Primary Keys and Indexes"> Primary Keys and Indexes </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-foreign-key" title="Foreign Keys and Other Constraints"> Foreign Keys and Other Constraints </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-character-set" title="Changing the Character Set"> Changing the Character Set </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-import" title="Importing InnoDB Tables"> Importing InnoDB Tables </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-row-order" title="Row Order for MyISAM Tables"> Row Order for MyISAM Tables </a> </p> </li> <li class="listitem"> <p> <a class="xref" href="alter-table.html#alter-table-partition-options" title="Partitioning Options"> Partitioning Options </a> </p> </li> </ul> </div> <h4> <a name="alter-table-options"> </a> Table Options </h4> <p> <em class="replaceable"> <code> table_options </code> </em> signifies table options of the kind that can be used in the <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> statement, such as <code class="literal"> ENGINE </code> , <code class="literal"> AUTO_INCREMENT </code> , <code class="literal"> AVG_ROW_LENGTH </code> , <code class="literal"> MAX_ROWS </code> , <code class="literal"> ROW_FORMAT </code> , or <code class="literal"> TABLESPACE </code> . </p> <p> For descriptions of all table options, see <a class="xref" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> Section 15.1.20, “CREATE TABLE Statement” </a> . However, <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> ignores <code class="literal"> DATA DIRECTORY </code> and <code class="literal"> INDEX DIRECTORY </code> when given as table options. <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> permits them only as partitioning options, and requires that you have the <code class="literal"> FILE </code> privilege. </p> <p> Use of table options with <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> provides a convenient way of altering single table characteristics. For example: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> If <code class="literal"> t1 </code> is currently not an <code class="literal"> InnoDB </code> table, this statement changes its storage engine to <code class="literal"> InnoDB </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa3578747"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">ENGINE</span> <span class="token operator">=</span> InnoDB<span class="token punctuation">;</span></code></pre> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> See <a class="xref" href="converting-tables-to-innodb.html" title="17.6.1.5 Converting Tables from MyISAM to InnoDB"> Section 17.6.1.5, “Converting Tables from MyISAM to InnoDB” </a> for considerations when switching tables to the <code class="literal"> InnoDB </code> storage engine. </p> </li> <li class="listitem"> <p> When you specify an <code class="literal"> ENGINE </code> clause, <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> rebuilds the table. This is true even if the table already has the specified storage engine. </p> </li> <li class="listitem"> <p> Running <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE <em class="replaceable"> <code> tbl_name </code> </em> ENGINE=INNODB </code> </a> on an existing <code class="literal"> InnoDB </code> table performs a <span class="quote"> “ <span class="quote"> null </span> ” </span> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation, which can be used to defragment an <code class="literal"> InnoDB </code> table, as described in <a class="xref" href="innodb-file-defragmenting.html" title="17.11.4 Defragmenting a Table"> Section 17.11.4, “Defragmenting a Table” </a> . Running <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE <em class="replaceable"> <code> tbl_name </code> </em> FORCE </code> </a> on an <code class="literal"> InnoDB </code> table performs the same function. </p> </li> <li class="listitem"> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE <em class="replaceable"> <code> tbl_name </code> </em> ENGINE=INNODB </code> </a> and <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE <em class="replaceable"> <code> tbl_name </code> </em> FORCE </code> </a> use <a class="link" href="innodb-online-ddl.html" title="17.12 InnoDB and Online DDL"> online DDL </a> . For more information, see <a class="xref" href="innodb-online-ddl.html" title="17.12 InnoDB and Online DDL"> Section 17.12, “InnoDB and Online DDL” </a> . </p> </li> <li class="listitem"> <p> The outcome of attempting to change the storage engine of a table is affected by whether the desired storage engine is available and the setting of the <a class="link" href="sql-mode.html#sqlmode_no_engine_substitution"> <code class="literal"> NO_ENGINE_SUBSTITUTION </code> </a> SQL mode, as described in <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes"> Section 7.1.11, “Server SQL Modes” </a> . </p> </li> <li class="listitem"> <p> To prevent inadvertent loss of data, <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> cannot be used to change the storage engine of a table to <code class="literal"> MERGE </code> or <code class="literal"> BLACKHOLE </code> . </p> </li> </ul> </div> </li> <li class="listitem"> <p> To change the <code class="literal"> InnoDB </code> table to use compressed row-storage format: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa79985828"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">ROW_FORMAT</span> <span class="token operator">=</span> <span class="token keyword">COMPRESSED</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> The <code class="literal"> ENCRYPTION </code> clause enables or disables page-level data encryption for an <code class="literal"> InnoDB </code> table. A keyring plugin must be installed and configured to enable encryption. </p> <p> If the <a class="link" href="server-system-variables.html#sysvar_table_encryption_privilege_check"> <code class="literal"> table_encryption_privilege_check </code> </a> variable is enabled, the <a class="link" href="privileges-provided.html#priv_table-encryption-admin"> <code class="literal"> TABLE_ENCRYPTION_ADMIN </code> </a> privilege is required to use an <code class="literal"> ENCRYPTION </code> clause with a setting that differs from the default schema encryption setting. </p> <p> <code class="literal"> ENCRYPTION </code> is also supported for tables residing in general tablespaces. </p> <p> For tables that reside in general tablespaces, table and tablespace encryption must match. </p> <p> The <code class="literal"> ENCRYPTION </code> option is supported only by the <code class="literal"> InnoDB </code> storage engine; thus it works only if the table already uses <code class="literal"> InnoDB </code> (and you do not change the table's storage engine), or if the <code class="literal"> ALTER TABLE </code> statement also specifies <code class="literal"> ENGINE=InnoDB </code> . Otherwise the statement is rejected with <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_check_not_implemented" target="_top"> <code class="literal"> ER_CHECK_NOT_IMPLEMENTED </code> </a> . </p> <p> Altering table encryption by moving a table to a different tablespace or changing the storage engine is not permitted without explicitly specifying an <code class="literal"> ENCRYPTION </code> clause. </p> <p> Specifying an <code class="literal"> ENCRYPTION </code> clause with a value other than <code class="literal"> 'N' </code> or <code class="literal"> '' </code> is not permitted if the table uses a storage engine that does not support encryption. Attempting to create a table without an <code class="literal"> ENCRYPTION </code> clause in an encryption-enabled schema using a storage engine that does not support encryption is also not permitted. </p> <p> For more information, see <a class="xref" href="innodb-data-encryption.html" title="17.13 InnoDB Data-at-Rest Encryption"> Section 17.13, “InnoDB Data-at-Rest Encryption” </a> . </p> </li> <li class="listitem"> <p> To reset the current auto-increment value: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa50932411"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">AUTO_INCREMENT</span> <span class="token operator">=</span> <span class="token number">13</span><span class="token punctuation">;</span></code></pre> </div> <p> You cannot reset the counter to a value less than or equal to the value that is currently in use. For both <code class="literal"> InnoDB </code> and <code class="literal"> MyISAM </code> , if the value is less than or equal to the maximum value currently in the <code class="literal"> AUTO_INCREMENT </code> column, the value is reset to the current maximum <code class="literal"> AUTO_INCREMENT </code> column value plus one. </p> </li> <li class="listitem"> <p> To change the default table character set: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa77478368"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token operator">=</span> utf8mb4<span class="token punctuation">;</span></code></pre> </div> <p> See also <a class="xref" href="alter-table.html#alter-table-character-set" title="Changing the Character Set"> Changing the Character Set </a> . </p> </li> <li class="listitem"> <p> To add (or change) a table comment: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa1024643"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'New table comment'</span><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> Use <code class="literal"> ALTER TABLE </code> with the <code class="literal"> TABLESPACE </code> option to move <code class="literal"> InnoDB </code> tables between existing <a class="link" href="glossary.html#glos_general_tablespace" title="general tablespace"> general tablespaces </a> , <a class="link" href="glossary.html#glos_file_per_table" title="file-per-table"> file-per-table </a> tablespaces, and the <a class="link" href="glossary.html#glos_system_tablespace" title="system tablespace"> system tablespace </a> . See <a class="xref" href="general-tablespaces.html#general-tablespaces-moving-non-partitioned-tables" title="Moving Tables Between Tablespaces Using ALTER TABLE"> Moving Tables Between Tablespaces Using ALTER TABLE </a> . </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> <code class="literal"> ALTER TABLE ... TABLESPACE </code> operations always cause a full table rebuild, even if the <code class="literal"> TABLESPACE </code> attribute has not changed from its previous value. </p> </li> <li class="listitem"> <p> <code class="literal"> ALTER TABLE ... TABLESPACE </code> syntax does not support moving a table from a temporary tablespace to a persistent tablespace. </p> </li> <li class="listitem"> <p> The <code class="literal"> DATA DIRECTORY </code> clause, which is supported with <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE ... TABLESPACE </code> </a> , is not supported with <code class="literal"> ALTER TABLE ... TABLESPACE </code> , and is ignored if specified. </p> </li> <li class="listitem"> <p> For more information about the capabilities and limitations of the <code class="literal"> TABLESPACE </code> option, see <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> . </p> </li> </ul> </div> </li> <li class="listitem"> <p> MySQL NDB Cluster 8.4 supports setting <code class="literal"> NDB_TABLE </code> options for controlling a table's partition balance (fragment count type), read-from-any-replica capability, full replication, or any combination of these, as part of the table comment for an <code class="literal"> ALTER TABLE </code> statement in the same manner as for <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> , as shown in this example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa47427485"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">"NDB_TABLE=READ_BACKUP=0,PARTITION_BALANCE=FOR_RA_BY_NODE"</span><span class="token punctuation">;</span></code></pre> </div> <p> It is also possible to set <code class="literal"> NDB_COMMENT </code> options for columns of <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables as part of an <code class="literal"> ALTER TABLE </code> statement, like this one: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa79404315"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHANGE</span> <span class="token keyword">COLUMN</span> c1 c1 <span class="token datatype">BLOB</span> <span class="token keyword">COMMENT</span> <span class="token operator">=</span> <span class="token string">'NDB_COLUMN=BLOB_INLINE_SIZE=4096,MAX_BLOB_PART_SIZE'</span><span class="token punctuation">;</span></code></pre> </div> <p> Bear in mind that <code class="literal"> ALTER TABLE ... COMMENT ... </code> discards any existing comment for the table. See <a class="xref" href="create-table.html#create-table-comment-ndb-table-options" title="Setting NDB_TABLE options"> Setting NDB_TABLE options </a> , for additional information and examples. </p> </li> <li class="listitem"> <p> <code class="literal"> ENGINE_ATTRIBUTE </code> and <code class="literal"> SECONDARY_ENGINE_ATTRIBUTE </code> options are used to specify table, column, and index attributes for primary and secondary storage engines. These options are reserved for future use. Index attributes cannot be altered. An index must be dropped and added back with the desired change, which can be performed in a single <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement. </p> </li> </ul> </div> <p> To verify that the table options were changed as intended, use <a class="link" href="show-create-table.html" title="15.7.7.11 SHOW CREATE TABLE Statement"> <code class="literal"> SHOW CREATE TABLE </code> </a> , or query the Information Schema <a class="link" href="information-schema-tables-table.html" title="28.3.38 The INFORMATION_SCHEMA TABLES Table"> <code class="literal"> TABLES </code> </a> table. </p> <h4> <a name="alter-table-performance"> </a> Performance and Space Requirements </h4> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operations are processed using one of the following algorithms: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> COPY </code> : Operations are performed on a copy of the original table, and table data is copied from the original table to the new table row by row. Concurrent DML is not permitted. </p> </li> <li class="listitem"> <p> <code class="literal"> INPLACE </code> : Operations avoid copying table data but may rebuild the table in place. An exclusive metadata lock on the table may be taken briefly during preparation and execution phases of the operation. Typically, concurrent DML is supported. </p> </li> <li class="listitem"> <p> <code class="literal"> INSTANT </code> : Operations only modify metadata in the data dictionary. An exclusive metadata lock on the table may be taken briefly during the execution phase of the operation. Table data is unaffected, making operations instantaneous. Concurrent DML is permitted. </p> </li> </ul> </div> <p> For tables using the <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> storage engine, these algorithms work as follows: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> COPY </code> : <code class="literal"> NDB </code> creates a copy of the table and alters it; the NDB Cluster handler then copies the data between the old and new versions of the table. Subsequently, <code class="literal"> NDB </code> deletes the old table and renames the new one. </p> <p> This is sometimes also referred to as a <span class="quote"> “ <span class="quote"> copying </span> ” </span> or <span class="quote"> “ <span class="quote"> offline </span> ” </span> <code class="literal"> ALTER TABLE </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> INPLACE </code> : The data nodes make the required changes; the NDB Cluster handler does not copy data or otherwise take part. </p> <p> This is sometimes also referred to as a <span class="quote"> “ <span class="quote"> non-copying </span> ” </span> or <span class="quote"> “ <span class="quote"> online </span> ” </span> <code class="literal"> ALTER TABLE </code> . </p> </li> <li class="listitem"> <p> <code class="literal"> INSTANT </code> : Not supported by <code class="literal"> NDB </code> . </p> </li> </ul> </div> <p> See <a class="xref" href="mysql-cluster-online-operations.html" title="25.6.12 Online Operations with ALTER TABLE in NDB Cluster"> Section 25.6.12, “Online Operations with ALTER TABLE in NDB Cluster” </a> , for more information. </p> <p> The <code class="literal"> ALGORITHM </code> clause is optional. If the <code class="literal"> ALGORITHM </code> clause is omitted, MySQL uses <code class="literal"> ALGORITHM=INSTANT </code> for storage engines and <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> clauses that support it. Otherwise, <code class="literal"> ALGORITHM=INPLACE </code> is used. If <code class="literal"> ALGORITHM=INPLACE </code> is not supported, <code class="literal"> ALGORITHM=COPY </code> is used. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> After adding a column to a partitioned table using <code class="literal"> ALGORITHM=INSTANT </code> , it is no longer possible to perform <a class="link" href="alter-table-partition-operations.html" title="15.1.9.1 ALTER TABLE Partition Operations"> <code class="literal"> ALTER TABLE ... EXCHANGE PARTITION </code> </a> on the table. </p> </div> <p> Specifying an <code class="literal"> ALGORITHM </code> clause requires the operation to use the specified algorithm for clauses and storage engines that support it, or fail with an error otherwise. Specifying <code class="literal"> ALGORITHM=DEFAULT </code> is the same as omitting the <code class="literal"> ALGORITHM </code> clause. </p> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operations that use the <code class="literal"> COPY </code> algorithm wait for other operations that are modifying the table to complete. After alterations are applied to the table copy, data is copied over, the original table is deleted, and the table copy is renamed to the name of the original table. While the <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation executes, the original table is readable by other sessions (with the exception noted shortly). Updates and writes to the table started after the <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation begins are stalled until the new table is ready, then are automatically redirected to the new table. The temporary copy of the table is created in the database directory of the original table unless it is a <code class="literal"> RENAME TO </code> operation that moves the table to a database that resides in a different directory. </p> <p> The exception referred to earlier is that <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> blocks reads (not just writes) at the point where it is ready to clear outdated table structures from the table and table definition caches. At this point, it must acquire an exclusive lock. To do so, it waits for current readers to finish, and blocks new reads and writes. </p> <p> An <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation that uses the <code class="literal"> COPY </code> algorithm prevents concurrent DML operations. Concurrent queries are still allowed. That is, a table-copying operation always includes at least the concurrency restrictions of <code class="literal"> LOCK=SHARED </code> (allow queries but not DML). You can further restrict concurrency for operations that support the <code class="literal"> LOCK </code> clause by specifying <code class="literal"> LOCK=EXCLUSIVE </code> , which prevents DML and queries. For more information, see <a class="xref" href="alter-table.html#alter-table-concurrency" title="Concurrency Control"> Concurrency Control </a> . </p> <p> To force use of the <code class="literal"> COPY </code> algorithm for an <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation that would otherwise not use it, specify <code class="literal"> ALGORITHM=COPY </code> or enable the <a class="link" href="server-system-variables.html#sysvar_old_alter_table"> <code class="literal"> old_alter_table </code> </a> system variable. If there is a conflict between the <code class="literal"> old_alter_table </code> setting and an <code class="literal"> ALGORITHM </code> clause with a value other than <code class="literal"> DEFAULT </code> , the <code class="literal"> ALGORITHM </code> clause takes precedence. </p> <p> For <code class="literal"> InnoDB </code> tables, an <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operation that uses the <code class="literal"> COPY </code> algorithm on a table that resides in a <a class="link" href="glossary.html#glos_shared_tablespace" title="shared tablespace"> shared tablespace </a> can increase the amount of space used by the tablespace. Such operations require as much additional space as the data in the table plus indexes. For a table residing in a shared tablespace, the additional space used during the operation is not released back to the operating system as it is for a table that resides in a <a class="link" href="glossary.html#glos_file_per_table" title="file-per-table"> file-per-table </a> tablespace. </p> <p> For information about space requirements for online DDL operations, see <a class="xref" href="innodb-online-ddl-space-requirements.html" title="17.12.3 Online DDL Space Requirements"> Section 17.12.3, “Online DDL Space Requirements” </a> . </p> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operations that support the <code class="literal"> INPLACE </code> algorithm include: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> ALTER TABLE </code> operations supported by the <code class="literal"> InnoDB </code> <a class="link" href="glossary.html#glos_online_ddl" title="online DDL"> online DDL </a> feature. See <a class="xref" href="innodb-online-ddl-operations.html" title="17.12.1 Online DDL Operations"> Section 17.12.1, “Online DDL Operations” </a> . </p> </li> <li class="listitem"> <p> Renaming a table. MySQL renames files that correspond to the table <em class="replaceable"> <code> tbl_name </code> </em> without making a copy. (You can also use the <a class="link" href="rename-table.html" title="15.1.36 RENAME TABLE Statement"> <code class="literal"> RENAME TABLE </code> </a> statement to rename tables. See <a class="xref" href="rename-table.html" title="15.1.36 RENAME TABLE Statement"> Section 15.1.36, “RENAME TABLE Statement” </a> .) Privileges granted specifically for the renamed table are not migrated to the new name. They must be changed manually. </p> </li> <li class="listitem"> <p> Operations that modify table metadata only. These operations are immediate because the server does not touch table contents. Metadata-only operations include: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Renaming a column. In NDB Cluster, this operation can also be performed online. </p> </li> <li class="listitem"> <p> Changing the default value of a column (except for <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables). </p> </li> <li class="listitem"> <p> Modifying the definition of an <a class="link" href="enum.html" title="13.3.5 The ENUM Type"> <code class="literal"> ENUM </code> </a> or <a class="link" href="set.html" title="13.3.6 The SET Type"> <code class="literal"> SET </code> </a> column by adding new enumeration or set members to the <span class="emphasis"> <em> end </em> </span> of the list of valid member values, as long as the storage size of the data type does not change. For example, adding a member to a <a class="link" href="set.html" title="13.3.6 The SET Type"> <code class="literal"> SET </code> </a> column that has 8 members changes the required storage per value from 1 byte to 2 bytes; this requires a table copy. Adding members in the middle of the list causes renumbering of existing members, which requires a table copy. </p> </li> <li class="listitem"> <p> Changing the definition of a spatial column to remove the <code class="literal"> SRID </code> attribute. (Adding or changing an <code class="literal"> SRID </code> attribute requires a rebuild, and cannot be done in place, because the server must verify that all values have the specified <code class="literal"> SRID </code> value.) </p> </li> <li class="listitem"> <p> Changing a column character set, when these conditions apply: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: square; "> <li class="listitem"> <p> The column data type is <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> , <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> , a <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> type, or <a class="link" href="enum.html" title="13.3.5 The ENUM Type"> <code class="literal"> ENUM </code> </a> . </p> </li> <li class="listitem"> <p> The character set change is from <code class="literal"> utf8mb3 </code> to <code class="literal"> utf8mb4 </code> , or any character set to <code class="literal"> binary </code> . </p> </li> <li class="listitem"> <p> There is no index on the column. </p> </li> </ul> </div> </li> <li class="listitem"> <p> Changing a generated column, when these conditions apply: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: square; "> <li class="listitem"> <p> For <code class="literal"> InnoDB </code> tables, statements that modify generated stored columns but do not change their type, expression, or nullability. </p> </li> <li class="listitem"> <p> For non- <code class="literal"> InnoDB </code> tables, statements that modify generated stored or virtual columns but do not change their type, expression, or nullability. </p> </li> </ul> </div> <p> An example of such a change is a change to the column comment. </p> </li> </ul> </div> </li> <li class="listitem"> <p> Renaming an index. </p> </li> <li class="listitem"> <p> Adding or dropping a secondary index, for <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine"> <code class="literal"> InnoDB </code> </a> and <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables. See <a class="xref" href="innodb-online-ddl-operations.html" title="17.12.1 Online DDL Operations"> Section 17.12.1, “Online DDL Operations” </a> . </p> </li> <li class="listitem"> <p> For <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables, operations that add and drop indexes on variable-width columns. These operations occur online, without table copying and without blocking concurrent DML actions for most of their duration. See <a class="xref" href="mysql-cluster-online-operations.html" title="25.6.12 Online Operations with ALTER TABLE in NDB Cluster"> Section 25.6.12, “Online Operations with ALTER TABLE in NDB Cluster” </a> . </p> </li> <li class="listitem"> <p> Modifying index visibility with an <code class="literal"> ALTER INDEX </code> operation. </p> </li> <li class="listitem"> <p> Column modifications of tables containing generated columns that depend on columns with a <code class="literal"> DEFAULT </code> value if the modified columns are not involved in the generated column expressions. For example, changing the <code class="literal"> NULL </code> property of a separate column can be done in place without a table rebuild. </p> </li> </ul> </div> <p> <code class="literal"> ALTER TABLE </code> operations that support the <code class="literal"> INSTANT </code> algorithm include: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Adding a column. This feature is referred to as <span class="quote"> “ <span class="quote"> Instant <code class="literal"> ADD COLUMN </code> </span> ” </span> . Limitations apply. See <a class="xref" href="innodb-online-ddl-operations.html" title="17.12.1 Online DDL Operations"> Section 17.12.1, “Online DDL Operations” </a> . </p> </li> <li class="listitem"> <p> Dropping a column. This feature is referred to as <span class="quote"> “ <span class="quote"> Instant <code class="literal"> DROP COLUMN </code> </span> ” </span> . Limitations apply. See <a class="xref" href="innodb-online-ddl-operations.html" title="17.12.1 Online DDL Operations"> Section 17.12.1, “Online DDL Operations” </a> . </p> </li> <li class="listitem"> <p> Adding or dropping a virtual column. </p> </li> <li class="listitem"> <p> Adding or dropping a column default value. </p> </li> <li class="listitem"> <p> Modifying the definition of an <a class="link" href="enum.html" title="13.3.5 The ENUM Type"> <code class="literal"> ENUM </code> </a> or <a class="link" href="set.html" title="13.3.6 The SET Type"> <code class="literal"> SET </code> </a> column. The same restrictions apply as described above for <code class="literal"> ALGORITHM=INSTANT </code> . </p> </li> <li class="listitem"> <p> Changing the index type. </p> </li> <li class="listitem"> <p> Renaming a table. The same restrictions apply as described above for <code class="literal"> ALGORITHM=INSTANT </code> . </p> </li> </ul> </div> <p> For more information about operations that support <code class="literal"> ALGORITHM=INSTANT </code> , see <a class="xref" href="innodb-online-ddl-operations.html" title="17.12.1 Online DDL Operations"> Section 17.12.1, “Online DDL Operations” </a> . </p> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> upgrades MySQL 5.5 temporal columns to 5.6 format for <code class="literal"> ADD COLUMN </code> , <code class="literal"> CHANGE COLUMN </code> , <code class="literal"> MODIFY COLUMN </code> , <code class="literal"> ADD INDEX </code> , and <code class="literal"> FORCE </code> operations. This conversion cannot be done using the <code class="literal"> INPLACE </code> algorithm because the table must be rebuilt, so specifying <code class="literal"> ALGORITHM=INPLACE </code> in these cases results in an error. Specify <code class="literal"> ALGORITHM=COPY </code> if necessary. </p> <p> If an <code class="literal"> ALTER TABLE </code> operation on a multicolumn index used to partition a table by <code class="literal"> KEY </code> changes the order of the columns, it can only be performed using <code class="literal"> ALGORITHM=COPY </code> . </p> <p> The <code class="literal"> WITHOUT VALIDATION </code> and <code class="literal"> WITH VALIDATION </code> clauses affect whether <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> performs an in-place operation for <a class="link" href="glossary.html#glos_virtual_generated_column" title="virtual generated column"> virtual generated column </a> modifications. See <a class="xref" href="alter-table-generated-columns.html" title="15.1.9.2 ALTER TABLE and Generated Columns"> Section 15.1.9.2, “ALTER TABLE and Generated Columns” </a> . </p> <p> NDB Cluster 8.4 supports online operations using the same <code class="literal"> ALGORITHM=INPLACE </code> syntax used with the standard MySQL Server. <code class="literal"> NDB </code> does not allow changing a tablespace online. See <a class="xref" href="mysql-cluster-online-operations.html" title="25.6.12 Online Operations with ALTER TABLE in NDB Cluster"> Section 25.6.12, “Online Operations with ALTER TABLE in NDB Cluster” </a> , for more information. </p> <p> When performing a copying <code class="literal"> ALTER TABLE </code> , <code class="literal"> NDB </code> checks to ensure that no concurrent writes have been made to the affected table. If it finds that any have been made, <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> rejects the <code class="literal"> ALTER TABLE </code> statement and raises <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_table_def_changed" target="_top"> <code class="literal"> ER_TABLE_DEF_CHANGED </code> </a> . </p> <p> <code class="literal"> ALTER TABLE </code> with <code class="literal"> DISCARD ... PARTITION ... TABLESPACE </code> or <code class="literal"> IMPORT ... PARTITION ... TABLESPACE </code> does not create any temporary tables or temporary partition files. </p> <p> <code class="literal"> ALTER TABLE </code> with <code class="literal"> ADD PARTITION </code> , <code class="literal"> DROP PARTITION </code> , <code class="literal"> COALESCE PARTITION </code> , <code class="literal"> REBUILD PARTITION </code> , or <code class="literal"> REORGANIZE PARTITION </code> does not create temporary tables (except when used with <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4"> <code class="literal"> NDB </code> </a> tables); however, these operations can and do create temporary partition files. </p> <p> <code class="literal"> ADD </code> or <code class="literal"> DROP </code> operations for <code class="literal"> RANGE </code> or <code class="literal"> LIST </code> partitions are immediate operations or nearly so. <code class="literal"> ADD </code> or <code class="literal"> COALESCE </code> operations for <code class="literal"> HASH </code> or <code class="literal"> KEY </code> partitions copy data between all partitions, unless <code class="literal"> LINEAR HASH </code> or <code class="literal"> LINEAR KEY </code> was used; this is effectively the same as creating a new table, although the <code class="literal"> ADD </code> or <code class="literal"> COALESCE </code> operation is performed partition by partition. <code class="literal"> REORGANIZE </code> operations copy only changed partitions and do not touch unchanged ones. </p> <p> For <code class="literal"> MyISAM </code> tables, you can speed up index re-creation (the slowest part of the alteration process) by setting the <a class="link" href="server-system-variables.html#sysvar_myisam_sort_buffer_size"> <code class="literal"> myisam_sort_buffer_size </code> </a> system variable to a high value. </p> <h4> <a name="alter-table-concurrency"> </a> Concurrency Control </h4> <p> For <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> operations that support it, you can use the <code class="literal"> LOCK </code> clause to control the level of concurrent reads and writes on a table while it is being altered. Specifying a non-default value for this clause enables you to require a certain amount of concurrent access or exclusivity during the alter operation, and halts the operation if the requested degree of locking is not available. </p> <p> Only <code class="literal"> LOCK = DEFAULT </code> is permitted for operations that use <code class="literal"> ALGORITHM=INSTANT </code> . The other <code class="literal"> LOCK </code> clause parameters are not applicable. </p> <p> The parameters for the <code class="literal"> LOCK </code> clause are: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> LOCK = DEFAULT </code> </p> <p> Maximum level of concurrency for the given <code class="literal"> ALGORITHM </code> clause (if any) and <code class="literal"> ALTER TABLE </code> operation: Permit concurrent reads and writes if supported. If not, permit concurrent reads if supported. If not, enforce exclusive access. </p> </li> <li class="listitem"> <p> <code class="literal"> LOCK = NONE </code> </p> <p> If supported, permit concurrent reads and writes. Otherwise, an error occurs. </p> </li> <li class="listitem"> <p> <code class="literal"> LOCK = SHARED </code> </p> <p> If supported, permit concurrent reads but block writes. Writes are blocked even if concurrent writes are supported by the storage engine for the given <code class="literal"> ALGORITHM </code> clause (if any) and <code class="literal"> ALTER TABLE </code> operation. If concurrent reads are not supported, an error occurs. </p> </li> <li class="listitem"> <p> <code class="literal"> LOCK = EXCLUSIVE </code> </p> <p> Enforce exclusive access. This is done even if concurrent reads/writes are supported by the storage engine for the given <code class="literal"> ALGORITHM </code> clause (if any) and <code class="literal"> ALTER TABLE </code> operation. </p> </li> </ul> </div> <h4> <a name="alter-table-add-drop-column"> </a> Adding and Dropping Columns </h4> <p> Use <code class="literal"> ADD </code> to add new columns to a table, and <code class="literal"> DROP </code> to remove existing columns. <code class="literal"> DROP <em class="replaceable"> <code> col_name </code> </em> </code> is a MySQL extension to standard SQL. </p> <p> To add a column at a specific position within a table row, use <code class="literal"> FIRST </code> or <code class="literal"> AFTER <em class="replaceable"> <code> col_name </code> </em> </code> . The default is to add the column last. </p> <p> If a table contains only one column, the column cannot be dropped. If what you intend is to remove the table, use the <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement"> <code class="literal"> DROP TABLE </code> </a> statement instead. </p> <p> If columns are dropped from a table, the columns are also removed from any index of which they are a part. If all columns that make up an index are dropped, the index is dropped as well. If you use <code class="literal"> CHANGE </code> or <code class="literal"> MODIFY </code> to shorten a column for which an index exists on the column, and the resulting column length is less than the index length, MySQL shortens the index automatically. </p> <p> For <code class="literal"> ALTER TABLE ... ADD </code> , if the column has an expression default value that uses a nondeterministic function, the statement may produce a warning or error. For further information, see <a class="xref" href="data-type-defaults.html" title="13.6 Data Type Default Values"> Section 13.6, “Data Type Default Values” </a> , and <a class="xref" href="replication-gtids-restrictions.html" title="19.1.3.7 Restrictions on Replication with GTIDs"> Section 19.1.3.7, “Restrictions on Replication with GTIDs” </a> . </p> <h4> <a name="alter-table-redefine-column"> </a> Renaming, Redefining, and Reordering Columns </h4> <a class="indexterm" name="idm46045189128768"> </a> <a class="indexterm" name="idm46045189127280"> </a> <a class="indexterm" name="idm46045189125792"> </a> <a class="indexterm" name="idm46045189124304"> </a> <p> The <code class="literal"> CHANGE </code> , <code class="literal"> MODIFY </code> , <code class="literal"> RENAME COLUMN </code> , and <code class="literal"> ALTER </code> clauses enable the names and definitions of existing columns to be altered. They have these comparative characteristics: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> CHANGE </code> : </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Can rename a column and change its definition, or both. </p> </li> <li class="listitem"> <p> Has more capability than <code class="literal"> MODIFY </code> or <code class="literal"> RENAME COLUMN </code> , but at the expense of convenience for some operations. <code class="literal"> CHANGE </code> requires naming the column twice if not renaming it, and requires respecifying the column definition if only renaming it. </p> </li> <li class="listitem"> <p> With <code class="literal"> FIRST </code> or <code class="literal"> AFTER </code> , can reorder columns. </p> </li> </ul> </div> </li> <li class="listitem"> <p> <code class="literal"> MODIFY </code> : </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Can change a column definition but not its name. </p> </li> <li class="listitem"> <p> More convenient than <code class="literal"> CHANGE </code> to change a column definition without renaming it. </p> </li> <li class="listitem"> <p> With <code class="literal"> FIRST </code> or <code class="literal"> AFTER </code> , can reorder columns. </p> </li> </ul> </div> </li> <li class="listitem"> <p> <code class="literal"> RENAME COLUMN </code> : </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: circle; "> <li class="listitem"> <p> Can change a column name but not its definition. </p> </li> <li class="listitem"> <p> More convenient than <code class="literal"> CHANGE </code> to rename a column without changing its definition. </p> </li> </ul> </div> </li> <li class="listitem"> <p> <code class="literal"> ALTER </code> : Used only to change a column default value. </p> </li> </ul> </div> <a class="indexterm" name="idm46045189098400"> </a> <a class="indexterm" name="idm46045189097328"> </a> <p> <code class="literal"> CHANGE </code> is a MySQL extension to standard SQL. <code class="literal"> MODIFY </code> and <code class="literal"> RENAME COLUMN </code> are MySQL extensions for Oracle compatibility. </p> <p> To alter a column to change both its name and definition, use <code class="literal"> CHANGE </code> , specifying the old and new names and the new definition. For example, to rename an <code class="literal"> INT NOT NULL </code> column from <code class="literal"> a </code> to <code class="literal"> b </code> and change its definition to use the <code class="literal"> BIGINT </code> data type while retaining the <code class="literal"> NOT NULL </code> attribute, do this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa62279787"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHANGE</span> a b <span class="token datatype">BIGINT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span></code></pre> </div> <p> To change a column definition but not its name, use <code class="literal"> CHANGE </code> or <code class="literal"> MODIFY </code> . With <code class="literal"> CHANGE </code> , the syntax requires two column names, so you must specify the same name twice to leave the name unchanged. For example, to change the definition of column <code class="literal"> b </code> , do this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa15469092"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHANGE</span> b b <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span></code></pre> </div> <p> <code class="literal"> MODIFY </code> is more convenient to change the definition without changing the name because it requires the column name only once: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa33906722"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">MODIFY</span> b <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span></code></pre> </div> <p> To change a column name but not its definition, use <code class="literal"> CHANGE </code> or <code class="literal"> RENAME COLUMN </code> . With <code class="literal"> CHANGE </code> , the syntax requires a column definition, so to leave the definition unchanged, you must respecify the definition the column currently has. For example, to rename an <code class="literal"> INT NOT NULL </code> column from <code class="literal"> b </code> to <code class="literal"> a </code> , do this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa91860529"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHANGE</span> b a <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span></code></pre> </div> <p> <code class="literal"> RENAME COLUMN </code> is more convenient to change the name without changing the definition because it requires only the old and new names: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa3473577"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> b <span class="token keyword">TO</span> a<span class="token punctuation">;</span></code></pre> </div> <p> In general, you cannot rename a column to a name that already exists in the table. However, this is sometimes not the case, such as when you swap names or move them through a cycle. If a table has columns named <code class="literal"> a </code> , <code class="literal"> b </code> , and <code class="literal"> c </code> , these are valid operations: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58698386"><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 comment" spellcheck="true">-- swap a and b</span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> a <span class="token keyword">TO</span> b<span class="token punctuation">,</span> <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> b <span class="token keyword">TO</span> a<span class="token punctuation">;</span> <span class="token comment" spellcheck="true">-- "rotate" a, b, c through a cycle</span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> a <span class="token keyword">TO</span> b<span class="token punctuation">,</span> <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> b <span class="token keyword">TO</span> c<span class="token punctuation">,</span> <span class="token keyword">RENAME</span> <span class="token keyword">COLUMN</span> c <span class="token keyword">TO</span> a<span class="token punctuation">;</span></code></pre> </div> <p> For column definition changes using <code class="literal"> CHANGE </code> or <code class="literal"> MODIFY </code> , the definition must include the data type and all attributes that should apply to the new column, other than index attributes such as <code class="literal"> PRIMARY KEY </code> or <code class="literal"> UNIQUE </code> . Attributes present in the original definition but not specified for the new definition are not carried forward. Suppose that a column <code class="literal"> col1 </code> is defined as <code class="literal"> INT UNSIGNED DEFAULT 1 COMMENT 'my column' </code> and you modify the column as follows, intending to change only <code class="literal"> INT </code> to <code class="literal"> BIGINT </code> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa36479411"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">MODIFY</span> col1 <span class="token datatype">BIGINT</span><span class="token punctuation">;</span></code></pre> </div> <p> That statement changes the data type from <code class="literal"> INT </code> to <code class="literal"> BIGINT </code> , but it also drops the <code class="literal"> UNSIGNED </code> , <code class="literal"> DEFAULT </code> , and <code class="literal"> COMMENT </code> attributes. To retain them, the statement must include them explicitly: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa94917873"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">MODIFY</span> col1 <span class="token datatype">BIGINT</span> <span class="token keyword">UNSIGNED</span> <span class="token keyword">DEFAULT</span> <span class="token number">1</span> <span class="token keyword">COMMENT</span> <span class="token string">'my column'</span><span class="token punctuation">;</span></code></pre> </div> <p> For data type changes using <code class="literal"> CHANGE </code> or <code class="literal"> MODIFY </code> , MySQL tries to convert existing column values to the new type as well as possible. </p> <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Warning </div> <p> This conversion may result in alteration of data. For example, if you shorten a string column, values may be truncated. To prevent the operation from succeeding if conversions to the new data type would result in loss of data, enable strict SQL mode before using <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> (see <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes"> Section 7.1.11, “Server SQL Modes” </a> ). </p> </div> <p> If you use <code class="literal"> CHANGE </code> or <code class="literal"> MODIFY </code> to shorten a column for which an index exists on the column, and the resulting column length is less than the index length, MySQL shortens the index automatically. </p> <p> For columns renamed by <code class="literal"> CHANGE </code> or <code class="literal"> RENAME COLUMN </code> , MySQL automatically renames these references to the renamed column: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Indexes that refer to the old column, including invisible indexes and disabled <code class="literal"> MyISAM </code> indexes. </p> </li> <li class="listitem"> <p> Foreign keys that refer to the old column. </p> </li> </ul> </div> <p> For columns renamed by <code class="literal"> CHANGE </code> or <code class="literal"> RENAME COLUMN </code> , MySQL does not automatically rename these references to the renamed column: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Generated column and partition expressions that refer to the renamed column. You must use <code class="literal"> CHANGE </code> to redefine such expressions in the same <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement as the one that renames the column. </p> </li> <li class="listitem"> <p> Views and stored programs that refer to the renamed column. You must manually alter the definition of these objects to refer to the new column name. </p> </li> </ul> </div> <p> To reorder columns within a table, use <code class="literal"> FIRST </code> and <code class="literal"> AFTER </code> in <code class="literal"> CHANGE </code> or <code class="literal"> MODIFY </code> operations. </p> <a class="indexterm" name="idm46045189035088"> </a> <p> <code class="literal"> ALTER ... SET DEFAULT </code> or <code class="literal"> ALTER ... DROP DEFAULT </code> specify a new default value for a column or remove the old default value, respectively. If the old default is removed and the column can be <code class="literal"> NULL </code> , the new default is <code class="literal"> NULL </code> . If the column cannot be <code class="literal"> NULL </code> , MySQL assigns a default value as described in <a class="xref" href="data-type-defaults.html" title="13.6 Data Type Default Values"> Section 13.6, “Data Type Default Values” </a> . </p> <p> <code class="literal"> ALTER ... SET VISIBLE </code> and <code class="literal"> ALTER ... SET INVISIBLE </code> enable column visibility to be changed. See <a class="xref" href="invisible-columns.html" title="15.1.20.10 Invisible Columns"> Section 15.1.20.10, “Invisible Columns” </a> . </p> <h4> <a name="alter-table-index"> </a> Primary Keys and Indexes </h4> <a class="indexterm" name="idm46045189025408"> </a> <a class="indexterm" name="idm46045189024368"> </a> <a class="indexterm" name="idm46045189022880"> </a> <p> <code class="literal"> DROP PRIMARY KEY </code> drops the <a class="link" href="glossary.html#glos_primary_key" title="primary key"> primary key </a> . If there is no primary key, an error occurs. For information about the performance characteristics of primary keys, especially for <code class="literal"> InnoDB </code> tables, see <a class="xref" href="primary-key-optimization.html" title="10.3.2 Primary Key Optimization"> Section 10.3.2, “Primary Key Optimization” </a> . </p> <p> If the <a class="link" href="server-system-variables.html#sysvar_sql_require_primary_key"> <code class="literal"> sql_require_primary_key </code> </a> system variable is enabled, attempting to drop a primary key produces an error. </p> <a class="indexterm" name="idm46045189015968"> </a> <a class="indexterm" name="idm46045189014896"> </a> <p> If you add a <code class="literal"> UNIQUE INDEX </code> or <code class="literal"> PRIMARY KEY </code> to a table, MySQL stores it before any nonunique index to permit detection of duplicate keys as early as possible. </p> <a class="indexterm" name="idm46045189011856"> </a> <a class="indexterm" name="idm46045189010784"> </a> <a class="indexterm" name="idm46045189009296"> </a> <p> <a class="link" href="drop-index.html" title="15.1.27 DROP INDEX Statement"> <code class="literal"> DROP INDEX </code> </a> removes an index. This is a MySQL extension to standard SQL. See <a class="xref" href="drop-index.html" title="15.1.27 DROP INDEX Statement"> Section 15.1.27, “DROP INDEX Statement” </a> . To determine index names, use <code class="literal"> SHOW INDEX FROM <em class="replaceable"> <code> tbl_name </code> </em> </code> . </p> <p> Some storage engines permit you to specify an index type when creating an index. The syntax for the <em class="replaceable"> <code> index_type </code> </em> specifier is <code class="literal"> USING <em class="replaceable"> <code> type_name </code> </em> </code> . For details about <code class="literal"> USING </code> , see <a class="xref" href="create-index.html" title="15.1.15 CREATE INDEX Statement"> Section 15.1.15, “CREATE INDEX Statement” </a> . The preferred position is after the column list. Expect support for use of the option before the column list to be removed in a future MySQL release. </p> <p> <em class="replaceable"> <code> index_option </code> </em> values specify additional options for an index. <code class="literal"> USING </code> is one such option. For details about permissible <em class="replaceable"> <code> index_option </code> </em> values, see <a class="xref" href="create-index.html" title="15.1.15 CREATE INDEX Statement"> Section 15.1.15, “CREATE INDEX Statement” </a> . </p> <p> <code class="literal"> RENAME INDEX <em class="replaceable"> <code> old_index_name </code> </em> TO <em class="replaceable"> <code> new_index_name </code> </em> </code> renames an index. This is a MySQL extension to standard SQL. The content of the table remains unchanged. <em class="replaceable"> <code> old_index_name </code> </em> must be the name of an existing index in the table that is not dropped by the same <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement. <em class="replaceable"> <code> new_index_name </code> </em> is the new index name, which cannot duplicate the name of an index in the resulting table after changes have been applied. Neither index name can be <code class="literal"> PRIMARY </code> . </p> <a class="indexterm" name="idm46045188993152"> </a> <a class="indexterm" name="idm46045188992080"> </a> <a class="indexterm" name="idm46045188990592"> </a> <p> If you use <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> on a <code class="literal"> MyISAM </code> table, all nonunique indexes are created in a separate batch (as for <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement"> <code class="literal"> REPAIR TABLE </code> </a> ). This should make <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> much faster when you have many indexes. </p> <p> For <code class="literal"> MyISAM </code> tables, key updating can be controlled explicitly. Use <code class="literal"> ALTER TABLE ... DISABLE KEYS </code> to tell MySQL to stop updating nonunique indexes. Then use <code class="literal"> ALTER TABLE ... ENABLE KEYS </code> to re-create missing indexes. <code class="literal"> MyISAM </code> does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using <code class="literal"> ALTER TABLE ... DISABLE KEYS </code> requires the <a class="link" href="privileges-provided.html#priv_index"> <code class="literal"> INDEX </code> </a> privilege in addition to the privileges mentioned earlier. </p> <p> While the nonunique indexes are disabled, they are ignored for statements such as <a class="link" href="select.html" title="15.2.13 SELECT Statement"> <code class="literal"> SELECT </code> </a> and <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN </code> </a> that otherwise would use them. </p> <p> After an <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement, it may be necessary to run <a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement"> <code class="literal"> ANALYZE TABLE </code> </a> to update index cardinality information. See <a class="xref" href="show-index.html" title="15.7.7.23 SHOW INDEX Statement"> Section 15.7.7.23, “SHOW INDEX Statement” </a> . </p> <a class="indexterm" name="idm46045188971920"> </a> <p> The <code class="literal"> ALTER INDEX </code> operation permits an index to be made visible or invisible. An invisible index is not used by the optimizer. Modification of index visibility applies to indexes other than primary keys (either explicit or implicit), and cannot be performed using <code class="literal"> ALGORITHM=INSTANT </code> . This feature is storage engine neutral (supported for any engine). For more information, see <a class="xref" href="invisible-indexes.html" title="10.3.12 Invisible Indexes"> Section 10.3.12, “Invisible Indexes” </a> . </p> <h4> <a name="alter-table-foreign-key"> </a> Foreign Keys and Other Constraints </h4> <a class="indexterm" name="idm46045188966784"> </a> <a class="indexterm" name="idm46045188965744"> </a> <p> The <code class="literal"> FOREIGN KEY </code> and <code class="literal"> REFERENCES </code> clauses are supported by the <code class="literal"> InnoDB </code> and <code class="literal"> NDB </code> storage engines, which implement <code class="literal"> ADD [CONSTRAINT [ <em class="replaceable"> <code> symbol </code> </em> ]] FOREIGN KEY [ <em class="replaceable"> <code> index_name </code> </em> ] (...) REFERENCES ... (...) </code> . See <a class="xref" href="create-table-foreign-keys.html" title="15.1.20.5 FOREIGN KEY Constraints"> Section 15.1.20.5, “FOREIGN KEY Constraints” </a> . For other storage engines, the clauses are parsed but ignored. </p> <p> For <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> , unlike <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> , <code class="literal"> ADD FOREIGN KEY </code> ignores <em class="replaceable"> <code> index_name </code> </em> if given and uses an automatically generated foreign key name. As a workaround, include the <code class="literal"> CONSTRAINT </code> clause to specify the foreign key name: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa68560052"><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">ADD</span> <span class="token keyword">CONSTRAINT</span> <span class="token keyword"><em class="replaceable">name</em></span> <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre> </div> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> MySQL silently ignores inline <code class="literal"> REFERENCES </code> specifications, where the references are defined as part of the column specification. MySQL accepts only <code class="literal"> REFERENCES </code> clauses defined as part of a separate <code class="literal"> FOREIGN KEY </code> specification. </p> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Partitioned <code class="literal"> InnoDB </code> tables do not support foreign keys. This restriction does not apply to <code class="literal"> NDB </code> tables, including those explicitly partitioned by <code class="literal"> [LINEAR] KEY </code> . For more information, see <a class="xref" href="partitioning-limitations-storage-engines.html" title="26.6.2 Partitioning Limitations Relating to Storage Engines"> Section 26.6.2, “Partitioning Limitations Relating to Storage Engines” </a> . </p> </div> <a class="indexterm" name="idm46045188945520"> </a> <a class="indexterm" name="idm46045188944448"> </a> <a class="indexterm" name="idm46045188942960"> </a> <p> MySQL Server and NDB Cluster both support the use of <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> to drop foreign keys: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa75617452"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">DROP</span> <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <em class="replaceable">fk_symbol</em><span class="token punctuation">;</span></code></pre> </div> <p> Adding and dropping a foreign key in the same <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement is supported for <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE ... ALGORITHM=INPLACE </code> </a> but not for <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE ... ALGORITHM=COPY </code> </a> . </p> <p> The server prohibits changes to foreign key columns that have the potential to cause loss of referential integrity. A workaround is to use <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE ... DROP FOREIGN KEY </code> </a> before changing the column definition and <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE ... ADD FOREIGN KEY </code> </a> afterward. Examples of prohibited changes include: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Changes to the data type of foreign key columns that may be unsafe. For example, changing <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR(20) </code> </a> to <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR(30) </code> </a> is permitted, but changing it to <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR(1024) </code> </a> is not because that alters the number of length bytes required to store individual values. </p> </li> <li class="listitem"> <p> Changing a <code class="literal"> NULL </code> column to <code class="literal"> NOT NULL </code> in non-strict mode is prohibited to prevent converting <code class="literal"> NULL </code> values to default non- <code class="literal"> NULL </code> values, for which there are no corresponding values in the referenced table. The operation is permitted in strict mode, but an error is returned if any such conversion is required. </p> </li> </ul> </div> <p> <code class="literal"> ALTER TABLE <em class="replaceable"> <code> tbl_name </code> </em> RENAME <em class="replaceable"> <code> new_tbl_name </code> </em> </code> changes internally generated foreign key constraint names and user-defined foreign key constraint names that begin with the string <span class="quote"> “ <span class="quote"> <em class="replaceable"> <code> tbl_name </code> </em> _ibfk_ </span> ” </span> to reflect the new table name. <code class="literal"> InnoDB </code> interprets foreign key constraint names that begin with the string <span class="quote"> “ <span class="quote"> <em class="replaceable"> <code> tbl_name </code> </em> _ibfk_ </span> ” </span> as internally generated names. </p> <a class="indexterm" name="idm46045188917328"> </a> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> permits <code class="literal"> CHECK </code> constraints for existing tables to be added, dropped, or altered: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Add a new <code class="literal"> CHECK </code> constraint: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68801855"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">ADD</span> <span class="token punctuation">[</span><span class="token keyword">CONSTRAINT</span> <span class="token punctuation">[</span><em class="replaceable">symbol</em><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token keyword">CHECK</span> <span class="token punctuation">(</span><em class="replaceable">expr</em><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">ENFORCED</span><span class="token punctuation">]</span><span class="token punctuation">;</span></code></pre> </div> <p> The meaning of constraint syntax elements is the same as for <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> . See <a class="xref" href="create-table-check-constraints.html" title="15.1.20.6 CHECK Constraints"> Section 15.1.20.6, “CHECK Constraints” </a> . </p> </li> <li class="listitem"> <p> Drop an existing <code class="literal"> CHECK </code> constraint named <em class="replaceable"> <code> symbol </code> </em> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63969837"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">DROP</span> <span class="token keyword">CHECK</span> <em class="replaceable">symbol</em><span class="token punctuation">;</span></code></pre> </div> </li> <li class="listitem"> <p> Alter whether an existing <code class="literal"> CHECK </code> constraint named <em class="replaceable"> <code> symbol </code> </em> is enforced: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa76747192"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">ALTER</span> <span class="token keyword">CHECK</span> <em class="replaceable">symbol</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">ENFORCED</span><span class="token punctuation">;</span></code></pre> </div> </li> </ul> </div> <p> The <code class="literal"> DROP CHECK </code> and <code class="literal"> ALTER CHECK </code> clauses are MySQL extensions to standard SQL. </p> <p> <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> permits more general (and SQL standard) syntax for dropping and altering existing constraints of any type, where the constraint type is determined from the constraint name: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Drop an existing constraint named <em class="replaceable"> <code> symbol </code> </em> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10600870"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">DROP</span> <span class="token keyword">CONSTRAINT</span> <em class="replaceable">symbol</em><span class="token punctuation">;</span></code></pre> </div> <p> If the <a class="link" href="server-system-variables.html#sysvar_sql_require_primary_key"> <code class="literal"> sql_require_primary_key </code> </a> system variable is enabled, attempting to drop a primary key produces an error. </p> </li> <li class="listitem"> <p> Alter whether an existing constraint named <em class="replaceable"> <code> symbol </code> </em> is enforced: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36041624"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">ALTER</span> <span class="token keyword">CONSTRAINT</span> <em class="replaceable">symbol</em> <span class="token punctuation">[</span><span class="token operator">NOT</span><span class="token punctuation">]</span> <span class="token keyword">ENFORCED</span><span class="token punctuation">;</span></code></pre> </div> <p> Only <code class="literal"> CHECK </code> constraints can be altered to be unenforced. All other constraint types are always enforced. </p> </li> </ul> </div> <p> The SQL standard specifies that all types of constraints (primary key, unique index, foreign key, check) belong to the same namespace. In MySQL, each constraint type has its own namespace per schema. Consequently, names for each type of constraint must be unique per schema, but constraints of different types can have the same name. When multiple constraints have the same name, <code class="literal"> DROP CONSTRAINT </code> and <code class="literal"> ADD CONSTRAINT </code> are ambiguous and an error occurs. In such cases, constraint-specific syntax must be used to modify the constraint. For example, use <code class="literal"> DROP PRIMARY KEY </code> or DROP FOREIGN KEY to drop a primary key or foreign key. </p> <p> If a table alteration causes a violation of an enforced <code class="literal"> CHECK </code> constraint, an error occurs and the table is not modified. Examples of operations for which an error occurs: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Attempts to add the <code class="literal"> AUTO_INCREMENT </code> attribute to a column that is used in a <code class="literal"> CHECK </code> constraint. </p> </li> <li class="listitem"> <p> Attempts to add an enforced <code class="literal"> CHECK </code> constraint or enforce a nonenforced <code class="literal"> CHECK </code> constraint for which existing rows violate the constraint condition. </p> </li> <li class="listitem"> <p> Attempts to modify, rename, or drop a column that is used in a <code class="literal"> CHECK </code> constraint, unless that constraint is also dropped in the same statement. Exception: If a <code class="literal"> CHECK </code> constraint refers only to a single column, dropping the column automatically drops the constraint. </p> </li> </ul> </div> <p> <code class="literal"> ALTER TABLE <em class="replaceable"> <code> tbl_name </code> </em> RENAME <em class="replaceable"> <code> new_tbl_name </code> </em> </code> changes internally generated and user-defined <code class="literal"> CHECK </code> constraint names that begin with the string <span class="quote"> “ <span class="quote"> <em class="replaceable"> <code> tbl_name </code> </em> _chk_ </span> ” </span> to reflect the new table name. MySQL interprets <code class="literal"> CHECK </code> constraint names that begin with the string <span class="quote"> “ <span class="quote"> <em class="replaceable"> <code> tbl_name </code> </em> _chk_ </span> ” </span> as internally generated names. </p> <h4> <a name="alter-table-character-set"> </a> Changing the Character Set </h4> <p> <a class="indexterm" name="idm46045188867552"> </a> To change the table default character set and all character columns ( <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> , <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> , <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> ) to a new character set, use a statement like this: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa32961287"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> CONVERT <span class="token keyword">TO</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span></code></pre> </div> <p> The statement also changes the collation of all character columns. If you specify no <code class="literal"> COLLATE </code> clause to indicate which collation to use, the statement uses default collation for the character set. If this collation is inappropriate for the intended table use (for example, if it would change from a case-sensitive collation to a case-insensitive collation), specify a collation explicitly. </p> <p> For a column that has a data type of <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> or one of the <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> types, <code class="literal"> CONVERT TO CHARACTER SET </code> changes the data type as necessary to ensure that the new column is long enough to store as many characters as the original column. For example, a <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> column has two length bytes, which store the byte-length of values in the column, up to a maximum of 65,535. For a <code class="literal"> latin1 </code> <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> column, each character requires a single byte, so the column can store up to 65,535 characters. If the column is converted to <code class="literal"> utf8mb4 </code> , each character might require up to 4 bytes, for a maximum possible length of 4 × 65,535 = 262,140 bytes. That length does not fit in a <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> column's length bytes, so MySQL converts the data type to <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> MEDIUMTEXT </code> </a> , which is the smallest string type for which the length bytes can record a value of 262,140. Similarly, a <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> column might be converted to <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> MEDIUMTEXT </code> </a> . </p> <p> To avoid data type changes of the type just described, do not use <code class="literal"> CONVERT TO CHARACTER SET </code> . Instead, use <code class="literal"> MODIFY </code> to change individual columns. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34821741"><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">ALTER</span> <span class="token keyword">TABLE</span> t <span class="token keyword">MODIFY</span> latin1_text_col <span class="token datatype">TEXT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> t <span class="token keyword">MODIFY</span> latin1_varchar_col <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><em class="replaceable">M</em><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">;</span></code></pre> </div> <p> If you specify <code class="literal"> CONVERT TO CHARACTER SET binary </code> , the <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> CHAR </code> </a> , <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types"> <code class="literal"> VARCHAR </code> </a> , and <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> TEXT </code> </a> columns are converted to their corresponding binary string types ( <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> BINARY </code> </a> , <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types"> <code class="literal"> VARBINARY </code> </a> , <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> ). This means that the columns no longer have a character set and a subsequent <code class="literal"> CONVERT TO </code> operation does not apply to them. </p> <p> If <em class="replaceable"> <code> charset_name </code> </em> is <code class="literal"> DEFAULT </code> in a <code class="literal"> CONVERT TO CHARACTER SET </code> operation, the character set named by the <a class="link" href="server-system-variables.html#sysvar_character_set_database"> <code class="literal"> character_set_database </code> </a> system variable is used. </p> <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Warning </div> <p> The <code class="literal"> CONVERT TO </code> operation converts column values between the original and named character sets. This is <span class="emphasis"> <em> not </em> </span> what you want if you have a column in one character set (like <code class="literal"> latin1 </code> ) but the stored values actually use some other, incompatible character set (like <code class="literal"> utf8mb4 </code> ). In this case, you have to do the following for each such column: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51832325"><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">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHANGE</span> c1 c1 <span class="token datatype">BLOB</span><span class="token punctuation">;</span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">CHANGE</span> c1 c1 <span class="token datatype">TEXT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">;</span></code></pre> </div> <p> The reason this works is that there is no conversion when you convert to or from <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types"> <code class="literal"> BLOB </code> </a> columns. </p> </div> <p> To change only the <span class="emphasis"> <em> default </em> </span> character set for a table, use this statement: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa17876601"><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">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span></code></pre> </div> <p> The word <code class="literal"> DEFAULT </code> is optional. The default character set is the character set that is used if you do not specify the character set for columns that you add to a table later (for example, with <code class="literal"> ALTER TABLE ... ADD column </code> ). </p> <p> When the <a class="link" href="server-system-variables.html#sysvar_foreign_key_checks"> <code class="literal"> foreign_key_checks </code> </a> system variable is enabled, which is the default setting, character set conversion is not permitted on tables that include a character string column used in a foreign key constraint. The workaround is to disable <a class="link" href="server-system-variables.html#sysvar_foreign_key_checks"> <code class="literal"> foreign_key_checks </code> </a> before performing the character set conversion. You must perform the conversion on both tables involved in the foreign key constraint before re-enabling <a class="link" href="server-system-variables.html#sysvar_foreign_key_checks"> <code class="literal"> foreign_key_checks </code> </a> . If you re-enable <a class="link" href="server-system-variables.html#sysvar_foreign_key_checks"> <code class="literal"> foreign_key_checks </code> </a> after converting only one of the tables, an <code class="literal"> ON DELETE CASCADE </code> or <code class="literal"> ON UPDATE CASCADE </code> operation could corrupt data in the referencing table due to implicit conversion that occurs during these operations (Bug #45290, Bug #74816). </p> <h4> <a name="alter-table-import"> </a> Importing InnoDB Tables </h4> <a class="indexterm" name="idm46045188809568"> </a> <a class="indexterm" name="idm46045188808496"> </a> <p> An <code class="literal"> InnoDB </code> table created in its own <a class="link" href="glossary.html#glos_file_per_table" title="file-per-table"> file-per-table </a> tablespace can be imported from a backup or from another MySQL server instance using <code class="literal"> DISCARD TABLEPACE </code> and <code class="literal"> IMPORT TABLESPACE </code> clauses. See <a class="xref" href="innodb-table-import.html" title="17.6.1.3 Importing InnoDB Tables"> Section 17.6.1.3, “Importing InnoDB Tables” </a> . </p> <h4> <a name="alter-table-row-order"> </a> Row Order for MyISAM Tables </h4> <a class="indexterm" name="idm46045188801936"> </a> <p> <code class="literal"> ORDER BY </code> enables you to create the new table with the rows in a specific order. This option is useful primarily when you know that you query the rows in a certain order most of the time. By using this option after major changes to the table, you might be able to get higher performance. In some cases, it might make sorting easier for MySQL if the table is in order by the column that you want to order it by later. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> The table does not remain in the specified order after inserts and deletes. </p> </div> <p> <code class="literal"> ORDER BY </code> syntax permits one or more column names to be specified for sorting, each of which optionally can be followed by <code class="literal"> ASC </code> or <code class="literal"> DESC </code> to indicate ascending or descending sort order, respectively. The default is ascending order. Only column names are permitted as sort criteria; arbitrary expressions are not permitted. This clause should be given last after any other clauses. </p> <p> <code class="literal"> ORDER BY </code> does not make sense for <code class="literal"> InnoDB </code> tables because <code class="literal"> InnoDB </code> always orders table rows according to the <a class="link" href="glossary.html#glos_clustered_index" title="clustered index"> clustered index </a> . </p> <p> When used on a partitioned table, <code class="literal"> ALTER TABLE ... ORDER BY </code> orders rows within each partition only. </p> <h4> <a name="alter-table-partition-options"> </a> Partitioning Options </h4> <p> <em class="replaceable"> <code> partition_options </code> </em> signifies options that can be used with partitioned tables for repartitioning, to add, drop, discard, import, merge, and split partitions, and to perform partitioning maintenance. </p> <p> It is possible for an <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement"> <code class="literal"> ALTER TABLE </code> </a> statement to contain a <code class="literal"> PARTITION BY </code> or <code class="literal"> REMOVE PARTITIONING </code> clause in an addition to other alter specifications, but the <code class="literal"> PARTITION BY </code> or <code class="literal"> REMOVE PARTITIONING </code> clause must be specified last after any other specifications. The <code class="literal"> ADD PARTITION </code> , <code class="literal"> DROP PARTITION </code> , <code class="literal"> DISCARD PARTITION </code> , <code class="literal"> IMPORT PARTITION </code> , <code class="literal"> COALESCE PARTITION </code> , <code class="literal"> REORGANIZE PARTITION </code> , <code class="literal"> EXCHANGE PARTITION </code> , <code class="literal"> ANALYZE PARTITION </code> , <code class="literal"> CHECK PARTITION </code> , and <code class="literal"> REPAIR PARTITION </code> options cannot be combined with other alter specifications in a single <code class="literal"> ALTER TABLE </code> , since the options just listed act on individual partitions. </p> <p> For more information about partition options, see <a class="xref" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> Section 15.1.20, “CREATE TABLE Statement” </a> , and <a class="xref" href="alter-table-partition-operations.html" title="15.1.9.1 ALTER TABLE Partition Operations"> Section 15.1.9.1, “ALTER TABLE Partition Operations” </a> . For information about and examples of <code class="literal"> ALTER TABLE ... EXCHANGE PARTITION </code> statements, see <a class="xref" href="partitioning-management-exchange.html" title="26.3.3 Exchanging Partitions and Subpartitions with Tables"> Section 26.3.3, “Exchanging Partitions and Subpartitions with Tables” </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/rename-user.html
<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>
https://dev.mysql.com/doc/refman/8.4/en/key-cache-restructuring.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="key-cache-restructuring"> </a> 10.10.2.6 Restructuring a Key Cache </h4> </div> </div> </div> <p> A key cache can be restructured at any time by updating its parameter values. For example: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa6346368"><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> <span class="token keyword">GLOBAL</span> cold_cache<span class="token punctuation">.</span>key_buffer_size<span class="token operator">=</span><span class="token number">4</span><span class="token operator">*</span><span class="token number">1024</span><span class="token operator">*</span><span class="token number">1024</span><span class="token punctuation">;</span></code></pre> </div> <p> If you assign to either the <a class="link" href="server-system-variables.html#sysvar_key_buffer_size"> <code class="literal"> key_buffer_size </code> </a> or <a class="link" href="server-system-variables.html#sysvar_key_cache_block_size"> <code class="literal"> key_cache_block_size </code> </a> key cache component a value that differs from the component's current value, the server destroys the cache's old structure and creates a new one based on the new values. If the cache contains any dirty blocks, the server saves them to disk before destroying and re-creating the cache. Restructuring does not occur if you change other key cache parameters. </p> <p> When restructuring a key cache, the server first flushes the contents of any dirty buffers to disk. After that, the cache contents become unavailable. However, restructuring does not block queries that need to use indexes assigned to the cache. Instead, the server directly accesses the table indexes using native file system caching. File system caching is not as efficient as using a key cache, so although queries execute, a slowdown can be anticipated. After the cache has been restructured, it becomes available again for caching indexes assigned to it, and the use of file system caching for the indexes ceases. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-replication-starting.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="mysql-cluster-replication-starting"> </a> 25.7.6 Starting NDB Cluster Replication (Single Replication Channel) </h3> </div> </div> </div> <a class="indexterm" name="idm46045086100992"> </a> <p> This section outlines the procedure for starting NDB Cluster replication using a single replication channel. </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> Start the MySQL replication source server by issuing this command, where <em class="replaceable"> <code> id </code> </em> is this server's unique ID (see <a class="xref" href="mysql-cluster-replication-general.html" title="25.7.2 General Requirements for NDB Cluster Replication"> Section 25.7.2, “General Requirements for NDB Cluster Replication” </a> ): </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa33674089"><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">shell<em class="replaceable">S</em>&gt;</span><span class="token command"> mysqld</span> <span class="token property">--ndbcluster</span> <span class="token constant">--server-id</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">id</em></span> \ <span class="token property">--log-bin</span> <span class="token property">--ndb-log-bin</span> &amp;</code></pre> </div> <p> This starts the server's <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> process with binary logging enabled using the proper logging format. It is also necessary to enable logging of updates to <code class="literal"> NDB </code> tables explicitly, using the <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_bin"> <code class="option"> --ndb-log-bin </code> </a> option. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> You can also start the source with <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format"> <code class="option"> --binlog-format=MIXED </code> </a> , in which case row-based replication is used automatically when replicating between clusters. Statement-based binary logging is not supported for NDB Cluster Replication (see <a class="xref" href="mysql-cluster-replication-general.html" title="25.7.2 General Requirements for NDB Cluster Replication"> Section 25.7.2, “General Requirements for NDB Cluster Replication” </a> ). </p> </div> </li> <li class="listitem"> <p> Start the MySQL replica server as shown here: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa81595080"><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">shell<em class="replaceable">R</em>&gt; mysqld <span class="token property">--ndbcluster</span> <span class="token constant">--server-id</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">id</em></span> &amp;</code></pre> </div> <p> In the command just shown, <em class="replaceable"> <code> id </code> </em> is the replica server's unique ID. It is not necessary to enable logging on the replica. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Unless you want replication to begin immediately, delay the start of the replication threads until the appropriate <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement"> <code class="literal"> START REPLICA </code> </a> statement has been issued, as explained in Step 4 below. You can do this by starting the replica with <a class="link" href="replication-options-replica.html#option_mysqld_skip-replica-start"> <code class="option"> --skip-replica-start </code> </a> . </p> </div> </li> <li class="listitem"> <p> It is necessary to synchronize the replica server with the source server's replication binary log. If binary logging has not previously been running on the source, run the following statement on the replica: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34464179"><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">mysql<em class="replaceable">R</em><span class="token operator">&gt;</span> <span class="token keyword">CHANGE</span> <span class="token keyword">REPLICATION</span> <span class="token keyword">SOURCE</span> <span class="token keyword">TO</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">SOURCE_LOG_FILE</span><span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> <span class="token prompt"> -&gt;</span> <span class="token keyword">SOURCE_LOG_POS</span><span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">;</span></code></pre> </div> <p> This instructs the replica to begin reading the source server's binary log from the log's starting point. Otherwise—that is, if you are loading data from the source using a backup—see <a class="xref" href="mysql-cluster-replication-failover.html" title="25.7.8 Implementing Failover with NDB Cluster Replication"> Section 25.7.8, “Implementing Failover with NDB Cluster Replication” </a> , for information on how to obtain the correct values to use for <code class="literal"> SOURCE_LOG_FILE </code> and <code class="literal"> SOURCE_LOG_POS </code> in such cases. </p> </li> <li class="listitem"> <p> Finally, instruct the replica to begin applying replication by issuing this command from 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 on the replica: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa39502227"><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">mysql<em class="replaceable">R</em><span class="token operator">&gt;</span> <span class="token keyword">START</span> <span class="token keyword">REPLICA</span><span class="token punctuation">;</span></code></pre> </div> <p> This also initiates the transmission of data and changes from the source to the replica. </p> </li> </ol> </div> <p> It is also possible to use two replication channels, in a manner similar to the procedure described in the next section; the differences between this and using a single replication channel are covered in <a class="xref" href="mysql-cluster-replication-two-channels.html" title="25.7.7 Using Two Replication Channels for NDB Cluster Replication"> Section 25.7.7, “Using Two Replication Channels for NDB Cluster Replication” </a> . </p> <a class="indexterm" name="idm46045086065488"> </a> <p> It is also possible to improve cluster replication performance by enabling <span class="firstterm"> batched updates </span> . This can be accomplished by setting the system variable <a class="link" href="mysql-cluster-options-variables.html#sysvar_replica_allow_batching"> <code class="literal"> replica_allow_batching </code> </a> on the replicas' <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server"> <span class="command"> <strong> mysqld </strong> </span> </a> processes. Normally, updates are applied as soon as they are received. However, the use of batching causes updates to be applied in batches of 32 KB each; this can result in higher throughput and less CPU usage, particularly where individual updates are relatively small. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Batching works on a per-epoch basis; updates belonging to more than one transaction can be sent as part of the same batch. </p> <p> All outstanding updates are applied when the end of an epoch is reached, even if the updates total less than 32 KB. </p> </div> <a class="indexterm" name="idm46045086058896"> </a> <a class="indexterm" name="idm46045086057824"> </a> <p> Batching can be turned on and off at runtime. To activate it at runtime, you can use either of these two statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99975536"><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">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span> <span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token keyword">ON</span><span class="token punctuation">;</span></code></pre> </div> <p> If a particular batch causes problems (such as a statement whose effects do not appear to be replicated correctly), batching can be deactivated using either of the following statements: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa30714248"><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">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token keyword">OFF</span><span class="token punctuation">;</span></code></pre> </div> <p> You can check whether batching is currently being used by means of an appropriate <a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement"> <code class="literal"> SHOW VARIABLES </code> </a> statement, like this one: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa4905650"><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">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'replica%'</span><span class="token punctuation">;</span></code></pre> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/optimizing-innodb-ddl-operations.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="optimizing-innodb-ddl-operations"> </a> 10.5.7 Optimizing InnoDB DDL Operations </h3> </div> </div> </div> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Many DDL operations on tables and indexes ( <code class="literal"> CREATE </code> , <code class="literal"> ALTER </code> , and <code class="literal"> DROP </code> statements) can be performed online. See <a class="xref" href="innodb-online-ddl.html" title="17.12 InnoDB and Online DDL"> Section 17.12, “InnoDB and Online DDL” </a> for details. </p> </li> <li class="listitem"> <p> Online DDL support for adding secondary indexes means that you can generally speed up the process of creating and loading a table and associated indexes by creating the table without secondary indexes, then adding secondary indexes after the data is loaded. </p> </li> <li class="listitem"> <p> Use <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement"> <code class="literal"> TRUNCATE TABLE </code> </a> to empty a table, not <code class="literal"> DELETE FROM <em class="replaceable"> <code> tbl_name </code> </em> </code> . Foreign key constraints can make a <code class="literal"> TRUNCATE </code> statement work like a regular <code class="literal"> DELETE </code> statement, in which case a sequence of commands like <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement"> <code class="literal"> DROP TABLE </code> </a> and <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> might be fastest. </p> </li> <li class="listitem"> <p> Because the primary key is integral to the storage layout of each <code class="literal"> InnoDB </code> table, and changing the definition of the primary key involves reorganizing the whole table, always set up the primary key as part of the <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement"> <code class="literal"> CREATE TABLE </code> </a> statement, and plan ahead so that you do not need to <code class="literal"> ALTER </code> or <code class="literal"> DROP </code> the primary key afterward. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/pluggable-storage-common-layer.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="pluggable-storage-common-layer"> </a> 18.11.2 The Common Database Server Layer </h3> </div> </div> </div> <p> A MySQL pluggable storage engine is the component in the MySQL database server that is responsible for performing the actual data I/O operations for a database as well as enabling and enforcing certain feature sets that target a specific application need. A major benefit of using specific storage engines is that you are only delivered the features needed for a particular application, and therefore you have less system overhead in the database, with the end result being more efficient and higher database performance. This is one of the reasons that MySQL has always been known to have such high performance, matching or beating proprietary monolithic databases in industry standard benchmarks. </p> <p> From a technical perspective, what are some of the unique supporting infrastructure components that are in a storage engine? Some of the key feature differentiations include: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <span class="emphasis"> <em> Concurrency </em> </span> : Some applications have more granular lock requirements (such as row-level locks) than others. Choosing the right locking strategy can reduce overhead and therefore improve overall performance. This area also includes support for capabilities such as multi-version concurrency control or <span class="quote"> “ <span class="quote"> snapshot </span> ” </span> read. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Transaction Support </em> </span> : Not every application needs transactions, but for those that do, there are very well defined requirements such as ACID compliance and more. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Referential Integrity </em> </span> : The need to have the server enforce relational database referential integrity through DDL defined foreign keys. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Physical Storage </em> </span> : This involves everything from the overall page size for tables and indexes as well as the format used for storing data to physical disk. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Index Support </em> </span> : Different application scenarios tend to benefit from different index strategies. Each storage engine generally has its own indexing methods, although some (such as B-tree indexes) are common to nearly all engines. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Memory Caches </em> </span> : Different applications respond better to some memory caching strategies than others, so although some memory caches are common to all storage engines (such as those used for user connections), others are uniquely defined only when a particular storage engine is put in play. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Performance Aids </em> </span> : This includes multiple I/O threads for parallel operations, thread concurrency, database checkpointing, bulk insert handling, and more. </p> </li> <li class="listitem"> <p> <span class="emphasis"> <em> Miscellaneous Target Features </em> </span> : This may include support for geospatial operations, security restrictions for certain data manipulation operations, and other similar features. </p> </li> </ul> </div> <p> Each set of the pluggable storage engine infrastructure components are designed to offer a selective set of benefits for a particular application. Conversely, avoiding a set of component features helps reduce unnecessary overhead. It stands to reason that understanding a particular application's set of requirements and selecting the proper MySQL storage engine can have a dramatic impact on overall system efficiency and performance. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/updating-apt-repo.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h2 class="title"> <a name="updating-apt-repo"> </a> 3.9 Upgrading MySQL with the MySQL APT Repository </h2> </div> </div> </div> <a class="indexterm" name="idm46045325938368"> </a> <a class="indexterm" name="idm46045325937328"> </a> <p> On Debian and Ubuntu platforms, to perform an in-place upgrade of MySQL and its components, use the MySQL APT repository. See <a class="xref" href="linux-installation-apt-repo.html#repo-qg-apt-upgrading" title="Upgrading MySQL with the MySQL APT Repository"> Upgrading MySQL with the MySQL APT Repository </a> . </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/reset-binary-logs-and-gtids.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="reset-binary-logs-and-gtids"> </a> 15.4.1.2 RESET BINARY LOGS AND GTIDS Statement </h4> </div> </div> </div> <a class="indexterm" name="idm46045177855152"> </a> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> This statement takes the place of the old <code class="literal"> RESET MASTER </code> statement, which is no longer supported. </p> </div> <div class="copytoclipboard-wrapper"> <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa89060994"><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">RESET</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token operator">AND</span> GTIDS <span class="token punctuation">[</span><span class="token keyword">TO</span> <em class="replaceable">binary_log_file_index_number</em><span class="token punctuation">]</span></code></pre> </div> <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Warning </div> <p> Use this statement with caution to ensure you do not lose any wanted binary log file data and GTID execution history. </p> </div> <p> <code class="literal"> RESET BINARY LOGS AND GTIDS </code> requires the <a class="link" href="privileges-provided.html#priv_reload"> <code class="literal"> RELOAD </code> </a> privilege. </p> <p> For a server where binary logging is enabled ( <a class="link" href="replication-options-binary-log.html#sysvar_log_bin"> <code class="literal"> log_bin </code> </a> is <code class="literal"> ON </code> ), <code class="literal"> RESET BINARY LOGS AND GTIDS </code> deletes all existing binary log files and resets the binary log index file, resetting the server to its state before binary logging was started. A new empty binary log file is created so that binary logging can be restarted. </p> <p> For a server where GTIDs are in use ( <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode"> <code class="literal"> gtid_mode </code> </a> is <code class="literal"> ON </code> ), issuing <code class="literal"> RESET BINARY LOGS AND GTIDS </code> resets the GTID execution history. The value of the <a class="link" href="replication-options-gtids.html#sysvar_gtid_purged"> <code class="literal"> gtid_purged </code> </a> system variable is set to an empty string ( <code class="literal"> '' </code> ), the global value (but not the session value) of the <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed"> <code class="literal"> gtid_executed </code> </a> system variable is set to an empty string, and the <code class="literal"> mysql.gtid_executed </code> table is cleared (see <a class="xref" href="replication-gtids-concepts.html#replication-gtids-gtid-executed-table" title="mysql.gtid_executed Table"> mysql.gtid_executed Table </a> ). If the GTID-enabled server has binary logging enabled, <code class="literal"> RESET BINARY LOGS AND GTIDS </code> also resets the binary log as described above. Note that <code class="literal"> RESET BINARY LOGS AND GTIDS </code> is the method to reset the GTID execution history even if the GTID-enabled server is a replica where binary logging is disabled; <a class="link" href="reset-replica.html" title="15.4.2.3 RESET REPLICA Statement"> <code class="literal"> RESET REPLICA </code> </a> has no effect on the GTID execution history. For more information on resetting the GTID execution history, see <a class="xref" href="replication-gtids-lifecycle.html#replication-gtids-execution-history" title="Resetting the GTID Execution History"> Resetting the GTID Execution History </a> . </p> <p> Issuing <code class="literal"> RESET BINARY LOGS AND GTIDS </code> without the optional <code class="literal"> TO </code> clause deletes all binary log files listed in the index file, resets the binary log index file to be empty, and creates a new binary log file starting at <code class="literal"> 1 </code> . Use the optional <code class="literal"> TO </code> clause to start the binary log file index from a number other than <code class="literal"> 1 </code> after the reset. </p> <p> Check that you are using a reasonable value for the index number. If you enter an incorrect value, you can correct this by issuing another <code class="literal"> RESET BINARY LOGS AND GTIDS </code> statement with or without the <code class="literal"> TO </code> clause. If you do not correct a value that is out of range, the server cannot be restarted. </p> <p> The following example demonstrates <code class="literal"> TO </code> clause usage: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74476384"><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">RESET</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token operator">AND</span> GTIDS <span class="token keyword">TO</span> <span class="token number">1234</span><span class="token punctuation">;</span> <span class="token keyword">SHOW</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</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> <span class="token output"><span class="token punctuation">|</span> Log_name <span class="token punctuation">|</span> File_size <span class="token punctuation">|</span> Encrypted <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> <span class="token output"><span class="token punctuation">|</span> source<span class="token punctuation">-</span>bin.001234 <span class="token punctuation">|</span> 154 <span class="token punctuation">|</span> No <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></code></pre> </div> <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Important </div> <p> The effects of <code class="literal"> RESET BINARY LOGS AND GTIDS </code> without the <code class="literal"> TO </code> clause differ from those of <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> <code class="literal"> PURGE BINARY LOGS </code> </a> in 2 key ways: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> <code class="literal"> RESET BINARY LOGS AND GTIDS </code> removes <span class="emphasis"> <em> all </em> </span> binary log files that are listed in the index file, leaving only a single, empty binary log file with a numeric suffix of <code class="literal"> .000001 </code> , whereas the numbering is not reset by <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> <code class="literal"> PURGE BINARY LOGS </code> </a> . </p> </li> <li class="listitem"> <p> <code class="literal"> RESET BINARY LOGS AND GTIDS </code> is <span class="emphasis"> <em> not </em> </span> intended to be used while any replicas are running. The behavior of <code class="literal"> RESET BINARY LOGS AND GTIDS </code> when used while replicas are running is undefined (and thus unsupported), whereas <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> <code class="literal"> PURGE BINARY LOGS </code> </a> may be safely used while replicas are running. </p> </li> </ol> </div> <p> See also <a class="xref" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement"> Section 15.4.1.1, “PURGE BINARY LOGS Statement” </a> . </p> </div> <p> <code class="literal"> RESET BINARY LOGS AND GTIDS </code> without the <code class="literal"> TO </code> clause can prove useful when you first set up a source and replica, so that you can verify the setup as follows: </p> <div class="orderedlist"> <ol class="orderedlist" type="1"> <li class="listitem"> <p> Start the source and replica, and start replication (see <a class="xref" href="replication-howto.html" title="19.1.2 Setting Up Binary Log File Position Based Replication"> Section 19.1.2, “Setting Up Binary Log File Position Based Replication” </a> ). </p> </li> <li class="listitem"> <p> Execute a few test queries on the source. </p> </li> <li class="listitem"> <p> Check that the queries were replicated to the replica. </p> </li> <li class="listitem"> <p> When replication is running correctly, issue <a class="link" href="stop-replica.html" title="15.4.2.5 STOP REPLICA Statement"> <code class="literal"> STOP REPLICA </code> </a> followed by <a class="link" href="reset-replica.html" title="15.4.2.3 RESET REPLICA Statement"> <code class="literal"> RESET REPLICA </code> </a> (both on the replica), then verify that no unwanted data from the test queries exists on the replica. Following this, issue <code class="literal"> RESET BINARY LOGS AND GTIDS </code> (also on the replica) to remove binary logs and and associated transaction IDs. </p> </li> <li class="listitem"> <p> Remove the unwanted data from the source, then issue <code class="literal"> RESET BINARY LOGS AND GTIDS </code> to purge any binary log entries and identifiers associated with it. </p> </li> </ol> </div> <p> After verifying the setup, resetting the source and replica and ensuring that no unwanted data or binary log files generated by testing remain on the source or replica, you can start the replica and begin replicating. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/sys-innodb-buffer-stats-by-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="sys-innodb-buffer-stats-by-table"> </a> 30.4.3.8 The innodb_buffer_stats_by_table and x$innodb_buffer_stats_by_table Views </h4> </div> </div> </div> <a class="indexterm" name="idm46045063164736"> </a> <a class="indexterm" name="idm46045063163280"> </a> <a class="indexterm" name="idm46045063161776"> </a> <a class="indexterm" name="idm46045063160272"> </a> <p> These views summarize the information in the <code class="literal"> INFORMATION_SCHEMA </code> <a class="link" href="information-schema-innodb-buffer-page-table.html" title="28.4.2 The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table"> <code class="literal"> INNODB_BUFFER_PAGE </code> </a> table, grouped by schema and table. By default, rows are sorted by descending buffer size. </p> <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Warning </div> <p> Querying views that access the <a class="link" href="information-schema-innodb-buffer-page-table.html" title="28.4.2 The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table"> <code class="literal"> INNODB_BUFFER_PAGE </code> </a> table can affect performance. Do not query these views on a production system unless you are aware of the performance impact and have determined it to be acceptable. To avoid impacting performance on a production system, reproduce the issue you want to investigate and query buffer pool statistics on a test instance. </p> </div> <p> The <a class="link" href="sys-innodb-buffer-stats-by-table.html" title="30.4.3.8 The innodb_buffer_stats_by_table and x$innodb_buffer_stats_by_table Views"> <code class="literal"> innodb_buffer_stats_by_table </code> </a> and <a class="link" href="sys-innodb-buffer-stats-by-table.html" title="30.4.3.8 The innodb_buffer_stats_by_table and x$innodb_buffer_stats_by_table Views"> <code class="literal"> x$innodb_buffer_stats_by_table </code> </a> views have these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> object_schema </code> </p> <p> The schema name for the object, or <code class="literal"> InnoDB System </code> if the table belongs to the <code class="literal"> InnoDB </code> storage engine. </p> </li> <li class="listitem"> <p> <code class="literal"> object_name </code> </p> <p> The table name. </p> </li> <li class="listitem"> <p> <code class="literal"> allocated </code> </p> <p> The total number of bytes allocated for the table. </p> </li> <li class="listitem"> <p> <code class="literal"> data </code> </p> <p> The number of data bytes allocated for the table. </p> </li> <li class="listitem"> <p> <code class="literal"> pages </code> </p> <p> The total number of pages allocated for the table. </p> </li> <li class="listitem"> <p> <code class="literal"> pages_hashed </code> </p> <p> The number of hashed pages allocated for the table. </p> </li> <li class="listitem"> <p> <code class="literal"> pages_old </code> </p> <p> The number of old pages allocated for the table. </p> </li> <li class="listitem"> <p> <code class="literal"> rows_cached </code> </p> <p> The number of cached rows for the table. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-ndbinfo-table-fragments.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h4 class="title"> <a name="mysql-cluster-ndbinfo-table-fragments"> </a> 25.6.17.58 The ndbinfo table_fragments Table </h4> </div> </div> </div> <a class="indexterm" name="idm46045087730832"> </a> <p> The <code class="literal"> table_fragments </code> table provides information about the fragmentation, partitioning, distribution, and (internal) replication of <code class="literal"> NDB </code> tables. </p> <p> The <code class="literal"> table_fragments </code> table contains the following columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> node_id </code> </p> <p> Node ID ( <a class="ulink" href="/doc/ndb-internals/en/ndb-internals-kernel-blocks-dbdih.html" target="_top"> <code class="literal"> DIH </code> </a> master) </p> </li> <li class="listitem"> <p> <code class="literal"> table_id </code> </p> <p> Table ID </p> </li> <li class="listitem"> <p> <code class="literal"> partition_id </code> </p> <p> Partition ID </p> </li> <li class="listitem"> <p> <code class="literal"> fragment_id </code> </p> <p> Fragment ID (same as partition ID unless table is fully replicated) </p> </li> <li class="listitem"> <p> <code class="literal"> partition_order </code> </p> <p> Order of fragment in partition </p> </li> <li class="listitem"> <p> <code class="literal"> log_part_id </code> </p> <p> Log part ID of fragment </p> </li> <li class="listitem"> <p> <code class="literal"> no_of_replicas </code> </p> <p> Number of fragment replicas </p> </li> <li class="listitem"> <p> <code class="literal"> current_primary </code> </p> <p> Current primary node ID </p> </li> <li class="listitem"> <p> <code class="literal"> preferred_primary </code> </p> <p> Preferred primary node ID </p> </li> <li class="listitem"> <p> <code class="literal"> current_first_backup </code> </p> <p> Current first backup node ID </p> </li> <li class="listitem"> <p> <code class="literal"> current_second_backup </code> </p> <p> Current second backup node ID </p> </li> <li class="listitem"> <p> <code class="literal"> current_third_backup </code> </p> <p> Current third backup node ID </p> </li> <li class="listitem"> <p> <code class="literal"> num_alive_replicas </code> </p> <p> Current number of live fragment replicas </p> </li> <li class="listitem"> <p> <code class="literal"> num_dead_replicas </code> </p> <p> Current number of dead fragment replicas </p> </li> <li class="listitem"> <p> <code class="literal"> num_lcp_replicas </code> </p> <p> Number of fragment replicas remaining to be checkpointed </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/information-schema-innodb-foreign-table.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="information-schema-innodb-foreign-table"> </a> 28.4.12 The INFORMATION_SCHEMA INNODB_FOREIGN Table </h3> </div> </div> </div> <a class="indexterm" name="idm46045077035104"> </a> <p> The <a class="link" href="information-schema-innodb-foreign-table.html" title="28.4.12 The INFORMATION_SCHEMA INNODB_FOREIGN Table"> <code class="literal"> INNODB_FOREIGN </code> </a> table provides metadata about <code class="literal"> InnoDB </code> <a class="link" href="glossary.html#glos_foreign_key" title="foreign key"> foreign keys </a> . </p> <p> For related usage information and examples, see <a class="xref" href="innodb-information-schema-system-tables.html" title="17.15.3 InnoDB INFORMATION_SCHEMA Schema Object Tables"> Section 17.15.3, “InnoDB INFORMATION_SCHEMA Schema Object Tables” </a> . </p> <p> The <a class="link" href="information-schema-innodb-foreign-table.html" title="28.4.12 The INFORMATION_SCHEMA INNODB_FOREIGN Table"> <code class="literal"> INNODB_FOREIGN </code> </a> table has these columns: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <code class="literal"> ID </code> </p> <p> The name (not a numeric value) of the foreign key index, preceded by the schema (database) name (for example, <code class="literal"> test/products_fk </code> ). </p> </li> <li class="listitem"> <p> <code class="literal"> FOR_NAME </code> </p> <p> The name of the <a class="link" href="glossary.html#glos_child_table" title="child table"> child table </a> in this foreign key relationship. </p> </li> <li class="listitem"> <p> <code class="literal"> REF_NAME </code> </p> <p> The name of the <a class="link" href="glossary.html#glos_parent_table" title="parent table"> parent table </a> in this foreign key relationship. </p> </li> <li class="listitem"> <p> <code class="literal"> N_COLS </code> </p> <p> The number of columns in the foreign key index. </p> </li> <li class="listitem"> <p> <code class="literal"> TYPE </code> </p> <p> A collection of bit flags with information about the foreign key column, ORed together. 0 = <code class="literal"> ON DELETE/UPDATE RESTRICT </code> , 1 = <code class="literal"> ON DELETE CASCADE </code> , 2 = <code class="literal"> ON DELETE SET NULL </code> , 4 = <code class="literal"> ON UPDATE CASCADE </code> , 8 = <code class="literal"> ON UPDATE SET NULL </code> , 16 = <code class="literal"> ON DELETE NO ACTION </code> , 32 = <code class="literal"> ON UPDATE NO ACTION </code> . </p> </li> </ul> </div> <h4> <a name="idm46045077010016"> </a> Example </h4> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa609264"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>INNODB_FOREIGN\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> ID<span class="token punctuation">:</span> test/fk1 FOR_NAME<span class="token punctuation">:</span> test/child REF_NAME<span class="token punctuation">:</span> test/parent N_COLS<span class="token punctuation">:</span> 1 TYPE<span class="token punctuation">:</span> 1</span></code></pre> </div> <h4> <a name="idm46045077007520"> </a> Notes </h4> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> You must have the <a class="link" href="privileges-provided.html#priv_process"> <code class="literal"> PROCESS </code> </a> privilege to query this table. </p> </li> <li class="listitem"> <p> Use the <code class="literal"> INFORMATION_SCHEMA </code> <a class="link" href="information-schema-columns-table.html" title="28.3.8 The INFORMATION_SCHEMA COLUMNS Table"> <code class="literal"> COLUMNS </code> </a> table or the <a class="link" href="show-columns.html" title="15.7.7.6 SHOW COLUMNS Statement"> <code class="literal"> SHOW COLUMNS </code> </a> statement to view additional information about the columns of this table, including data types and default values. </p> </li> </ul> </div> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/information-schema-optimization.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="information-schema-optimization"> </a> 10.2.3 Optimizing INFORMATION_SCHEMA Queries </h3> </div> </div> </div> <a class="indexterm" name="idm46045227782048"> </a> <a class="indexterm" name="idm46045227780544"> </a> <p> Applications that monitor databases may make frequent use of <code class="literal"> INFORMATION_SCHEMA </code> tables. To write queries for these tables most efficiently, use the following general guidelines: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> Try to query only <code class="literal"> INFORMATION_SCHEMA </code> tables that are views on data dictionary tables. </p> </li> <li class="listitem"> <p> Try to query only for static metadata. Selecting columns or using retrieval conditions for dynamic metadata along with static metadata adds overhead to process the dynamic metadata. </p> </li> </ul> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> Comparison behavior for database and table names in <code class="literal"> INFORMATION_SCHEMA </code> queries might differ from what you expect. For details, see <a class="xref" href="charset-collation-information-schema.html" title="12.8.7 Using Collation in INFORMATION_SCHEMA Searches"> Section 12.8.7, “Using Collation in INFORMATION_SCHEMA Searches” </a> . </p> </div> <p> These <code class="literal"> INFORMATION_SCHEMA </code> tables are implemented as views on data dictionary tables, so queries on them retrieve information from the data dictionary: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa87620233"><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-none">CHARACTER_SETS CHECK_CONSTRAINTS COLLATIONS COLLATION_CHARACTER_SET_APPLICABILITY COLUMNS EVENTS FILES INNODB_COLUMNS INNODB_DATAFILES INNODB_FIELDS INNODB_FOREIGN INNODB_FOREIGN_COLS INNODB_INDEXES INNODB_TABLES INNODB_TABLESPACES INNODB_TABLESPACES_BRIEF INNODB_TABLESTATS KEY_COLUMN_USAGE PARAMETERS PARTITIONS REFERENTIAL_CONSTRAINTS RESOURCE_GROUPS ROUTINES SCHEMATA STATISTICS TABLES TABLE_CONSTRAINTS TRIGGERS VIEWS VIEW_ROUTINE_USAGE VIEW_TABLE_USAGE</code></pre> </div> <p> Some types of values, even for a non-view <code class="literal"> INFORMATION_SCHEMA </code> table, are retrieved by lookups from the data dictionary. This includes values such as database and table names, table types, and storage engines. </p> <p> Some <code class="literal"> INFORMATION_SCHEMA </code> tables contain columns that provide table statistics: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-none"><div class="docs-select-all right" id="sa81222058"><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-none">STATISTICS.CARDINALITY TABLES.AUTO_INCREMENT TABLES.AVG_ROW_LENGTH TABLES.CHECKSUM TABLES.CHECK_TIME TABLES.CREATE_TIME TABLES.DATA_FREE TABLES.DATA_LENGTH TABLES.INDEX_LENGTH TABLES.MAX_DATA_LENGTH TABLES.TABLE_ROWS TABLES.UPDATE_TIME</code></pre> </div> <p> Those columns represent dynamic table metadata; that is, information that changes as table contents change. </p> <p> By default, MySQL retrieves cached values for those columns from the <code class="literal"> mysql.index_stats </code> and <code class="literal"> mysql.innodb_table_stats </code> dictionary tables when the columns are queried, which is more efficient than retrieving statistics directly from the storage engine. If cached statistics are not available or have expired, MySQL retrieves the latest statistics from the storage engine and caches them in the <code class="literal"> mysql.index_stats </code> and <code class="literal"> mysql.innodb_table_stats </code> dictionary tables. Subsequent queries retrieve the cached statistics until the cached statistics expire. A server restart or the first opening of the <code class="literal"> mysql.index_stats </code> and <code class="literal"> mysql.innodb_table_stats </code> tables do not update cached statistics automatically. </p> <p> The <a class="link" href="server-system-variables.html#sysvar_information_schema_stats_expiry"> <code class="literal"> information_schema_stats_expiry </code> </a> session variable defines the period of time before cached statistics expire. The default is 86400 seconds (24 hours), but the time period can be extended to as much as one year. </p> <p> To update cached values at any time for a given table, use <a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement"> <code class="literal"> ANALYZE TABLE </code> </a> . </p> <p> Querying statistics columns does not store or update statistics in the <code class="literal"> mysql.index_stats </code> and <code class="literal"> mysql.innodb_table_stats </code> dictionary tables under these circumstances: </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> When cached statistics have not expired. </p> </li> <li class="listitem"> <p> When <a class="link" href="server-system-variables.html#sysvar_information_schema_stats_expiry"> <code class="literal"> information_schema_stats_expiry </code> </a> is set to 0. </p> </li> <li class="listitem"> <p> When the server is in <a class="link" href="server-system-variables.html#sysvar_read_only"> <code class="literal"> read_only </code> </a> , <a class="link" href="server-system-variables.html#sysvar_super_read_only"> <code class="literal"> super_read_only </code> </a> , <a class="link" href="server-system-variables.html#sysvar_transaction_read_only"> <code class="literal"> transaction_read_only </code> </a> , or <a class="link" href="innodb-parameters.html#sysvar_innodb_read_only"> <code class="literal"> innodb_read_only </code> </a> mode. </p> </li> <li class="listitem"> <p> When the query also fetches Performance Schema data. </p> </li> </ul> </div> <p> <a class="link" href="server-system-variables.html#sysvar_information_schema_stats_expiry"> <code class="literal"> information_schema_stats_expiry </code> </a> is a session variable, and each client session can define its own expiration value. Statistics that are retrieved from the storage engine and cached by one session are available to other sessions. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <div class="admon-title"> Note </div> <p> If the <a class="link" href="innodb-parameters.html#sysvar_innodb_read_only"> <code class="literal"> innodb_read_only </code> </a> system variable is enabled, <a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement"> <code class="literal"> ANALYZE TABLE </code> </a> may fail because it cannot update statistics tables in the data dictionary, which use <code class="literal"> InnoDB </code> . For <a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement"> <code class="literal"> ANALYZE TABLE </code> </a> operations that update the key distribution, failure may occur even if the operation updates the table itself (for example, if it is a <code class="literal"> MyISAM </code> table). To obtain the updated distribution statistics, set <a class="link" href="server-system-variables.html#sysvar_information_schema_stats_expiry"> <code class="literal"> information_schema_stats_expiry=0 </code> </a> . </p> </div> <p> For <code class="literal"> INFORMATION_SCHEMA </code> tables implemented as views on data dictionary tables, indexes on the underlying data dictionary tables permit the optimizer to construct efficient query execution plans. To see the choices made by the optimizer, use <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN </code> </a> . To also see the query used by the server to execute an <code class="literal"> INFORMATION_SCHEMA </code> query, use <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement"> <code class="literal"> SHOW WARNINGS </code> </a> immediately following <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN </code> </a> . </p> <p> Consider this statement, which identifies collations for the <code class="literal"> utf8mb4 </code> character set: </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43829076"><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">SELECT</span> COLLATION_NAME <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>COLLATION_CHARACTER_SET_APPLICABILITY <span class="token keyword">WHERE</span> CHARACTER_SET_NAME <span class="token operator">=</span> <span class="token string">'utf8mb4'</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> <span class="token output"><span class="token punctuation">|</span> COLLATION_NAME <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> <span class="token output"><span class="token punctuation">|</span> utf8mb4_general_ci <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> utf8mb4_bin <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> utf8mb4_unicode_ci <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> utf8mb4_icelandic_ci <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> utf8mb4_latvian_ci <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> utf8mb4_romanian_ci <span class="token punctuation">|</span></span> <span class="token output"><span class="token punctuation">|</span> utf8mb4_slovenian_ci <span class="token punctuation">|</span></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre> </div> <p> How does the server process that statement? To find out, use <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement"> <code class="literal"> EXPLAIN </code> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa4207036"><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">EXPLAIN</span> <span class="token keyword">SELECT</span> COLLATION_NAME <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>COLLATION_CHARACTER_SET_APPLICABILITY <span class="token keyword">WHERE</span> CHARACTER_SET_NAME <span class="token operator">=</span> <span class="token string">'utf8mb4'</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> id<span class="token punctuation">:</span> 1 select_type<span class="token punctuation">:</span> SIMPLE table<span class="token punctuation">:</span> cs partitions<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> const possible_keys<span class="token punctuation">:</span> PRIMARY,name key<span class="token punctuation">:</span> name key_len<span class="token punctuation">:</span> 194 ref<span class="token punctuation">:</span> const rows<span class="token punctuation">:</span> 1 filtered<span class="token punctuation">:</span> 100.00 Extra<span class="token punctuation">:</span> Using index <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 2. 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> id<span class="token punctuation">:</span> 1 select_type<span class="token punctuation">:</span> SIMPLE table<span class="token punctuation">:</span> col partitions<span class="token punctuation">:</span> NULL type<span class="token punctuation">:</span> ref possible_keys<span class="token punctuation">:</span> character_set_id key<span class="token punctuation">:</span> character_set_id key_len<span class="token punctuation">:</span> 8 ref<span class="token punctuation">:</span> const rows<span class="token punctuation">:</span> 68 filtered<span class="token punctuation">:</span> 100.00 Extra<span class="token punctuation">:</span> NULL </span><span class="token output">2 rows in set, 1 warning (0.01 sec)</span></code></pre> </div> <p> To see the query used to satisfy that statement, use <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement"> <code class="literal"> SHOW WARNINGS </code> </a> : </p> <div class="copytoclipboard-wrapper"> <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17703466"><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">WARNINGS</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> Level<span class="token punctuation">:</span> Note Code<span class="token punctuation">:</span> 1003 Message<span class="token punctuation">:</span> /<span class="token punctuation">*</span> select#1 <span class="token punctuation">*</span>/ select `mysql`.`col`.`name` AS `COLLATION_NAME` from `mysql`.`character_sets` `cs` join `mysql`.`collations` `col` where ((`mysql`.`col`.`character_set_id` = '45') and ('utf8mb4' = 'utf8mb4'))</span></code></pre> </div> <p> As indicated by <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement"> <code class="literal"> SHOW WARNINGS </code> </a> , the server handles the query on <a class="link" href="information-schema-collation-character-set-applicability-table.html" title="28.3.7 The INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY Table"> <code class="literal"> COLLATION_CHARACTER_SET_APPLICABILITY </code> </a> as a query on the <code class="literal"> character_sets </code> and <code class="literal"> collations </code> data dictionary tables in the <code class="literal"> mysql </code> system database. </p> </div> <br/> </div>
https://dev.mysql.com/doc/refman/8.4/en/event-scheduler-thread-states.html
<div id="docs-body"> <div class="section"> <div class="titlepage"> <div> <div> <h3 class="title"> <a name="event-scheduler-thread-states"> </a> 10.14.9 Event Scheduler Thread States </h3> </div> </div> </div> <a class="indexterm" name="idm46045220941504"> </a> <a class="indexterm" name="idm46045220940016"> </a> <p> These states occur for the Event Scheduler thread, threads that are created to execute scheduled events, or threads that terminate the scheduler. </p> <div class="itemizedlist"> <ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"> <p> <a class="indexterm" name="idm46045220937184"> </a> <a class="indexterm" name="idm46045220935696"> </a> <code class="literal"> Clearing </code> </p> <p> The scheduler thread or a thread that was executing an event is terminating and is about to end. </p> </li> <li class="listitem"> <p> <a class="indexterm" name="idm46045220932224"> </a> <a class="indexterm" name="idm46045220930736"> </a> <code class="literal"> Initialized </code> </p> <p> The scheduler thread or a thread that executes an event has been initialized. </p> </li> <li class="listitem"> <p> <a class="indexterm" name="idm46045220927280"> </a> <a class="indexterm" name="idm46045220925776"> </a> <code class="literal"> Waiting for next activation </code> </p> <p> The scheduler has a nonempty event queue but the next activation is in the future. </p> </li> <li class="listitem"> <p> <a class="indexterm" name="idm46045220922288"> </a> <a class="indexterm" name="idm46045220920784"> </a> <code class="literal"> Waiting for scheduler to stop </code> </p> <p> The thread issued <code class="literal"> SET GLOBAL event_scheduler=OFF </code> and is waiting for the scheduler to stop. </p> </li> <li class="listitem"> <p> <a class="indexterm" name="idm46045220916576"> </a> <a class="indexterm" name="idm46045220915088"> </a> <code class="literal"> Waiting on empty queue </code> </p> <p> The scheduler's event queue is empty and it is sleeping. </p> </li> </ul> </div> </div> <br/> </div>