url
stringlengths 45
122
| content
stringlengths 380
3.07M
|
---|---|
https://dev.mysql.com/doc/refman/8.4/en/drop-function-loadable.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="drop-function-loadable">
</a>
15.7.4.2 DROP FUNCTION Statement for Loadable Functions
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045171838928">
</a>
<a class="indexterm" name="idm46045171837888">
</a>
<a class="indexterm" name="idm46045171836400">
</a>
<a class="indexterm" name="idm46045171834912">
</a>
<a class="indexterm" name="idm46045171833424">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa63028367"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">FUNCTION</span> <span class="token punctuation">[</span><span class="token keyword">IF</span> <span class="token keyword">EXISTS</span><span class="token punctuation">]</span> <em class="replaceable">function_name</em></code></pre>
</div>
<p>
This statement drops the loadable function named
<em class="replaceable">
<code>
function_name
</code>
</em>
. (
<code class="literal">
DROP
FUNCTION
</code>
is also used to drop stored functions; see
<a class="xref" href="drop-procedure.html" title="15.1.29 DROP PROCEDURE and DROP FUNCTION Statements">
Section 15.1.29, “DROP PROCEDURE and DROP FUNCTION Statements”
</a>
.)
</p>
<p>
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
is the complement of
<a class="link" href="create-function-loadable.html" title="15.7.4.1 CREATE FUNCTION Statement for Loadable Functions">
<code class="literal">
CREATE
FUNCTION
</code>
</a>
. It requires the
<a class="link" href="privileges-provided.html#priv_delete">
<code class="literal">
DELETE
</code>
</a>
privilege for the
<code class="literal">
mysql
</code>
system schema because it removes the
row from the
<code class="literal">
mysql.func
</code>
system table that
registers the function.
</p>
<p>
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
also removes the function from the
Performance Schema
<a class="link" href="performance-schema-user-defined-functions-table.html" title="29.12.22.10 The user_defined_functions Table">
<code class="literal">
user_defined_functions
</code>
</a>
table that
provides runtime information about installed loadable functions.
See
<a class="xref" href="performance-schema-user-defined-functions-table.html" title="29.12.22.10 The user_defined_functions Table">
Section 29.12.22.10, “The user_defined_functions Table”
</a>
.
</p>
<p>
During the normal startup sequence, the server loads functions
registered in the
<code class="literal">
mysql.func
</code>
table. Because
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
removes the
<code class="literal">
mysql.func
</code>
row
for the dropped function, the server does not load the function
during subsequent restarts.
</p>
<p>
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
cannot be used to drop a loadable function
that is installed automatically by components or plugins rather
than by using
<a class="link" href="create-function-loadable.html" title="15.7.4.1 CREATE FUNCTION Statement for Loadable Functions">
<code class="literal">
CREATE
FUNCTION
</code>
</a>
. Such a function is also dropped
automatically, when the component or plugin that installed it is
uninstalled.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
To upgrade the shared library associated with a loadable
function, issue a
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
statement, upgrade the shared library, and
then issue a
<a class="link" href="create-function-loadable.html" title="15.7.4.1 CREATE FUNCTION Statement for Loadable Functions">
<code class="literal">
CREATE
FUNCTION
</code>
</a>
statement. If you upgrade the shared
library first and then use
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
, the server may unexpectedly shut down.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/comp-err.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="comp-err">
</a>
6.4.1 comp_err — Compile MySQL Error Message File
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045320862800">
</a>
<p>
<a class="link" href="comp-err.html" title="6.4.1 comp_err — Compile MySQL Error Message File">
<span class="command">
<strong>
comp_err
</strong>
</span>
</a>
creates the
<code class="filename">
errmsg.sys
</code>
file that is used by
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
to determine the error messages to
display for different error codes.
<a class="link" href="comp-err.html" title="6.4.1 comp_err — Compile MySQL Error Message File">
<span class="command">
<strong>
comp_err
</strong>
</span>
</a>
normally is run automatically when MySQL is built. It compiles
the
<code class="filename">
errmsg.sys
</code>
file from text-format error
information in MySQL source distributions:
</p>
<p>
The error information comes from the
<code class="filename">
messages_to_error_log.txt
</code>
and
<code class="filename">
messages_to_clients.txt
</code>
files in the
<code class="filename">
share
</code>
directory.
</p>
<p>
For more information about defining error messages, see the
comments within those files, along with the
<code class="filename">
errmsg_readme.txt
</code>
file.
</p>
<p>
<a class="link" href="comp-err.html" title="6.4.1 comp_err — Compile MySQL Error Message File">
<span class="command">
<strong>
comp_err
</strong>
</span>
</a>
also generates the
<code class="filename">
mysqld_error.h
</code>
,
<code class="filename">
mysqld_ername.h
</code>
, and
<code class="filename">
mysqld_errmsg.h
</code>
header files.
</p>
<p>
Invoke
<a class="link" href="comp-err.html" title="6.4.1 comp_err — Compile MySQL Error Message File">
<span class="command">
<strong>
comp_err
</strong>
</span>
</a>
like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa63995148"><div class="copy-help left">Press ⌘+C to 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">comp_err <span class="token punctuation">[</span><em class="replaceable">options</em><span class="token punctuation">]</span></code></pre>
</div>
<p>
<a class="link" href="comp-err.html" title="6.4.1 comp_err — Compile MySQL Error Message File">
<span class="command">
<strong>
comp_err
</strong>
</span>
</a>
supports the following options.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_comp_err_help">
</a>
<a class="link" href="comp-err.html#option_comp_err_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>
<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="idm46045320830944">
</a>
<a class="indexterm" name="idm46045320829456">
</a>
<p>
Display a help message and exit.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_charset">
</a>
<a class="link" href="comp-err.html#option_comp_err_charset">
<code class="option">
--charset=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
,
<code class="option">
-C
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for charset">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--charset
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
../share/charsets
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320814272">
</a>
<a class="indexterm" name="idm46045320812784">
</a>
<p>
The character set directory. The default is
<code class="filename">
../sql/share/charsets
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_debug">
</a>
<a class="link" href="comp-err.html#option_comp_err_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=options
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
d:t:O,/tmp/comp_err.trace
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320796864">
</a>
<a class="indexterm" name="idm46045320795376">
</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,/tmp/comp_err.trace
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_debug-info">
</a>
<a class="link" href="comp-err.html#option_comp_err_debug-info">
<code class="option">
--debug-info
</code>
</a>
,
<code class="option">
-T
</code>
</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="idm46045320778368">
</a>
<a class="indexterm" name="idm46045320776880">
</a>
<p>
Print some debugging information when the program exits.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_errmsg-file">
</a>
<a class="link" href="comp-err.html#option_comp_err_errmsg-file">
<code class="option">
--errmsg-file=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
,
<code class="option">
-H
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for errmsg-file">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--errmsg-file=name
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
mysqld_errmsg.h
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320761488">
</a>
<a class="indexterm" name="idm46045320760000">
</a>
<p>
The name of the error message file. The default is
<code class="filename">
mysqld_errmsg.h
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_header-file">
</a>
<a class="link" href="comp-err.html#option_comp_err_header-file">
<code class="option">
--header-file=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
,
<code class="option">
-H
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for header-file">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--header-file=name
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
mysqld_error.h
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320744048">
</a>
<a class="indexterm" name="idm46045320742560">
</a>
<p>
The name of the error header file. The default is
<code class="filename">
mysqld_error.h
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_in-file-errlog">
</a>
<a class="link" href="comp-err.html#option_comp_err_in-file-errlog">
<code class="option">
--in-file-errlog=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
,
<code class="option">
-e
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for in-file-errlog">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--in-file-errlog
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
../share/messages_to_error_log.txt
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320726480">
</a>
<a class="indexterm" name="idm46045320724992">
</a>
<p>
The name of the input file that defines error messages
intended to be written to the error log. The default is
<code class="filename">
../share/messages_to_error_log.txt
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_in-file-toclient">
</a>
<a class="link" href="comp-err.html#option_comp_err_in-file-toclient">
<code class="option">
--in-file-toclient=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
,
<code class="option">
-c
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for in-file-toclient">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--in-file-toclient=path
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
../share/messages_to_clients.txt
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320708896">
</a>
<a class="indexterm" name="idm46045320707408">
</a>
<p>
The name of the input file that defines error messages
intended to be written to clients. The default is
<code class="filename">
../share/messages_to_clients.txt
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_name-file">
</a>
<a class="link" href="comp-err.html#option_comp_err_name-file">
<code class="option">
--name-file=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
,
<code class="option">
-N
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for name-file">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--name-file=name
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
mysqld_ername.h
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320691280">
</a>
<a class="indexterm" name="idm46045320689792">
</a>
<p>
The name of the error name file. The default is
<code class="filename">
mysqld_ername.h
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_out-dir">
</a>
<a class="link" href="comp-err.html#option_comp_err_out-dir">
<code class="option">
--out-dir=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
,
<code class="option">
-D
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for out-dir">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--out-dir=path
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
../share/
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320673872">
</a>
<a class="indexterm" name="idm46045320672384">
</a>
<p>
The name of the output base directory. The default is
<code class="filename">
../sql/share/
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_out-file">
</a>
<a class="link" href="comp-err.html#option_comp_err_out-file">
<code class="option">
--out-file=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
,
<code class="option">
-O
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for out-file">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--out-file=name
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
errmsg.sys
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045320656336">
</a>
<a class="indexterm" name="idm46045320654848">
</a>
<p>
The name of the output file. The default is
<code class="filename">
errmsg.sys
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_comp_err_version">
</a>
<a class="link" href="comp-err.html#option_comp_err_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>
<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="idm46045320639568">
</a>
<a class="indexterm" name="idm46045320638080">
</a>
<p>
Display version information and exit.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-ndbinfo-cpustat-20sec.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="mysql-cluster-ndbinfo-cpustat-20sec">
</a>
25.6.17.22 The ndbinfo cpustat_20sec Table
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045089850640">
</a>
<p>
The
<code class="literal">
cpustat_20sec
</code>
table provides raw,
per-thread CPU data obtained each 20 seconds, 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-1sec.html" title="25.6.17.21 The ndbinfo cpustat_1sec Table">
<code class="literal">
cpustat_1sec
</code>
</a>
, this table shows
20 measurement sets per thread, each referencing a period of the
named duration. Thus,
<code class="literal">
cpsustat_20sec
</code>
provides
400 seconds of history.
</p>
<p>
The
<code class="literal">
cpustat_20sec
</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/information-schema-role-routine-grants-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="information-schema-role-routine-grants-table">
</a>
28.3.28 The INFORMATION_SCHEMA ROLE_ROUTINE_GRANTS Table
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045078953232">
</a>
<p>
The
<a class="link" href="information-schema-role-routine-grants-table.html" title="28.3.28 The INFORMATION_SCHEMA ROLE_ROUTINE_GRANTS Table">
<code class="literal">
ROLE_ROUTINE_GRANTS
</code>
</a>
table
provides information about the routine privileges for roles that
are available to or granted by the currently enabled roles.
</p>
<p>
The
<a class="link" href="information-schema-role-routine-grants-table.html" title="28.3.28 The INFORMATION_SCHEMA ROLE_ROUTINE_GRANTS Table">
<code class="literal">
ROLE_ROUTINE_GRANTS
</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">
GRANTOR
</code>
</p>
<p>
The user name part of the account that granted the role.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
GRANTOR_HOST
</code>
</p>
<p>
The host name part of the account that granted the role.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
GRANTEE
</code>
</p>
<p>
The user name part of the account to which the role is
granted.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
GRANTEE_HOST
</code>
</p>
<p>
The host name part of the account to which the role is
granted.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SPECIFIC_CATALOG
</code>
</p>
<p>
The name of the catalog to which the routine belongs. This
value is always
<code class="literal">
def
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SPECIFIC_SCHEMA
</code>
</p>
<p>
The name of the schema (database) to which the routine
belongs.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SPECIFIC_NAME
</code>
</p>
<p>
The name of the routine.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
ROUTINE_CATALOG
</code>
</p>
<p>
The name of the catalog to which the routine belongs. This
value is always
<code class="literal">
def
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
ROUTINE_SCHEMA
</code>
</p>
<p>
The name of the schema (database) to which the routine
belongs.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
ROUTINE_NAME
</code>
</p>
<p>
The name of the routine.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
PRIVILEGE_TYPE
</code>
</p>
<p>
The privilege granted. The value can be any privilege that can
be granted at the routine level; see
<a class="xref" href="grant.html" title="15.7.1.6 GRANT Statement">
Section 15.7.1.6, “GRANT Statement”
</a>
.
Each row lists a single privilege, so there is one row per
column privilege held by the grantee.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
IS_GRANTABLE
</code>
</p>
<p>
<code class="literal">
YES
</code>
or
<code class="literal">
NO
</code>
, depending on
whether the role is grantable to other accounts.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/using-explain.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="using-explain">
</a>
10.8.1 Optimizing Queries with EXPLAIN
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045225610896">
</a>
<a class="indexterm" name="idm46045225609856">
</a>
<p>
The
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
statement provides
information about how MySQL executes statements:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
works with
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
,
<a class="link" href="delete.html" title="15.2.2 DELETE Statement">
<code class="literal">
DELETE
</code>
</a>
,
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
,
<a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
<code class="literal">
REPLACE
</code>
</a>
, and
<a class="link" href="update.html" title="15.2.17 UPDATE Statement">
<code class="literal">
UPDATE
</code>
</a>
statements.
</p>
</li>
<li class="listitem">
<p>
When
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
is used with an
explainable statement, MySQL displays information from the
optimizer about the statement execution plan. That is, MySQL
explains how it would process the statement, including
information about how tables are joined and in which order.
For information about using
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
to obtain execution
plan information, see
<a class="xref" href="explain-output.html" title="10.8.2 EXPLAIN Output Format">
Section 10.8.2, “EXPLAIN Output Format”
</a>
.
</p>
</li>
<li class="listitem">
<p>
When
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
is used with
<code class="literal">
FOR CONNECTION
<em class="replaceable">
<code>
connection_id
</code>
</em>
</code>
rather
than an explainable statement, it displays the execution
plan for the statement executing in the named connection.
See
<a class="xref" href="explain-for-connection.html" title="10.8.4 Obtaining Execution Plan Information for a Named Connection">
Section 10.8.4, “Obtaining Execution Plan Information for a Named Connection”
</a>
.
</p>
</li>
<li class="listitem">
<p>
For
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statements,
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
produces additional
execution plan information that can be displayed using
<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="explain-extended.html" title="10.8.3 Extended EXPLAIN Output Format">
Section 10.8.3, “Extended EXPLAIN Output Format”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
is useful for
examining queries involving partitioned tables. See
<a class="xref" href="partitioning-info.html" title="26.3.5 Obtaining Information About Partitions">
Section 26.3.5, “Obtaining Information About Partitions”
</a>
.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
FORMAT
</code>
option can be used to select
the output format.
<code class="literal">
TRADITIONAL
</code>
presents
the output in tabular format. This is the default if no
<code class="literal">
FORMAT
</code>
option is present.
<code class="literal">
JSON
</code>
format displays the information in
JSON format.
</p>
</li>
</ul>
</div>
<p>
<a class="indexterm" name="idm46045225576624">
</a>
With the help of
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
, you can
see where you should add indexes to tables so that the statement
executes faster by using indexes to find rows. You can also use
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
to check whether the
optimizer joins the tables in an optimal order. To give a hint
to the optimizer to use a join order corresponding to the order
in which the tables are named in a
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement, begin the
statement with
<code class="literal">
SELECT STRAIGHT_JOIN
</code>
rather
than just
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
. (See
<a class="xref" href="select.html" title="15.2.13 SELECT Statement">
Section 15.2.13, “SELECT Statement”
</a>
.) However,
<code class="literal">
STRAIGHT_JOIN
</code>
may prevent indexes from being
used because it disables semijoin transformations. See
<a class="ulink" href="/doc/refman/8.0/en/semijoins.html" target="_top">
Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations
</a>
.
</p>
<p>
The optimizer trace may sometimes provide information
complementary to that of
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
.
However, the optimizer trace format and content are subject to
change between versions. For details, see
<a class="xref" href="optimizer-tracing.html" title="10.15 Tracing the Optimizer">
Section 10.15, “Tracing the Optimizer”
</a>
.
</p>
<p>
If you have a problem with indexes not being used when you
believe that they should be, 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 table statistics, such as cardinality
of keys, that can affect the choices the optimizer makes. See
<a class="xref" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
Section 15.7.3.1, “ANALYZE TABLE Statement”
</a>
.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
can also be used to
obtain information about the columns in a table.
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
<em class="replaceable">
<code>
tbl_name
</code>
</em>
</code>
</a>
is synonymous
with
<code class="literal">
DESCRIBE
<em class="replaceable">
<code>
tbl_name
</code>
</em>
</code>
and
<code class="literal">
SHOW COLUMNS FROM
<em class="replaceable">
<code>
tbl_name
</code>
</em>
</code>
. For more
information, see
<a class="xref" href="describe.html" title="15.8.1 DESCRIBE Statement">
Section 15.8.1, “DESCRIBE Statement”
</a>
, and
<a class="xref" href="show-columns.html" title="15.7.7.6 SHOW COLUMNS Statement">
Section 15.7.7.6, “SHOW COLUMNS Statement”
</a>
.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/audit-api-message-emit.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="audit-api-message-emit">
</a>
8.4.6 The Audit Message Component
</h3>
</div>
</div>
</div>
<p>
The
<code class="literal">
audit_api_message_emit
</code>
component enables
applications to add their own message events to the audit log,
using the
<a class="link" href="audit-api-message-emit.html#function_audit-api-message-emit-udf">
<code class="literal">
audit_api_message_emit_udf()
</code>
</a>
function.
</p>
<p>
The
<code class="literal">
audit_api_message_emit
</code>
component cooperates
with all plugins of audit type. For concreteness, examples use the
<code class="literal">
audit_log
</code>
plugin described in
<a class="xref" href="audit-log.html" title="8.4.5 MySQL Enterprise Audit">
Section 8.4.5, “MySQL Enterprise Audit”
</a>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="audit-api-message-emit.html#audit-api-message-emit-install" title="Installing or Uninstalling the Audit Message Component">
Installing or Uninstalling the Audit Message Component
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="audit-api-message-emit.html#audit-api-message-emit-functions" title="Audit Message Function">
Audit Message Function
</a>
</p>
</li>
</ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="audit-api-message-emit-install">
</a>
Installing or Uninstalling the Audit Message Component
</h4>
</div>
</div>
</div>
<p>
To be usable by the server, the component 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 install the
<code class="literal">
audit_api_message_emit
</code>
component, use this statement:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa91798039"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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_audit_api_message_emit"</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Component installation is a one-time operation that need not be
done per server startup.
<a class="link" href="install-component.html" title="15.7.4.3 INSTALL COMPONENT Statement">
<code class="literal">
INSTALL
COMPONENT
</code>
</a>
loads the component, and also registers it
in the
<code class="literal">
mysql.component
</code>
system table to cause
it to be loaded during subsequent server startups.
</p>
<p>
To uninstall the
<code class="literal">
audit_api_message_emit
</code>
component, use this statement:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa79523706"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">COMPONENT</span> <span class="token string">"file://component_audit_api_message_emit"</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
<a class="link" href="uninstall-component.html" title="15.7.4.5 UNINSTALL COMPONENT Statement">
<code class="literal">
UNINSTALL COMPONENT
</code>
</a>
unloads the
component, and unregisters it from the
<code class="literal">
mysql.component
</code>
system table to cause it not
to be loaded during subsequent server startups.
</p>
<p>
Because installing and uninstalling the
<code class="literal">
audit_api_message_emit
</code>
component installs and
uninstalls the
<a class="link" href="audit-api-message-emit.html#function_audit-api-message-emit-udf">
<code class="literal">
audit_api_message_emit_udf()
</code>
</a>
function that the component implements, it is not necessary to
use
<a class="link" href="create-function-loadable.html" title="15.7.4.1 CREATE FUNCTION Statement for Loadable Functions">
<code class="literal">
CREATE
FUNCTION
</code>
</a>
or
<a class="link" href="drop-function-loadable.html" title="15.7.4.2 DROP FUNCTION Statement for Loadable Functions">
<code class="literal">
DROP
FUNCTION
</code>
</a>
to do so.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="audit-api-message-emit-functions">
</a>
Audit Message Function
</h4>
</div>
</div>
</div>
<p>
This section describes the
<a class="link" href="audit-api-message-emit.html#function_audit-api-message-emit-udf">
<code class="literal">
audit_api_message_emit_udf()
</code>
</a>
function implemented by the
<code class="literal">
audit_api_message_emit
</code>
component.
</p>
<p>
Before using the audit message function, install the audit
message component according to the instructions provided at
<a class="xref" href="audit-api-message-emit.html#audit-api-message-emit-install" title="Installing or Uninstalling the Audit Message Component">
Installing or Uninstalling the Audit Message Component
</a>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="function_audit-api-message-emit-udf">
</a>
<a class="link" href="audit-api-message-emit.html#function_audit-api-message-emit-udf">
<code class="literal">
audit_api_message_emit_udf(
<em class="replaceable">
<code>
component
</code>
</em>
,
<em class="replaceable">
<code>
producer
</code>
</em>
,
<em class="replaceable">
<code>
message
</code>
</em>
[,
<em class="replaceable">
<code>
key
</code>
</em>
,
<em class="replaceable">
<code>
value
</code>
</em>
] ...)
</code>
</a>
</p>
<a class="indexterm" name="idm46045234678448">
</a>
<a class="indexterm" name="idm46045234677344">
</a>
<p>
Adds a message event to the audit log. Message events
include component, producer, and message strings of the
caller's choosing, and optionally a set of key-value
pairs.
</p>
<p>
An event posted by this function is sent to all enabled
plugins of audit type, each of which handles the event
according to its own rules. If no plugin of audit type is
enabled, posting the event has no effect.
</p>
<p>
Arguments:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<em class="replaceable">
<code>
component
</code>
</em>
: A string that
specifies a component name.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
producer
</code>
</em>
: A string that
specifies a producer name.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
message
</code>
</em>
: A string that
specifies the event message.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
key
</code>
</em>
,
<em class="replaceable">
<code>
value
</code>
</em>
: Events may include 0
or more key-value pairs that specify an arbitrary
application-provided data map. Each
<em class="replaceable">
<code>
key
</code>
</em>
argument is a string that
specifies a name for its immediately following
<em class="replaceable">
<code>
value
</code>
</em>
argument. Each
<em class="replaceable">
<code>
value
</code>
</em>
argument specifies a
value for its immediately following
<em class="replaceable">
<code>
key
</code>
</em>
argument. Each
<em class="replaceable">
<code>
value
</code>
</em>
can be a string or
numeric value, or
<code class="literal">
NULL
</code>
.
</p>
</li>
</ul>
</div>
<p>
Return value:
</p>
<p>
The string
<code class="literal">
OK
</code>
to indicate success. An
error occurs if the function fails.
</p>
<p>
Example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38067821"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> audit_api_message_emit_udf<span class="token punctuation">(</span><span class="token string">'component_text'</span><span class="token punctuation">,</span>
<span class="token string">'producer_text'</span><span class="token punctuation">,</span>
<span class="token string">'message_text'</span><span class="token punctuation">,</span>
<span class="token string">'key1'</span><span class="token punctuation">,</span> <span class="token string">'value1'</span><span class="token punctuation">,</span>
<span class="token string">'key2'</span><span class="token punctuation">,</span> <span class="token number">123</span><span class="token punctuation">,</span>
<span class="token string">'key3'</span><span class="token punctuation">,</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token string">'Message'</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>
<span class="token output"><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>
<span class="token output"><span class="token punctuation">|</span> OK <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></code></pre>
</div>
<p>
Additional information:
</p>
<p>
Each audit plugin that receives an event posted by
<a class="link" href="audit-api-message-emit.html#function_audit-api-message-emit-udf">
<code class="literal">
audit_api_message_emit_udf()
</code>
</a>
logs the event in plugin-specific format. For example, the
<code class="literal">
audit_log
</code>
plugin (see
<a class="xref" href="audit-log.html" title="8.4.5 MySQL Enterprise Audit">
Section 8.4.5, “MySQL Enterprise Audit”
</a>
) logs message values as follows,
depending on the log format configured by the
<a class="link" href="audit-log-reference.html#sysvar_audit_log_format">
<code class="literal">
audit_log_format
</code>
</a>
system
variable:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
JSON format
(
<a class="link" href="audit-log-reference.html#sysvar_audit_log_format">
<code class="literal">
audit_log_format=JSON
</code>
</a>
):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-json"><div class="docs-select-all right" id="sa18327302"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">{</span>
...
<span class="token property">"class"</span><span class="token operator">:</span> <span class="token string">"message"</span><span class="token punctuation">,</span>
<span class="token property">"event"</span><span class="token operator">:</span> <span class="token string">"user"</span><span class="token punctuation">,</span>
...
<span class="token property">"message_data"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">"component"</span><span class="token operator">:</span> <span class="token string">"component_text"</span><span class="token punctuation">,</span>
<span class="token property">"producer"</span><span class="token operator">:</span> <span class="token string">"producer_text"</span><span class="token punctuation">,</span>
<span class="token property">"message"</span><span class="token operator">:</span> <span class="token string">"message_text"</span><span class="token punctuation">,</span>
<span class="token property">"map"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">"key1"</span><span class="token operator">:</span> <span class="token string">"value1"</span><span class="token punctuation">,</span>
<span class="token property">"key2"</span><span class="token operator">:</span> <span class="token number">123</span><span class="token punctuation">,</span>
<span class="token property">"key3"</span><span class="token operator">:</span> <span class="token null">null</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
New-style XML format
(
<a class="link" href="audit-log-reference.html#sysvar_audit_log_format">
<code class="literal">
audit_log_format=NEW
</code>
</a>
):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-xml"><div class="docs-select-all right" id="sa64997184"><div class="copy-help left">Press ⌘+C to 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"><</span>AUDIT_RECORD</span><span class="token punctuation">></span></span>
...
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>NAME</span><span class="token punctuation">></span></span>Message<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>NAME</span><span class="token punctuation">></span></span>
...
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>COMMAND_CLASS</span><span class="token punctuation">></span></span>user<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>COMMAND_CLASS</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>COMPONENT</span><span class="token punctuation">></span></span>component_text<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>COMPONENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>PRODUCER</span><span class="token punctuation">></span></span>producer_text<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>PRODUCER</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>MESSAGE</span><span class="token punctuation">></span></span>message_text<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>MESSAGE</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>MAP</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ELEMENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>KEY</span><span class="token punctuation">></span></span>key1<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>KEY</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>VALUE</span><span class="token punctuation">></span></span>value1<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>VALUE</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ELEMENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ELEMENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>KEY</span><span class="token punctuation">></span></span>key2<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>KEY</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>VALUE</span><span class="token punctuation">></span></span>123<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>VALUE</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ELEMENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ELEMENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>KEY</span><span class="token punctuation">></span></span>key3<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>KEY</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>VALUE</span><span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ELEMENT</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>MAP</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>AUDIT_RECORD</span><span class="token punctuation">></span></span></code></pre>
</div>
</li>
<li class="listitem">
<p>
Old-style XML format
(
<a class="link" href="audit-log-reference.html#sysvar_audit_log_format">
<code class="literal">
audit_log_format=OLD
</code>
</a>
):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-xml"><div class="docs-select-all right" id="sa96701187"><div class="copy-help left">Press ⌘+C to 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"><</span>AUDIT_RECORD</span>
<span class="token attr-name">...</span>
<span class="token attr-name">NAME</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Message<span class="token punctuation">"</span></span>
<span class="token attr-name">...</span>
<span class="token attr-name">COMMAND_CLASS</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>user<span class="token punctuation">"</span></span>
<span class="token attr-name">COMPONENT</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>component_text<span class="token punctuation">"</span></span>
<span class="token attr-name">PRODUCER</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>producer_text<span class="token punctuation">"</span></span>
<span class="token attr-name">MESSAGE</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>message_text<span class="token punctuation">"</span></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>
Message events logged in old-style XML format do not
include the key-value map due to representational
constraints imposed by this format.
</p>
</div>
</li>
</ul>
</div>
<p>
Messages posted by
<a class="link" href="audit-api-message-emit.html#function_audit-api-message-emit-udf">
<code class="literal">
audit_api_message_emit_udf()
</code>
</a>
have an event class of
<code class="literal">
MYSQL_AUDIT_MESSAGE_CLASS
</code>
and a subclass
of
<code class="literal">
MYSQL_AUDIT_MESSAGE_USER
</code>
. (Internally
generated audit messages have the same class and a subclass
of
<code class="literal">
MYSQL_AUDIT_MESSAGE_INTERNAL
</code>
; this
subclass currently is unused.) To refer to such events in
<code class="literal">
audit_log
</code>
filtering rules, use a
<code class="literal">
class
</code>
element with a
<code class="literal">
name
</code>
value of
<code class="literal">
message
</code>
.
For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-json"><div class="docs-select-all right" id="sa55743967"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">{</span>
<span class="token property">"filter"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">"class"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
<span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"message"</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
</div>
<p>
Should it be necessary to distinguish user-generated and
internally generated message events, test the
<code class="literal">
subclass
</code>
value against
<code class="literal">
user
</code>
or
<code class="literal">
internal
</code>
.
</p>
<p>
Filtering based on the contents of the key-value map is not
supported.
</p>
<p>
For information about writing filtering rules, see
<a class="xref" href="audit-log-filtering.html" title="8.4.5.7 Audit Log Filtering">
Section 8.4.5.7, “Audit Log Filtering”
</a>
.
</p>
</li>
</ul>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/enum.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="enum">
</a>
13.3.5 The ENUM Type
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045212490160">
</a>
<a class="indexterm" name="idm46045212489088">
</a>
<p>
An
<code class="literal">
ENUM
</code>
is a string object with a value
chosen from a list of permitted values that are enumerated
explicitly in the column specification at table creation time.
</p>
<p>
See
<a class="xref" href="string-type-syntax.html" title="13.3.1 String Data Type Syntax">
Section 13.3.1, “String Data Type Syntax”
</a>
for
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
type syntax and length
limits.
</p>
<p>
The
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
type has these
advantages:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Compact data storage in situations where a column has a
limited set of possible values. The strings you specify as
input values are automatically encoded as numbers. See
<a class="xref" href="storage-requirements.html" title="13.7 Data Type Storage Requirements">
Section 13.7, “Data Type Storage Requirements”
</a>
for storage
requirements for the
<code class="literal">
ENUM
</code>
type.
</p>
</li>
<li class="listitem">
<p>
Readable queries and output. The numbers are translated back
to the corresponding strings in query results.
</p>
</li>
</ul>
</div>
<p>
and these potential issues to consider:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
If you make enumeration values that look like numbers, it is
easy to mix up the literal values with their internal index
numbers, as explained in
<a class="xref" href="enum.html#enum-limits" title="Enumeration Limitations">
Enumeration Limitations
</a>
.
</p>
</li>
<li class="listitem">
<p>
Using
<code class="literal">
ENUM
</code>
columns in
<code class="literal">
ORDER
BY
</code>
clauses requires extra care, as explained in
<a class="xref" href="enum.html#enum-sorting" title="Enumeration Sorting">
Enumeration Sorting
</a>
.
</p>
</li>
</ul>
</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="enum.html#enum-using" title="Creating and Using ENUM Columns">
Creating and Using ENUM Columns
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="enum.html#enum-indexes" title="Index Values for Enumeration Literals">
Index Values for Enumeration Literals
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="enum.html#enum-literals" title="Handling of Enumeration Literals">
Handling of Enumeration Literals
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="enum.html#enum-nulls" title="Empty or NULL Enumeration Values">
Empty or NULL Enumeration Values
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="enum.html#enum-sorting" title="Enumeration Sorting">
Enumeration Sorting
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="enum.html#enum-limits" title="Enumeration Limitations">
Enumeration Limitations
</a>
</p>
</li>
</ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="enum-using">
</a>
Creating and Using ENUM Columns
</h4>
</div>
</div>
</div>
<p>
An enumeration value must be a quoted string literal. For
example, you can create a table with an
<code class="literal">
ENUM
</code>
column like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69554908"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> shirts <span class="token punctuation">(</span>
<span class="token keyword">name</span> <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
size <span class="token datatype">ENUM</span><span class="token punctuation">(</span><span class="token string">'x-small'</span><span class="token punctuation">,</span> <span class="token string">'small'</span><span class="token punctuation">,</span> <span class="token string">'medium'</span><span class="token punctuation">,</span> <span class="token string">'large'</span><span class="token punctuation">,</span> <span class="token string">'x-large'</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> shirts <span class="token punctuation">(</span><span class="token keyword">name</span><span class="token punctuation">,</span> size<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">'dress shirt'</span><span class="token punctuation">,</span><span class="token string">'large'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'t-shirt'</span><span class="token punctuation">,</span><span class="token string">'medium'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token string">'polo shirt'</span><span class="token punctuation">,</span><span class="token string">'small'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token keyword">name</span><span class="token punctuation">,</span> size <span class="token keyword">FROM</span> shirts <span class="token keyword">WHERE</span> size <span class="token operator">=</span> <span class="token string">'medium'</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>
<span class="token output"><span class="token punctuation">|</span> name <span class="token punctuation">|</span> size <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>
<span class="token output"><span class="token punctuation">|</span> t<span class="token punctuation">-</span>shirt <span class="token punctuation">|</span> medium <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>
<span class="token keyword">UPDATE</span> shirts <span class="token keyword">SET</span> size <span class="token operator">=</span> <span class="token string">'small'</span> <span class="token keyword">WHERE</span> size <span class="token operator">=</span> <span class="token string">'large'</span><span class="token punctuation">;</span>
<span class="token keyword">COMMIT</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Inserting 1 million rows into this table with a value of
<code class="literal">
'medium'
</code>
would require 1 million bytes of
storage, as opposed to 6 million bytes if you stored the
actual string
<code class="literal">
'medium'
</code>
in a
<code class="literal">
VARCHAR
</code>
column.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="enum-indexes">
</a>
Index Values for Enumeration Literals
</h4>
</div>
</div>
</div>
<p>
Each enumeration value has an index:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The elements listed in the column specification are
assigned index numbers, beginning with 1.
</p>
</li>
<li class="listitem">
<p>
The index value of the empty string error value is 0. This
means that you can use the following
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement to find
rows into which invalid
<code class="literal">
ENUM
</code>
values
were assigned:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa48868951"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em> <span class="token keyword">WHERE</span> <em class="replaceable">enum_col</em><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
The index of the
<code class="literal">
NULL
</code>
value is
<code class="literal">
NULL
</code>
.
</p>
</li>
<li class="listitem">
<p>
The term
<span class="quote">
“
<span class="quote">
index
</span>
”
</span>
here refers to a position
within the list of enumeration values. It has nothing to
do with table indexes.
</p>
</li>
</ul>
</div>
<p>
For example, a column specified as
<code class="literal">
ENUM('Mercury',
'Venus', 'Earth')
</code>
can have any of the values shown
here. The index of each value is also shown.
</p>
<div class="informaltable">
<table summary="Possible values for a column specified as ENUM('Mercury', 'Venus', 'Earth'). The table also shows the index of each value.">
<colgroup>
<col style="width: 15%"/>
<col style="width: 15%"/>
</colgroup>
<thead>
<tr>
<th>
Value
</th>
<th>
Index
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="literal">
NULL
</code>
</td>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
<tr>
<td>
<code class="literal">
''
</code>
</td>
<td>
0
</td>
</tr>
<tr>
<td>
<code class="literal">
'Mercury'
</code>
</td>
<td>
1
</td>
</tr>
<tr>
<td>
<code class="literal">
'Venus'
</code>
</td>
<td>
2
</td>
</tr>
<tr>
<td>
<code class="literal">
'Earth'
</code>
</td>
<td>
3
</td>
</tr>
</tbody>
</table>
</div>
<p>
An
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
column can have a
maximum of 65,535 distinct elements.
</p>
<p>
If you retrieve an
<code class="literal">
ENUM
</code>
value in a numeric
context, the column value's index is returned. For example,
you can retrieve numeric values from an
<code class="literal">
ENUM
</code>
column like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa9743022"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <em class="replaceable">enum_col</em><span class="token operator">+</span><span class="token number">0</span> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em><span class="token punctuation">;</span></code></pre>
</div>
<p>
Functions such as
<a class="link" href="aggregate-functions.html#function_sum">
<code class="literal">
SUM()
</code>
</a>
or
<a class="link" href="aggregate-functions.html#function_avg">
<code class="literal">
AVG()
</code>
</a>
that expect a numeric
argument cast the argument to a number if necessary. For
<code class="literal">
ENUM
</code>
values, the index number is used in
the calculation.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="enum-literals">
</a>
Handling of Enumeration Literals
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045212416912">
</a>
<p>
Trailing spaces are automatically deleted from
<code class="literal">
ENUM
</code>
member values in the table definition
when a table is created.
</p>
<p>
When retrieved, values stored into an
<code class="literal">
ENUM
</code>
column are displayed using the lettercase that was used in the
column definition. Note that
<code class="literal">
ENUM
</code>
columns
can be assigned a character set and collation. For binary or
case-sensitive collations, lettercase is taken into account
when assigning values to the column.
</p>
<p>
If you store a number into an
<code class="literal">
ENUM
</code>
column,
the number is treated as the index into the possible values,
and the value stored is the enumeration member with that
index. (However, this does
<span class="emphasis">
<em>
not
</em>
</span>
work with
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
, which treats all
input as strings.) If the numeric value is quoted, it is still
interpreted as an index if there is no matching string in the
list of enumeration values. For these reasons, it is not
advisable to define an
<code class="literal">
ENUM
</code>
column with
enumeration values that look like numbers, because this can
easily become confusing. For example, the following column has
enumeration members with string values of
<code class="literal">
'0'
</code>
,
<code class="literal">
'1'
</code>
, and
<code class="literal">
'2'
</code>
, but numeric index values of
<code class="literal">
1
</code>
,
<code class="literal">
2
</code>
, and
<code class="literal">
3
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa63911817"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">numbers <span class="token datatype">ENUM</span><span class="token punctuation">(</span><span class="token string">'0'</span><span class="token punctuation">,</span><span class="token string">'1'</span><span class="token punctuation">,</span><span class="token string">'2'</span><span class="token punctuation">)</span></code></pre>
</div>
<p>
If you store
<code class="literal">
2
</code>
, it is interpreted as an
index value, and becomes
<code class="literal">
'1'
</code>
(the value
with index 2). If you store
<code class="literal">
'2'
</code>
, it matches
an enumeration value, so it is stored as
<code class="literal">
'2'
</code>
. If you store
<code class="literal">
'3'
</code>
,
it does not match any enumeration value, so it is treated as
an index and becomes
<code class="literal">
'2'
</code>
(the value with
index 3).
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84170049"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t <span class="token punctuation">(</span>numbers<span class="token punctuation">)</span> <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 punctuation">,</span><span class="token punctuation">(</span><span class="token string">'2'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token string">'3'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t<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>
<span class="token output"><span class="token punctuation">|</span> numbers <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>
<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> 2 <span class="token punctuation">|</span></span>
<span class="token output"><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></code></pre>
</div>
<p>
To determine all possible values for an
<code class="literal">
ENUM
</code>
column, use
<a class="link" href="show-columns.html" title="15.7.7.6 SHOW COLUMNS Statement">
<code class="literal">
SHOW COLUMNS
FROM
<em class="replaceable">
<code>
tbl_name
</code>
</em>
LIKE
'
<em class="replaceable">
<code>
enum_col
</code>
</em>
'
</code>
</a>
and parse the
<code class="literal">
ENUM
</code>
definition in the
<code class="literal">
Type
</code>
column of the output.
</p>
<p>
In the C API,
<code class="literal">
ENUM
</code>
values are returned as
strings. For information about using result set metadata to
distinguish them from other strings, see
<a class="ulink" href="/doc/c-api/8.4/en/c-api-data-structures.html" target="_top">
C API Basic Data Structures
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="enum-nulls">
</a>
Empty or NULL Enumeration Values
</h4>
</div>
</div>
</div>
<p>
An enumeration value can also be the empty string
(
<code class="literal">
''
</code>
) or
<code class="literal">
NULL
</code>
under
certain circumstances:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
If you insert an invalid value into an
<code class="literal">
ENUM
</code>
(that is, a string not present in
the list of permitted values), the empty string is
inserted instead as a special error value. This string can
be distinguished from a
<span class="quote">
“
<span class="quote">
normal
</span>
”
</span>
empty string
by the fact that this string has the numeric value 0. See
<a class="xref" href="enum.html#enum-indexes" title="Index Values for Enumeration Literals">
Index Values for Enumeration Literals
</a>
for details about the
numeric indexes for the enumeration values.
</p>
<p>
If strict SQL mode is enabled, attempts to insert invalid
<code class="literal">
ENUM
</code>
values result in an error.
</p>
</li>
<li class="listitem">
<p>
If an
<code class="literal">
ENUM
</code>
column is declared to permit
<code class="literal">
NULL
</code>
, the
<code class="literal">
NULL
</code>
value
is a valid value for the column, and the default value is
<code class="literal">
NULL
</code>
. If an
<code class="literal">
ENUM
</code>
column is declared
<code class="literal">
NOT NULL
</code>
, its
default value is the first element of the list of
permitted values.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="enum-sorting">
</a>
Enumeration Sorting
</h4>
</div>
</div>
</div>
<p>
<code class="literal">
ENUM
</code>
values are sorted based on their index
numbers, which depend on the order in which the enumeration
members were listed in the column specification. For example,
<code class="literal">
'b'
</code>
sorts before
<code class="literal">
'a'
</code>
for
<code class="literal">
ENUM('b', 'a')
</code>
. The empty string sorts
before nonempty strings, and
<code class="literal">
NULL
</code>
values
sort before all other enumeration values.
</p>
<p>
To prevent unexpected results when using the
<code class="literal">
ORDER
BY
</code>
clause on an
<code class="literal">
ENUM
</code>
column, use
one of these techniques:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Specify the
<code class="literal">
ENUM
</code>
list in alphabetic
order.
</p>
</li>
<li class="listitem">
<p>
Make sure that the column is sorted lexically rather than
by index number by coding
<code class="literal">
ORDER BY
CAST(
<em class="replaceable">
<code>
col
</code>
</em>
AS CHAR)
</code>
or
<code class="literal">
ORDER BY
CONCAT(
<em class="replaceable">
<code>
col
</code>
</em>
)
</code>
.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="enum-limits">
</a>
Enumeration Limitations
</h4>
</div>
</div>
</div>
<p>
An enumeration value cannot be an expression, even one that
evaluates to a string value.
</p>
<p>
For example, this
<a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
<code class="literal">
CREATE TABLE
</code>
</a>
statement does
<span class="emphasis">
<em>
not
</em>
</span>
work because the
<code class="literal">
CONCAT
</code>
function cannot be used to construct
an enumeration value:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10172814"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> sizes <span class="token punctuation">(</span>
size <span class="token datatype">ENUM</span><span class="token punctuation">(</span><span class="token string">'small'</span><span class="token punctuation">,</span> <span class="token function">CONCAT</span><span class="token punctuation">(</span><span class="token string">'med'</span><span class="token punctuation">,</span><span class="token string">'ium'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'large'</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
You also cannot employ a user variable as an enumeration
value. This pair of statements do
<span class="emphasis">
<em>
not
</em>
</span>
work:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21835649"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">@mysize</span> <span class="token operator">=</span> <span class="token string">'medium'</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> sizes <span class="token punctuation">(</span>
size <span class="token datatype">ENUM</span><span class="token punctuation">(</span><span class="token string">'small'</span><span class="token punctuation">,</span> <span class="token variable">@mysize</span><span class="token punctuation">,</span> <span class="token string">'large'</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
We strongly recommend that you do
<span class="emphasis">
<em>
not
</em>
</span>
use
numbers as enumeration values, because it does not save on
storage over the appropriate
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
TINYINT
</code>
</a>
or
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
SMALLINT
</code>
</a>
type, and it is easy
to mix up the strings and the underlying number values (which
might not be the same) if you quote the
<code class="literal">
ENUM
</code>
values incorrectly. If you do use a
number as an enumeration value, always enclose it in quotation
marks. If the quotation marks are omitted, the number is
regarded as an index. See
<a class="xref" href="enum.html#enum-literals" title="Handling of Enumeration Literals">
Handling of Enumeration Literals
</a>
to
see how even a quoted number could be mistakenly used as a
numeric index value.
</p>
<p>
Duplicate values in the definition cause a warning, or an
error if strict SQL mode is enabled.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/charset-unicode-conversion.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="charset-unicode-conversion">
</a>
12.9.8 Converting Between 3-Byte and 4-Byte Unicode Character Sets
</h3>
</div>
</div>
</div>
<p>
This section describes issues that you may face when converting
character data between the
<code class="literal">
utf8mb3
</code>
and
<code class="literal">
utf8mb4
</code>
character sets.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
This discussion focuses primarily on converting between
<code class="literal">
utf8mb3
</code>
and
<code class="literal">
utf8mb4
</code>
, but
similar principles apply to converting between the
<code class="literal">
ucs2
</code>
character set and character sets such
as
<code class="literal">
utf16
</code>
or
<code class="literal">
utf32
</code>
.
</p>
</div>
<p>
The
<code class="literal">
utf8mb3
</code>
and
<code class="literal">
utf8mb4
</code>
character sets differ as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
utf8mb3
</code>
supports only characters in the
Basic Multilingual Plane (BMP).
<code class="literal">
utf8mb4
</code>
additionally supports supplementary characters that lie
outside the BMP.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
utf8mb3
</code>
uses a maximum of three bytes per
character.
<code class="literal">
utf8mb4
</code>
uses a maximum of four
bytes per character.
</p>
</li>
</ul>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
This discussion refers to the
<code class="literal">
utf8mb3
</code>
and
<code class="literal">
utf8mb4
</code>
character set names to be explicit
about referring to 3-byte and 4-byte UTF-8 character set data.
</p>
</div>
<p>
One advantage of converting from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
is that this enables applications to
use supplementary characters. One tradeoff is that this may
increase data storage space requirements.
</p>
<p>
In terms of table content, conversion from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
presents no problems:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For a BMP character,
<code class="literal">
utf8mb4
</code>
and
<code class="literal">
utf8mb3
</code>
have identical storage
characteristics: same code values, same encoding, same
length.
</p>
</li>
<li class="listitem">
<p>
For a supplementary character,
<code class="literal">
utf8mb4
</code>
requires four bytes to store it, whereas
<code class="literal">
utf8mb3
</code>
cannot store the character at
all. When converting
<code class="literal">
utf8mb3
</code>
columns to
<code class="literal">
utf8mb4
</code>
, you need not worry about
converting supplementary characters because there are none.
</p>
</li>
</ul>
</div>
<p>
In terms of table structure, these are the primary potential
incompatibilities:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For the variable-length character data types
(
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
and the
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
types), the maximum
permitted length in characters is less for
<code class="literal">
utf8mb4
</code>
columns than for
<code class="literal">
utf8mb3
</code>
columns.
</p>
</li>
<li class="listitem">
<p>
For all character data types
(
<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 the
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
types), the maximum
number of characters that can be indexed is less for
<code class="literal">
utf8mb4
</code>
columns than for
<code class="literal">
utf8mb3
</code>
columns.
</p>
</li>
</ul>
</div>
<p>
Consequently, to convert tables from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
, it may be necessary to change
some column or index definitions.
</p>
<p>
Tables can be converted from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
by using
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER
TABLE
</code>
</a>
. Suppose that a table has this definition:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa93841230"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
col1 <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 keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb3 <span class="token keyword">COLLATE</span> utf8mb3_unicode_ci <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
col2 <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 keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb3 <span class="token keyword">COLLATE</span> utf8mb3_bin <span class="token operator">NOT</span> <span class="token boolean">NULL</span>
<span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb3<span class="token punctuation">;</span></code></pre>
</div>
<p>
The following statement converts
<code class="literal">
t1
</code>
to use
<code class="literal">
utf8mb4
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa13249982"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DEFAULT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">,</span>
<span class="token keyword">MODIFY</span> col1 <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 keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4 <span class="token keyword">COLLATE</span> utf8mb4_unicode_ci <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">MODIFY</span> col2 <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 keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4 <span class="token keyword">COLLATE</span> utf8mb4_bin <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The catch when converting from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
is that the maximum length of a
column or index key is unchanged in terms of
<span class="emphasis">
<em>
bytes
</em>
</span>
. Therefore, it is smaller in terms of
<span class="emphasis">
<em>
characters
</em>
</span>
because the maximum length of a
character is four bytes instead of three. For 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>
data types, watch for these
issues when converting your MySQL tables:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Check all definitions of
<code class="literal">
utf8mb3
</code>
columns
and make sure they do not exceed the maximum length for the
storage engine.
</p>
</li>
<li class="listitem">
<p>
Check all indexes on
<code class="literal">
utf8mb3
</code>
columns and
make sure they do not exceed the maximum length for the
storage engine. Sometimes the maximum can change due to
storage engine enhancements.
</p>
</li>
</ul>
</div>
<p>
If the preceding conditions apply, you must either reduce the
defined length of columns or indexes, or continue to use
<code class="literal">
utf8mb3
</code>
rather than
<code class="literal">
utf8mb4
</code>
.
</p>
<p>
Here are some examples where structural changes may be needed:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TINYTEXT
</code>
</a>
column can hold up
to 255 bytes, so it can hold up to 85 3-byte or 63 4-byte
characters. Suppose that you have a
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TINYTEXT
</code>
</a>
column that uses
<code class="literal">
utf8mb3
</code>
but must be able to contain more
than 63 characters. You cannot convert it to
<code class="literal">
utf8mb4
</code>
unless you also change the data
type to a longer type such as
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
.
</p>
<p>
Similarly, a very long
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
column may need to be
changed to one of the longer
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
types if you want to
convert it from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
InnoDB
</code>
has a maximum index length of 767
bytes for tables that use
<code class="literal">
<a class="link" href="glossary.html#glos_compact_row_format" title="compact row format">
COMPACT
</a>
</code>
or
<code class="literal">
<a class="link" href="glossary.html#glos_redundant_row_format" title="redundant row format">
REDUNDANT
</a>
</code>
row format, so for
<code class="literal">
utf8mb3
</code>
or
<code class="literal">
utf8mb4
</code>
columns, you can index a maximum
of 255 or 191 characters, respectively. If you currently
have
<code class="literal">
utf8mb3
</code>
columns with indexes longer
than 191 characters, you must index a smaller number of
characters.
</p>
<p>
In an
<code class="literal">
InnoDB
</code>
table that uses
<code class="literal">
<a class="link" href="glossary.html#glos_compact_row_format" title="compact row format">
COMPACT
</a>
</code>
or
<code class="literal">
<a class="link" href="glossary.html#glos_redundant_row_format" title="redundant row format">
REDUNDANT
</a>
</code>
row format, these column and index definitions are legal:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa28037365"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">col1 <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb3<span class="token punctuation">,</span> <span class="token keyword">INDEX</span> <span class="token punctuation">(</span>col1<span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">)</span></code></pre>
</div>
<p>
To use
<code class="literal">
utf8mb4
</code>
instead, the index must be
smaller:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa69221948"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">col1 <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">,</span> <span class="token keyword">INDEX</span> <span class="token punctuation">(</span>col1<span class="token punctuation">(</span><span class="token number">191</span><span class="token punctuation">)</span><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>
For
<code class="literal">
InnoDB
</code>
tables that use
<code class="literal">
<a class="link" href="glossary.html#glos_compressed_row_format" title="compressed row format">
COMPRESSED
</a>
</code>
or
<code class="literal">
<a class="link" href="glossary.html#glos_dynamic_row_format" title="dynamic row format">
DYNAMIC
</a>
</code>
row format,
<a class="link" href="glossary.html#glos_index_prefix" title="index prefix">
index key
prefixes
</a>
longer than 767 bytes (up to 3072 bytes)
are permitted. Tables created with these row formats
enable you to index a maximum of 1024 or 768 characters
for
<code class="literal">
utf8mb3
</code>
or
<code class="literal">
utf8mb4
</code>
columns, respectively. For
related information, see
<a class="xref" href="innodb-limits.html" title="17.21 InnoDB Limits">
Section 17.21, “InnoDB Limits”
</a>
,
and
<a class="xref" href="innodb-row-format.html#innodb-row-format-dynamic" title="DYNAMIC Row Format">
DYNAMIC Row Format
</a>
.
</p>
</div>
</li>
</ul>
</div>
<p>
The preceding types of changes are most likely to be required
only if you have very long columns or indexes. Otherwise, you
should be able to convert your tables from
<code class="literal">
utf8mb3
</code>
to
<code class="literal">
utf8mb4
</code>
without
problems, using
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
as
described previously.
</p>
<p>
The following items summarize other potential incompatibilities:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
SET NAMES 'utf8mb4'
</code>
causes use of the
4-byte character set for connection character sets. As long
as no 4-byte characters are sent from the server, there
should be no problems. Otherwise, applications that expect
to receive a maximum of three bytes per character may have
problems. Conversely, applications that expect to send
4-byte characters must ensure that the server understands
them.
</p>
</li>
<li class="listitem">
<p>
For replication, if character sets that support
supplementary characters are to be used on the source, all
replicas must understand them as well.
</p>
<p>
Also, keep in mind the general principle that if a table has
different definitions on the source and replica, this can
lead to unexpected results. For example, the differences in
maximum index key length make it risky to use
<code class="literal">
utf8mb3
</code>
on the source and
<code class="literal">
utf8mb4
</code>
on the replica.
</p>
</li>
</ul>
</div>
<p>
If you have converted to
<code class="literal">
utf8mb4
</code>
,
<code class="literal">
utf16
</code>
,
<code class="literal">
utf16le
</code>
, or
<code class="literal">
utf32
</code>
, and then decide to convert back to
<code class="literal">
utf8mb3
</code>
or
<code class="literal">
ucs2
</code>
(for
example, to downgrade to an older version of MySQL), these
considerations apply:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
utf8mb3
</code>
and
<code class="literal">
ucs2
</code>
data
should present no problems.
</p>
</li>
<li class="listitem">
<p>
The server must be recent enough to recognize definitions
referring to the character set from which you are
converting.
</p>
</li>
<li class="listitem">
<p>
For object definitions that refer to the
<code class="literal">
utf8mb4
</code>
character set, you can dump them
with
<a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
<span class="command">
<strong>
mysqldump
</strong>
</span>
</a>
prior to downgrading, edit
the dump file to change instances of
<code class="literal">
utf8mb4
</code>
to
<code class="literal">
utf8
</code>
, and
reload the file in the older server, as long as there are no
4-byte characters in the data. The older server sees
<code class="literal">
utf8
</code>
in the dump file object definitions
and create new objects that use the (3-byte)
<code class="literal">
utf8
</code>
character set.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/audit-log-restrictions.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="audit-log-restrictions">
</a>
8.4.5.12 Audit Log Restrictions
</h4>
</div>
</div>
</div>
<p>
MySQL Enterprise Audit is subject to these general restrictions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Only SQL statements are logged. Changes made by no-SQL APIs,
such as memcached, Node.JS, and the NDB API, are not logged.
</p>
</li>
<li class="listitem">
<p>
Only top-level statements are logged, not statements within
stored programs such as triggers or stored procedures.
</p>
</li>
<li class="listitem">
<p>
Contents of files referenced by statements such as
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
are not logged.
</p>
</li>
</ul>
</div>
<p>
<b>
NDB Cluster.
</b>
It is possible to use MySQL Enterprise Audit with MySQL NDB Cluster,
subject to the following conditions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
All changes to be logged must be done using the SQL
interface. Changes using no-SQL interfaces, such as those
provided by the NDB API, memcached, or ClusterJ, are not
logged.
</p>
</li>
<li class="listitem">
<p>
The plugin must be installed on each MySQL server that is
used to execute SQL on the cluster.
</p>
</li>
<li class="listitem">
<p>
Audit plugin data must be aggregated amongst all MySQL
servers used with the cluster. This aggregation is the
responsibility of the application or user.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-shell-tutorial-python-download.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="mysql-shell-tutorial-python-download">
</a>
22.4.2 Download and Import world_x Database
</h3>
</div>
</div>
</div>
<p>
As part of this quick-start guide, an example schema is provided
which is referred to as the
<code class="literal">
world_x
</code>
schema.
Many of the examples demonstrate Document Store functionality
using this schema. Start your MySQL server so that you can load
the
<code class="literal">
world_x
</code>
schema, then follow these steps:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
Download
<a class="ulink" href="http://downloads.mysql.com/docs/world_x-db.zip" target="_blank">
world_x-db.zip
</a>
.
</p>
</li>
<li class="listitem">
<p>
Extract the installation archive to a temporary location such
as
<code class="filename">
/tmp/
</code>
. Unpacking the archive results
in a single file named
<code class="filename">
world_x.sql
</code>
.
</p>
</li>
<li class="listitem">
<p>
Import the
<code class="filename">
world_x.sql
</code>
file to your
server. You can either:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Start MySQL Shell in SQL mode and import the file by
issuing:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa33625594"><div class="copy-help left">Press ⌘+C to 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 <span class="token property">-u</span> root <span class="token property">--sql</span> <span class="token property">--file</span> /tmp/world_x-db/world_x<span class="token punctuation">.</span>sql
Enter password<span class="token punctuation">:</span> ****</code></pre>
</div>
</li>
<li class="listitem">
<p>
Set MySQL Shell to SQL mode while it is running and
source the schema file by issuing:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa12562761"><div class="copy-help left">Press ⌘+C to 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">\sql
Switching to SQL mode<span class="token operator">...</span> Commands end <span class="token keyword">with</span> <span class="token punctuation">;</span>
\source <span class="token operator">/</span>tmp<span class="token operator">/</span>world_x<span class="token operator">-</span>db<span class="token operator">/</span>world_x<span class="token punctuation">.</span>sql</code></pre>
</div>
</li>
</ul>
</div>
<p>
Replace
<code class="filename">
/tmp/
</code>
with the path to the
<code class="filename">
world_x.sql
</code>
file on your system. Enter
your password if prompted. A non-root account can be used as
long as the account has privileges to create new schemas.
</p>
</li>
</ol>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="mysql-shell-tutorial-python-world-x">
</a>
The world_x Schema
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045127324832">
</a>
<p>
The
<code class="literal">
world_x
</code>
example schema contains the
following JSON collection and relational tables:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Collection
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
countryinfo
</code>
: Information about
countries in the world.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
Tables
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
country
</code>
: Minimal information about
countries of the world.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
city
</code>
: Information about some of the
cities in those countries.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
countrylanguage
</code>
: Languages spoken in
each country.
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="idm46045127313040">
</a>
Related Information
</h4>
</div>
</div>
</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="ulink" href="/doc/mysql-shell/8.4/en/mysql-shell-sessions.html" target="_top">
MySQL Shell Sessions
</a>
explains session
types.
</p>
</li>
</ul>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/source-configuration-options.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="source-configuration-options">
</a>
2.8.7 MySQL Source-Configuration Options
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045329377392">
</a>
<a class="indexterm" name="idm46045329375904">
</a>
<a class="indexterm" name="idm46045329374416">
</a>
<p>
The
<span class="command">
<strong>
CMake
</strong>
</span>
program provides a great deal of
control over how you configure a MySQL source distribution.
Typically, you do this using options on the
<span class="command">
<strong>
CMake
</strong>
</span>
command line. For information about
options supported by
<span class="command">
<strong>
CMake
</strong>
</span>
, run either of these
commands in the top-level source directory:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa39737646"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">cmake</span> <span class="token punctuation">.</span> <span class="token property">-LH</span>
<span class="token prompt">$> </span><span class="token command">ccmake</span> <span class="token punctuation">.</span></code></pre>
</div>
<p>
You can also affect
<span class="command">
<strong>
CMake
</strong>
</span>
using certain
environment variables. See
<a class="xref" href="environment-variables.html" title="6.9 Environment Variables">
Section 6.9, “Environment Variables”
</a>
.
</p>
<p>
For boolean options, the value may be specified as
<code class="literal">
1
</code>
or
<code class="literal">
ON
</code>
to enable the
option, or as
<code class="literal">
0
</code>
or
<code class="literal">
OFF
</code>
to
disable the option.
</p>
<p>
Many options configure compile-time defaults that can be
overridden at server startup. For example, the
<a class="link" href="source-configuration-options.html#option_cmake_cmake_install_prefix">
<code class="option">
CMAKE_INSTALL_PREFIX
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_mysql_tcp_port">
<code class="option">
MYSQL_TCP_PORT
</code>
</a>
, and
<a class="link" href="source-configuration-options.html#option_cmake_mysql_unix_addr">
<code class="option">
MYSQL_UNIX_ADDR
</code>
</a>
options that
configure the default installation base directory location, TCP/IP
port number, and Unix socket file can be changed at server startup
with the
<a class="link" href="server-system-variables.html#sysvar_basedir">
<code class="option">
--basedir
</code>
</a>
,
<a class="link" href="server-options.html#option_mysqld_port">
<code class="option">
--port
</code>
</a>
, and
<a class="link" href="server-options.html#option_mysqld_socket">
<code class="option">
--socket
</code>
</a>
options for
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
. Where applicable, configuration option
descriptions indicate the corresponding
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
startup option.
</p>
<p>
The following sections provide more information about
<span class="command">
<strong>
CMake
</strong>
</span>
options.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#cmake-option-reference" title="CMake Option Reference">
CMake Option Reference
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#cmake-general-options" title="General Options">
General Options
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#cmake-installation-layout-options" title="Installation Layout Options">
Installation Layout Options
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#option_cmake_storage_engine_options" title="Storage Engine Options">
Storage Engine Options
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#cmake-feature-options" title="Feature Options">
Feature Options
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#cmake-compiler-flags" title="Compiler Flags">
Compiler Flags
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="source-configuration-options.html#cmake-mysql-cluster-options" title="CMake Options for Compiling NDB Cluster">
CMake Options for Compiling NDB Cluster
</a>
</p>
</li>
</ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="cmake-option-reference">
</a>
CMake Option Reference
</h4>
</div>
</div>
</div>
<p>
The following table shows the available
<span class="command">
<strong>
CMake
</strong>
</span>
options. In the
<code class="literal">
Default
</code>
column,
<code class="literal">
PREFIX
</code>
stands for the value of the
<a class="link" href="source-configuration-options.html#option_cmake_cmake_install_prefix">
<code class="option">
CMAKE_INSTALL_PREFIX
</code>
</a>
option, which
specifies the installation base directory. This value is used as
the parent location for several of the installation
subdirectories.
</p>
<div class="table">
<a name="idm46045329339632">
</a>
<p class="title">
<b>
Table 2.13 MySQL Source-Configuration Option Reference
(CMake)
</b>
</p>
<div class="table-contents">
<table frame="box" rules="all" summary="CMake options that are available to configure MySQL when building from source.">
<colgroup>
<col style="width: 37%"/>
<col style="width: 37%"/>
<col style="width: 25%"/>
</colgroup>
<thead>
<tr>
<th scope="col">
Formats
</th>
<th scope="col">
Description
</th>
<th scope="col">
Default
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_add_gdb_index">
<code class="literal">
ADD_GDB_INDEX
</code>
</a>
</th>
<td>
Whether to enable generation of .gdb_index section in binaries
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_build_config">
<code class="literal">
BUILD_CONFIG
</code>
</a>
</th>
<td>
Use same build options as official releases
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_bundle_runtime_libraries">
<code class="literal">
BUNDLE_RUNTIME_LIBRARIES
</code>
</a>
</th>
<td>
Bundle runtime libraries with server MSI and Zip packages for Windows
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_cmake_build_type">
<code class="literal">
CMAKE_BUILD_TYPE
</code>
</a>
</th>
<td>
Type of build to produce
</td>
<td>
<code class="literal">
RelWithDebInfo
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_cmake_cxx_flags">
<code class="literal">
CMAKE_CXX_FLAGS
</code>
</a>
</th>
<td>
Flags for C++ Compiler
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_cmake_c_flags">
<code class="literal">
CMAKE_C_FLAGS
</code>
</a>
</th>
<td>
Flags for C Compiler
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_cmake_install_prefix">
<code class="literal">
CMAKE_INSTALL_PREFIX
</code>
</a>
</th>
<td>
Installation base directory
</td>
<td>
<code class="literal">
/usr/local/mysql
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment">
<code class="literal">
COMPILATION_COMMENT
</code>
</a>
</th>
<td>
Comment about compilation environment
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment_server">
<code class="literal">
COMPILATION_COMMENT_SERVER
</code>
</a>
</th>
<td>
Comment about compilation environment for use by mysqld
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_compress_debug_sections">
<code class="literal">
COMPRESS_DEBUG_SECTIONS
</code>
</a>
</th>
<td>
Compress debug sections of binary executables
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_cpack_monolithic_install">
<code class="literal">
CPACK_MONOLITHIC_INSTALL
</code>
</a>
</th>
<td>
Whether package build produces single file
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_default_charset">
<code class="literal">
DEFAULT_CHARSET
</code>
</a>
</th>
<td>
The default server character set
</td>
<td>
<code class="literal">
utf8mb4
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_default_collation">
<code class="literal">
DEFAULT_COLLATION
</code>
</a>
</th>
<td>
The default server collation
</td>
<td>
<code class="literal">
utf8mb4_0900_ai_ci
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_cond">
<code class="literal">
DISABLE_PSI_COND
</code>
</a>
</th>
<td>
Exclude Performance Schema condition instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_data_lock">
<code class="literal">
DISABLE_PSI_DATA_LOCK
</code>
</a>
</th>
<td>
Exclude the performance schema data lock instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_error">
<code class="literal">
DISABLE_PSI_ERROR
</code>
</a>
</th>
<td>
Exclude the performance schema server error instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_file">
<code class="literal">
DISABLE_PSI_FILE
</code>
</a>
</th>
<td>
Exclude Performance Schema file instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_idle">
<code class="literal">
DISABLE_PSI_IDLE
</code>
</a>
</th>
<td>
Exclude Performance Schema idle instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_memory">
<code class="literal">
DISABLE_PSI_MEMORY
</code>
</a>
</th>
<td>
Exclude Performance Schema memory instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_metadata">
<code class="literal">
DISABLE_PSI_METADATA
</code>
</a>
</th>
<td>
Exclude Performance Schema metadata instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_mutex">
<code class="literal">
DISABLE_PSI_MUTEX
</code>
</a>
</th>
<td>
Exclude Performance Schema mutex instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_ps">
<code class="literal">
DISABLE_PSI_PS
</code>
</a>
</th>
<td>
Exclude the performance schema prepared statements
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_rwlock">
<code class="literal">
DISABLE_PSI_RWLOCK
</code>
</a>
</th>
<td>
Exclude Performance Schema rwlock instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_socket">
<code class="literal">
DISABLE_PSI_SOCKET
</code>
</a>
</th>
<td>
Exclude Performance Schema socket instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_sp">
<code class="literal">
DISABLE_PSI_SP
</code>
</a>
</th>
<td>
Exclude Performance Schema stored program instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_stage">
<code class="literal">
DISABLE_PSI_STAGE
</code>
</a>
</th>
<td>
Exclude Performance Schema stage instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_statement">
<code class="literal">
DISABLE_PSI_STATEMENT
</code>
</a>
</th>
<td>
Exclude Performance Schema statement instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_statement_digest">
<code class="literal">
DISABLE_PSI_STATEMENT_DIGEST
</code>
</a>
</th>
<td>
Exclude Performance Schema statements_digest instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_table">
<code class="literal">
DISABLE_PSI_TABLE
</code>
</a>
</th>
<td>
Exclude Performance Schema table instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_thread">
<code class="literal">
DISABLE_PSI_THREAD
</code>
</a>
</th>
<td>
Exclude the performance schema thread instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_transaction">
<code class="literal">
DISABLE_PSI_TRANSACTION
</code>
</a>
</th>
<td>
Exclude the performance schema transaction instrumentation
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_enabled_local_infile">
<code class="literal">
ENABLED_LOCAL_INFILE
</code>
</a>
</th>
<td>
Whether to enable LOCAL for LOAD DATA
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_enabled_profiling">
<code class="literal">
ENABLED_PROFILING
</code>
</a>
</th>
<td>
Whether to enable query profiling code
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_enable_experimental_sysvars">
<code class="literal">
ENABLE_EXPERIMENTAL_SYSVARS
</code>
</a>
</th>
<td>
Whether to enabled experimental InnoDB system variables
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_enable_gcov">
<code class="literal">
ENABLE_GCOV
</code>
</a>
</th>
<td>
Whether to include gcov support
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_enable_gprof">
<code class="literal">
ENABLE_GPROF
</code>
</a>
</th>
<td>
Enable gprof (optimized Linux builds only)
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_force_colored_output">
<code class="literal">
FORCE_COLORED_OUTPUT
</code>
</a>
</th>
<td>
Whether to colorize compiler output
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_force_insource_build">
<code class="literal">
FORCE_INSOURCE_BUILD
</code>
</a>
</th>
<td>
Whether to force an in-source build
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_force_unsupported_compiler">
<code class="literal">
FORCE_UNSUPPORTED_COMPILER
</code>
</a>
</th>
<td>
Whether to permit unsupported compilers
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_generate">
<code class="literal">
FPROFILE_GENERATE
</code>
</a>
</th>
<td>
Whether to generate profile guided optimization data
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_use">
<code class="literal">
FPROFILE_USE
</code>
</a>
</th>
<td>
Whether to use profile guided optimization data
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_have_psi_memory_interface">
<code class="literal">
HAVE_PSI_MEMORY_INTERFACE
</code>
</a>
</th>
<td>
Enable performance schema memory tracing module for memory allocation functions used in dynamic storage of over-aligned types
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_ignore_aio_check">
<code class="literal">
IGNORE_AIO_CHECK
</code>
</a>
</th>
<td>
With -DBUILD_CONFIG=mysql_release, ignore libaio check
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_bindir">
<code class="literal">
INSTALL_BINDIR
</code>
</a>
</th>
<td>
User executables directory
</td>
<td>
<code class="literal">
PREFIX/bin
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_docdir">
<code class="literal">
INSTALL_DOCDIR
</code>
</a>
</th>
<td>
Documentation directory
</td>
<td>
<code class="literal">
PREFIX/docs
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_docreadmedir">
<code class="literal">
INSTALL_DOCREADMEDIR
</code>
</a>
</th>
<td>
README file directory
</td>
<td>
<code class="literal">
PREFIX
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_includedir">
<code class="literal">
INSTALL_INCLUDEDIR
</code>
</a>
</th>
<td>
Header file directory
</td>
<td>
<code class="literal">
PREFIX/include
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_infodir">
<code class="literal">
INSTALL_INFODIR
</code>
</a>
</th>
<td>
Info file directory
</td>
<td>
<code class="literal">
PREFIX/docs
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_layout">
<code class="literal">
INSTALL_LAYOUT
</code>
</a>
</th>
<td>
Select predefined installation layout
</td>
<td>
<code class="literal">
STANDALONE
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_libdir">
<code class="literal">
INSTALL_LIBDIR
</code>
</a>
</th>
<td>
Library file directory
</td>
<td>
<code class="literal">
PREFIX/lib
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_mandir">
<code class="literal">
INSTALL_MANDIR
</code>
</a>
</th>
<td>
Manual page directory
</td>
<td>
<code class="literal">
PREFIX/man
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_mysqlsharedir">
<code class="literal">
INSTALL_MYSQLSHAREDIR
</code>
</a>
</th>
<td>
Shared data directory
</td>
<td>
<code class="literal">
PREFIX/share
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_mysqltestdir">
<code class="literal">
INSTALL_MYSQLTESTDIR
</code>
</a>
</th>
<td>
mysql-test directory
</td>
<td>
<code class="literal">
PREFIX/mysql-test
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_pkgconfigdir">
<code class="literal">
INSTALL_PKGCONFIGDIR
</code>
</a>
</th>
<td>
Directory for mysqlclient.pc pkg-config file
</td>
<td>
<code class="literal">
INSTALL_LIBDIR/pkgconfig
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_plugindir">
<code class="literal">
INSTALL_PLUGINDIR
</code>
</a>
</th>
<td>
Plugin directory
</td>
<td>
<code class="literal">
PREFIX/lib/plugin
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_priv_libdir">
<code class="literal">
INSTALL_PRIV_LIBDIR
</code>
</a>
</th>
<td>
Installation private library directory
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_sbindir">
<code class="literal">
INSTALL_SBINDIR
</code>
</a>
</th>
<td>
Server executable directory
</td>
<td>
<code class="literal">
PREFIX/bin
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_secure_file_privdir">
<code class="literal">
INSTALL_SECURE_FILE_PRIVDIR
</code>
</a>
</th>
<td>
secure_file_priv default value
</td>
<td>
<code class="literal">
platform specific
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_sharedir">
<code class="literal">
INSTALL_SHAREDIR
</code>
</a>
</th>
<td>
aclocal/mysql.m4 installation directory
</td>
<td>
<code class="literal">
PREFIX/share
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_static_libraries">
<code class="literal">
INSTALL_STATIC_LIBRARIES
</code>
</a>
</th>
<td>
Whether to install static libraries
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_install_supportfilesdir">
<code class="literal">
INSTALL_SUPPORTFILESDIR
</code>
</a>
</th>
<td>
Extra support files directory
</td>
<td>
<code class="literal">
PREFIX/support-files
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_link_randomize">
<code class="literal">
LINK_RANDOMIZE
</code>
</a>
</th>
<td>
Whether to randomize order of symbols in mysqld binary
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_link_randomize_seed">
<code class="literal">
LINK_RANDOMIZE_SEED
</code>
</a>
</th>
<td>
Seed value for LINK_RANDOMIZE option
</td>
<td>
<code class="literal">
mysql
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_max_indexes">
<code class="literal">
MAX_INDEXES
</code>
</a>
</th>
<td>
Maximum indexes per table
</td>
<td>
<code class="literal">
64
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_msvc_cppcheck">
<code class="literal">
MSVC_CPPCHECK
</code>
</a>
</th>
<td>
Enable MSVC code analysis.
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mutex_type">
<code class="literal">
MUTEX_TYPE
</code>
</a>
</th>
<td>
InnoDB mutex type
</td>
<td>
<code class="literal">
event
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysqlx_tcp_port">
<code class="literal">
MYSQLX_TCP_PORT
</code>
</a>
</th>
<td>
TCP/IP port number used by X Plugin
</td>
<td>
<code class="literal">
33060
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysqlx_unix_addr">
<code class="literal">
MYSQLX_UNIX_ADDR
</code>
</a>
</th>
<td>
Unix socket file used by X Plugin
</td>
<td>
<code class="literal">
/tmp/mysqlx.sock
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysql_datadir">
<code class="literal">
MYSQL_DATADIR
</code>
</a>
</th>
<td>
Data directory
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysql_maintainer_mode">
<code class="literal">
MYSQL_MAINTAINER_MODE
</code>
</a>
</th>
<td>
Whether to enable MySQL maintainer-specific development environment
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysql_project_name">
<code class="literal">
MYSQL_PROJECT_NAME
</code>
</a>
</th>
<td>
Windows/macOS project name
</td>
<td>
<code class="literal">
MySQL
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysql_tcp_port">
<code class="literal">
MYSQL_TCP_PORT
</code>
</a>
</th>
<td>
TCP/IP port number
</td>
<td>
<code class="literal">
3306
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_mysql_unix_addr">
<code class="literal">
MYSQL_UNIX_ADDR
</code>
</a>
</th>
<td>
Unix socket file
</td>
<td>
<code class="literal">
/tmp/mysql.sock
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_ndb_utils_link_dynamic">
<code class="literal">
NDB_UTILS_LINK_DYNAMIC
</code>
</a>
</th>
<td>
Cause NDB tools to be dynamically linked to ndbclient
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_odbc_includes">
<code class="literal">
ODBC_INCLUDES
</code>
</a>
</th>
<td>
ODBC includes directory
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_odbc_lib_dir">
<code class="literal">
ODBC_LIB_DIR
</code>
</a>
</th>
<td>
ODBC library directory
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_optimizer_trace">
<code class="literal">
OPTIMIZER_TRACE
</code>
</a>
</th>
<td>
Whether to support optimizer tracing
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_optimize_sanitizer_builds">
<code class="literal">
OPTIMIZE_SANITIZER_BUILDS
</code>
</a>
</th>
<td>
Whether to optimize sanitizer builds
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_reproducible_build">
<code class="literal">
REPRODUCIBLE_BUILD
</code>
</a>
</th>
<td>
Take extra care to create a build result independent of build location and time
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_show_suppressed_compiler_warnings">
<code class="literal">
SHOW_SUPPRESSED_COMPILER_WARNING
</code>
</a>
</th>
<td>
Whether to show suppressed compiler warnings and not fail with -Werror.
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_sysconfdir">
<code class="literal">
SYSCONFDIR
</code>
</a>
</th>
<td>
Option file directory
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_systemd_pid_dir">
<code class="literal">
SYSTEMD_PID_DIR
</code>
</a>
</th>
<td>
Directory for PID file under systemd
</td>
<td>
<code class="literal">
/var/run/mysqld
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_systemd_service_name">
<code class="literal">
SYSTEMD_SERVICE_NAME
</code>
</a>
</th>
<td>
Name of MySQL service under systemd
</td>
<td>
<code class="literal">
mysqld
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_tmpdir">
<code class="literal">
TMPDIR
</code>
</a>
</th>
<td>
tmpdir default value
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_win_debug_no_inline">
<code class="literal">
WIN_DEBUG_NO_INLINE
</code>
</a>
</th>
<td>
Whether to disable function inlining
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_without_server">
<code class="literal">
WITHOUT_SERVER
</code>
</a>
</th>
<td>
Do not build the server
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_storage_engine_options" title="Storage Engine Options">
<code class="literal">
WITHOUT_xxx_STORAGE_ENGINE
</code>
</a>
</th>
<td>
Exclude storage engine xxx from build
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ant">
<code class="literal">
WITH_ANT
</code>
</a>
</th>
<td>
Path to Ant for building GCS Java wrapper
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_asan">
<code class="literal">
WITH_ASAN
</code>
</a>
</th>
<td>
Enable AddressSanitizer
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_asan_scope">
<code class="literal">
WITH_ASAN_SCOPE
</code>
</a>
</th>
<td>
Enable AddressSanitizer -fsanitize-address-use-after-scope Clang flag
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_authentication_client_plugins">
<code class="literal">
WITH_AUTHENTICATION_CLIENT_PLUGINS
</code>
</a>
</th>
<td>
Enabled automatically if any corresponding server authentication plugins are built
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_authentication_ldap">
<code class="literal">
WITH_AUTHENTICATION_LDAP
</code>
</a>
</th>
<td>
Whether to report error if LDAP authentication plugins cannot be built
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_authentication_pam">
<code class="literal">
WITH_AUTHENTICATION_PAM
</code>
</a>
</th>
<td>
Build PAM authentication plugin
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_aws_sdk">
<code class="literal">
WITH_AWS_SDK
</code>
</a>
</th>
<td>
Location of Amazon Web Services software development kit
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_build_id">
<code class="literal">
WITH_BUILD_ID
</code>
</a>
</th>
<td>
On Linux systems, generate a unique build ID
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_classpath">
<code class="literal">
WITH_CLASSPATH
</code>
</a>
</th>
<td>
Classpath to use when building MySQL Cluster Connector for Java. Default is an empty string.
</td>
<td>
<code class="literal">
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_client_protocol_tracing">
<code class="literal">
WITH_CLIENT_PROTOCOL_TRACING
</code>
</a>
</th>
<td>
Build client-side protocol tracing framework
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_curl">
<code class="literal">
WITH_CURL
</code>
</a>
</th>
<td>
Location of curl library
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="literal">
WITH_DEBUG
</code>
</a>
</th>
<td>
Whether to include debugging support
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_default_compiler_options">
<code class="literal">
WITH_DEFAULT_COMPILER_OPTIONS
</code>
</a>
</th>
<td>
Whether to use default compiler options
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_developer_entitlements">
<code class="literal">
WITH_DEVELOPER_ENTITLEMENTS
</code>
</a>
</th>
<td>
Whether to add the 'get-task-allow' entitlement to all executables on macOS to generate a core dump in the event of an unexpected server halt
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_editline">
<code class="literal">
WITH_EDITLINE
</code>
</a>
</th>
<td>
Which libedit/editline library to use
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_error_insert">
<code class="literal">
WITH_ERROR_INSERT
</code>
</a>
</th>
<td>
Enable error injection in the NDB storage engine. Should not be used for building binaries intended for production.
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_icu">
<code class="literal">
WITH_ICU
</code>
</a>
</th>
<td>
Type of ICU support
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_innodb_extra_debug">
<code class="literal">
WITH_INNODB_EXTRA_DEBUG
</code>
</a>
</th>
<td>
Whether to include extra debugging support for InnoDB.
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_jemalloc">
<code class="literal">
WITH_JEMALLOC
</code>
</a>
</th>
<td>
Whether to link with -ljemalloc
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ld">
<code class="literal">
WITH_LD
</code>
</a>
</th>
<td>
Whether to use the LLVM lld or mold linker
</td>
<td>
<code class="literal">
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_libevent">
<code class="literal">
WITH_LIBEVENT
</code>
</a>
</th>
<td>
Which libevent library to use
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_libwrap">
<code class="literal">
WITH_LIBWRAP
</code>
</a>
</th>
<td>
Whether to include libwrap (TCP wrappers) support
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_lock_order">
<code class="literal">
WITH_LOCK_ORDER
</code>
</a>
</th>
<td>
Whether to enable LOCK_ORDER tooling
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_lsan">
<code class="literal">
WITH_LSAN
</code>
</a>
</th>
<td>
Whether to run LeakSanitizer, without AddressSanitizer
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_lto">
<code class="literal">
WITH_LTO
</code>
</a>
</th>
<td>
Enable link-time optimizer
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_lz4">
<code class="literal">
WITH_LZ4
</code>
</a>
</th>
<td>
Type of LZ4 library support
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_mecab">
<code class="literal">
WITH_MECAB
</code>
</a>
</th>
<td>
Compiles MeCab
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_msan">
<code class="literal">
WITH_MSAN
</code>
</a>
</th>
<td>
Enable MemorySanitizer
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_mscrt_debug">
<code class="literal">
WITH_MSCRT_DEBUG
</code>
</a>
</th>
<td>
Enable Visual Studio CRT memory leak tracing
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_mysqlx">
<code class="literal">
WITH_MYSQLX
</code>
</a>
</th>
<td>
Whether to disable X Protocol
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb">
<code class="literal">
WITH_NDB
</code>
</a>
</th>
<td>
Build MySQL NDB Cluster, including NDB storage engine and all NDB programs
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbapi_examples">
<code class="literal">
WITH_NDBAPI_EXAMPLES
</code>
</a>
</th>
<td>
Build API example programs.
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbcluster">
<code class="literal">
WITH_NDBCLUSTER
</code>
</a>
</th>
<td>
NDB 8.0.30 and earlier: Build NDB storage engine. NDB 8.0.31 and later: Deprecated; use WITH_NDB instead
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbcluster_storage_engine">
<code class="literal">
WITH_NDBCLUSTER_STORAGE_ENGINE
</code>
</a>
</th>
<td>
Prior to NDB 8.0.31, this was for internal use only. NDB 8.0.31 and later: toggles (only) inclusion of NDBCLUSTER storage engine
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbmtd">
<code class="literal">
WITH_NDBMTD
</code>
</a>
</th>
<td>
Build multithreaded data node binary
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_debug">
<code class="literal">
WITH_NDB_DEBUG
</code>
</a>
</th>
<td>
Produce a debug build for testing or troubleshooting.
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_java">
<code class="literal">
WITH_NDB_JAVA
</code>
</a>
</th>
<td>
Enable building of Java and ClusterJ support. Enabled by default. Supported in MySQL Cluster only.
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_port">
<code class="literal">
WITH_NDB_PORT
</code>
</a>
</th>
<td>
Default port used by a management server built with this option. If this option was not used to build it, the management server's default port is 1186.
</td>
<td>
<code class="literal">
[none]
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_test">
<code class="literal">
WITH_NDB_TEST
</code>
</a>
</th>
<td>
Include NDB API test programs.
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_tls_search_path">
<code class="literal">
WITH_NDB_TLS_SEARCH_PATH
</code>
</a>
</th>
<td>
Default path used by NDB programs to search for TLS certificate and key files.
</td>
<td>
<code class="literal">
$HOME/ndb-tls
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_numa">
<code class="literal">
WITH_NUMA
</code>
</a>
</th>
<td>
Set NUMA memory allocation policy
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_package_flags">
<code class="literal">
WITH_PACKAGE_FLAGS
</code>
</a>
</th>
<td>
For flags typically used for RPM/DEB packages, whether to add them to standalone builds on those platforms
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_protobuf">
<code class="literal">
WITH_PROTOBUF
</code>
</a>
</th>
<td>
Which Protocol Buffers package to use
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_rapid">
<code class="literal">
WITH_RAPID
</code>
</a>
</th>
<td>
Whether to build rapid development cycle plugins
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_rapidjson">
<code class="literal">
WITH_RAPIDJSON
</code>
</a>
</th>
<td>
Type of RapidJSON support
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_router">
<code class="literal">
WITH_ROUTER
</code>
</a>
</th>
<td>
Whether to build MySQL Router
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_sasl">
<code class="literal">
WITH_SASL
</code>
</a>
</th>
<td>
Internal use only
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_show_parse_tree">
<code class="literal">
WITH_SHOW_PARSE_TREE
</code>
</a>
</th>
<td>
Support for SHOW PARSE_TREE debugging statement
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ssl">
<code class="literal">
WITH_SSL
</code>
</a>
</th>
<td>
Type of SSL support
</td>
<td>
<code class="literal">
system
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd">
<code class="literal">
WITH_SYSTEMD
</code>
</a>
</th>
<td>
Enable installation of systemd support files
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd_debug">
<code class="literal">
WITH_SYSTEMD_DEBUG
</code>
</a>
</th>
<td>
Enable additional systemd debug information
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_system_libs">
<code class="literal">
WITH_SYSTEM_LIBS
</code>
</a>
</th>
<td>
Set system value of library options not set explicitly
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_tcmalloc">
<code class="literal">
WITH_TCMALLOC
</code>
</a>
</th>
<td>
Whether to link with -ltcmalloc. BUNDLED is supported on Linux only
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_test_trace_plugin">
<code class="literal">
WITH_TEST_TRACE_PLUGIN
</code>
</a>
</th>
<td>
Build test protocol trace plugin
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_tsan">
<code class="literal">
WITH_TSAN
</code>
</a>
</th>
<td>
Enable ThreadSanitizer
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_ubsan">
<code class="literal">
WITH_UBSAN
</code>
</a>
</th>
<td>
Enable Undefined Behavior Sanitizer
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_unit_tests">
<code class="literal">
WITH_UNIT_TESTS
</code>
</a>
</th>
<td>
Compile MySQL with unit tests
</td>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_unixodbc">
<code class="literal">
WITH_UNIXODBC
</code>
</a>
</th>
<td>
Enable unixODBC support
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_valgrind">
<code class="literal">
WITH_VALGRIND
</code>
</a>
</th>
<td>
Whether to compile in Valgrind header files
</td>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_win_jemalloc">
<code class="literal">
WITH_WIN_JEMALLOC
</code>
</a>
</th>
<td>
Path to directory containing jemalloc.dll
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_zlib">
<code class="literal">
WITH_ZLIB
</code>
</a>
</th>
<td>
Type of zlib support
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_with_zstd">
<code class="literal">
WITH_ZSTD
</code>
</a>
</th>
<td>
Type of zstd support
</td>
<td>
<code class="literal">
bundled
</code>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="source-configuration-options.html#option_cmake_storage_engine_options" title="Storage Engine Options">
<code class="literal">
WITH_xxx_STORAGE_ENGINE
</code>
</a>
</th>
<td>
Compile storage engine xxx statically into server
</td>
<td>
</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 scope="col" style="width: 283.266px;">
Formats
</th>
<th scope="col" style="width: 252.719px;">
Description
</th>
<th scope="col" style="width: 202.016px;">
Default
</th>
</tr>
</thead>
</table>
</div>
</div>
<br class="table-break"/>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="cmake-general-options">
</a>
General Options
</h4>
</div>
</div>
</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_cmake_build_config">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_build_config">
<code class="option">
-DBUILD_CONFIG=mysql_release
</code>
</a>
</p>
<a class="indexterm" name="idm46045328641824">
</a>
<a class="indexterm" name="idm46045328640336">
</a>
<p>
This option configures a source distribution with the same
build options used by Oracle to produce binary distributions
for official MySQL releases.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_build_id">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_build_id">
<code class="option">
-DWITH_BUILD_ID=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328635728">
</a>
<a class="indexterm" name="idm46045328634240">
</a>
<p>
On Linux systems, generates a unique build ID which is used
as the value of the
<a class="link" href="server-system-variables.html#sysvar_build_id">
<code class="literal">
build_id
</code>
</a>
system variable
and written to the MySQL server log on startup. Set this
option to
<code class="literal">
OFF
</code>
to disable this feature.
</p>
<p>
This option has no effect on platforms other than Linux.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_bundle_runtime_libraries">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_bundle_runtime_libraries">
<code class="option">
-DBUNDLE_RUNTIME_LIBRARIES=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328627216">
</a>
<a class="indexterm" name="idm46045328625712">
</a>
<p>
Whether to bundle runtime libraries with server MSI and Zip
packages for Windows.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_cmake_build_type">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_cmake_build_type">
<code class="option">
-DCMAKE_BUILD_TYPE=
<em class="replaceable">
<code>
type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328621232">
</a>
<a class="indexterm" name="idm46045328619744">
</a>
<p>
The type of build to produce:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
RelWithDebInfo
</code>
: Enable optimizations
and generate debugging information. This is the default
MySQL build type.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Release
</code>
: Enable optimizations but
omit debugging information to reduce the build size.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Debug
</code>
: Disable optimizations and
generate debugging information. This build type is also
used if the
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
WITH_DEBUG
</code>
</a>
option is enabled. That is,
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
-DWITH_DEBUG=1
</code>
</a>
has the
same effect as
<a class="link" href="source-configuration-options.html#option_cmake_cmake_build_type">
<code class="option">
-DCMAKE_BUILD_TYPE=Debug
</code>
</a>
.
</p>
</li>
</ul>
</div>
<p>
The option values
<code class="literal">
None
</code>
and
<code class="literal">
MinSizeRel
</code>
are not supported.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_cpack_monolithic_install">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_cpack_monolithic_install">
<code class="option">
-DCPACK_MONOLITHIC_INSTALL=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328605264">
</a>
<a class="indexterm" name="idm46045328603760">
</a>
<p>
This option affects whether the
<span class="command">
<strong>
make
package
</strong>
</span>
operation produces multiple installation
package files or a single file. If disabled, the operation
produces multiple installation package files, which may be
useful if you want to install only a subset of a full MySQL
installation. If enabled, it produces a single file for
installing everything.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_force_insource_build">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_force_insource_build">
<code class="option">
-DFORCE_INSOURCE_BUILD=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328598192">
</a>
<a class="indexterm" name="idm46045328596736">
</a>
<p>
Defines whether to force an in-source build. Out-of-source
builds are recommended, as they permit multiple builds from
the same source, and cleanup can be performed quickly by
removing the build directory. To force an in-source build,
invoke
<span class="command">
<strong>
CMake
</strong>
</span>
with
<a class="link" href="source-configuration-options.html#option_cmake_force_insource_build">
<code class="option">
-DFORCE_INSOURCE_BUILD=ON
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_force_colored_output">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_force_colored_output">
<code class="option">
-DFORCE_COLORED_OUTPUT=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328590336">
</a>
<a class="indexterm" name="idm46045328588880">
</a>
<p>
Defines whether to enable colorized compiler output for
<span class="command">
<strong>
gcc
</strong>
</span>
and
<span class="command">
<strong>
clang
</strong>
</span>
when
compiling on the command line. Defaults to
<code class="literal">
OFF
</code>
.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="cmake-installation-layout-options">
</a>
Installation Layout Options
</h4>
</div>
</div>
</div>
<p>
The
<a class="link" href="source-configuration-options.html#option_cmake_cmake_install_prefix">
<code class="option">
CMAKE_INSTALL_PREFIX
</code>
</a>
option
indicates the base installation directory. Other options with
names of the form
<code class="literal">
INSTALL_
<em class="replaceable">
<code>
xxx
</code>
</em>
</code>
that
indicate component locations are interpreted relative to the
prefix and their values are relative pathnames. Their values
should not include the prefix.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_cmake_cmake_install_prefix">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_cmake_install_prefix">
<code class="option">
-DCMAKE_INSTALL_PREFIX=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328577792">
</a>
<a class="indexterm" name="idm46045328576336">
</a>
<p>
The installation base directory.
</p>
<p>
This value can be set at server startup using the
<a class="link" href="server-system-variables.html#sysvar_basedir">
<code class="option">
--basedir
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_bindir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_bindir">
<code class="option">
-DINSTALL_BINDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328570400">
</a>
<a class="indexterm" name="idm46045328568912">
</a>
<p>
Where to install user programs.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_docdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_docdir">
<code class="option">
-DINSTALL_DOCDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328564560">
</a>
<a class="indexterm" name="idm46045328563072">
</a>
<p>
Where to install documentation.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_docreadmedir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_docreadmedir">
<code class="option">
-DINSTALL_DOCREADMEDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328558656">
</a>
<a class="indexterm" name="idm46045328557200">
</a>
<p>
Where to install
<code class="filename">
README
</code>
files.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_includedir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_includedir">
<code class="option">
-DINSTALL_INCLUDEDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328552080">
</a>
<a class="indexterm" name="idm46045328550624">
</a>
<p>
Where to install header files.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_infodir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_infodir">
<code class="option">
-DINSTALL_INFODIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328546144">
</a>
<a class="indexterm" name="idm46045328544656">
</a>
<p>
Where to install Info files.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_layout">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_layout">
<code class="option">
-DINSTALL_LAYOUT=
<em class="replaceable">
<code>
name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328540240">
</a>
<a class="indexterm" name="idm46045328538752">
</a>
<p>
Select a predefined installation layout:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
STANDALONE
</code>
: Same layout as used for
<code class="filename">
.tar.gz
</code>
and
<code class="filename">
.zip
</code>
packages. This is the default.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
RPM
</code>
: Layout similar to RPM packages.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SVR4
</code>
: Solaris package layout.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
DEB
</code>
: DEB package layout
(experimental).
</p>
</li>
</ul>
</div>
<p>
You can select a predefined layout but modify individual
component installation locations by specifying other
options. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa18357326"><div class="copy-help left">Press ⌘+C to 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">cmake <span class="token punctuation">.</span> <span class="token constant">-DINSTALL_LAYOUT</span><span class="token attr-value"><span class="token punctuation">=</span>SVR4</span> <span class="token constant">-DMYSQL_DATADIR</span><span class="token attr-value"><span class="token punctuation">=</span>/var/mysql/data</span></code></pre>
</div>
<p>
The
<a class="link" href="source-configuration-options.html#option_cmake_install_layout">
<code class="option">
INSTALL_LAYOUT
</code>
</a>
value
determines the default value of the
<a class="link" href="server-system-variables.html#sysvar_secure_file_priv">
<code class="literal">
secure_file_priv
</code>
</a>
system
variable. See the description of this variable in
<a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables">
Section 7.1.8, “Server System Variables”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_libdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_libdir">
<code class="option">
-DINSTALL_LIBDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328521488">
</a>
<a class="indexterm" name="idm46045328520000">
</a>
<p>
Where to install library files.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_mandir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_mandir">
<code class="option">
-DINSTALL_MANDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328515648">
</a>
<a class="indexterm" name="idm46045328514160">
</a>
<p>
Where to install manual pages.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_mysqlsharedir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_mysqlsharedir">
<code class="option">
-DINSTALL_MYSQLSHAREDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328509776">
</a>
<a class="indexterm" name="idm46045328508272">
</a>
<p>
Where to install shared data files.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_mysqltestdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_mysqltestdir">
<code class="option">
-DINSTALL_MYSQLTESTDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328503840">
</a>
<a class="indexterm" name="idm46045328502384">
</a>
<p>
Where to install the
<code class="filename">
mysql-test
</code>
directory. To suppress installation of this directory,
explicitly set the option to the empty value
(
<a class="link" href="source-configuration-options.html#option_cmake_install_mysqltestdir">
<code class="option">
-DINSTALL_MYSQLTESTDIR=
</code>
</a>
).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_pkgconfigdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_pkgconfigdir">
<code class="option">
-DINSTALL_PKGCONFIGDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328496144">
</a>
<a class="indexterm" name="idm46045328494688">
</a>
<p>
The directory in which to install the
<code class="filename">
mysqlclient.pc
</code>
file for use by
<span class="command">
<strong>
pkg-config
</strong>
</span>
. The default value is
<code class="literal">
INSTALL_LIBDIR/pkgconfig
</code>
, unless
<a class="link" href="source-configuration-options.html#option_cmake_install_libdir">
<code class="option">
INSTALL_LIBDIR
</code>
</a>
ends with
<code class="literal">
/mysql
</code>
, in which case that is removed
first.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_plugindir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_plugindir">
<code class="option">
-DINSTALL_PLUGINDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328486288">
</a>
<a class="indexterm" name="idm46045328484832">
</a>
<p>
The location of the plugin directory.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="server-system-variables.html#sysvar_plugin_dir">
<code class="option">
--plugin_dir
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_priv_libdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_priv_libdir">
<code class="option">
-DINSTALL_PRIV_LIBDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328478960">
</a>
<a class="indexterm" name="idm46045328477504">
</a>
<p>
The location of the dynamic library directory.
</p>
<p>
<b>
Default location.
</b>
For RPM builds, this is
<code class="filename">
/usr/lib64/mysql/private/
</code>
, for DEB it
is
<code class="filename">
/usr/lib/mysql/private/
</code>
, and for
TAR it is
<code class="filename">
lib/private/
</code>
.
</p>
<p>
<b>
Protobuf.
</b>
Because this is a private location, the loader (such as
<code class="filename">
ld-linux.so
</code>
on Linux) may not find
the
<code class="filename">
libprotobuf.so
</code>
files without
help. To guide the loader,
<code class="literal">
RPATH=$ORIGIN/../$INSTALL_PRIV_LIBDIR
</code>
is added to
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
and
<span class="command">
<strong>
mysqlxtest
</strong>
</span>
. This works for most cases
but when using the
<a class="link" href="resource-groups.html" title="7.1.16 Resource Groups">
Resource Group
</a>
feature,
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
is
<code class="literal">
setsuid
</code>
, and the loader ignores any
<code class="literal">
RPATH
</code>
which contains
<code class="literal">
$ORIGIN
</code>
. To overcome this, an explicit
full path to the directory is set in the DEB and RPM
versions of
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
, since the target
destination is known. For tarball installs, patching of
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with a tool like
<span class="command">
<strong>
patchelf
</strong>
</span>
is required.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_sbindir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_sbindir">
<code class="option">
-DINSTALL_SBINDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328456176">
</a>
<a class="indexterm" name="idm46045328454688">
</a>
<p>
Where to install the
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
server.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_secure_file_privdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_secure_file_privdir">
<code class="option">
-DINSTALL_SECURE_FILE_PRIVDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328448960">
</a>
<a class="indexterm" name="idm46045328447456">
</a>
<p>
The default value for the
<a class="link" href="server-system-variables.html#sysvar_secure_file_priv">
<code class="literal">
secure_file_priv
</code>
</a>
system
variable. The default value is platform specific and depends
on the value of the
<a class="link" href="source-configuration-options.html#option_cmake_install_layout">
<code class="option">
INSTALL_LAYOUT
</code>
</a>
<span class="command">
<strong>
CMake
</strong>
</span>
option; see the description of the
<a class="link" href="server-system-variables.html#sysvar_secure_file_priv">
<code class="literal">
secure_file_priv
</code>
</a>
system
variable in
<a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables">
Section 7.1.8, “Server System Variables”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_sharedir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_sharedir">
<code class="option">
-DINSTALL_SHAREDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328438064">
</a>
<a class="indexterm" name="idm46045328436576">
</a>
<p>
Where to install
<code class="filename">
aclocal/mysql.m4
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_static_libraries">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_static_libraries">
<code class="option">
-DINSTALL_STATIC_LIBRARIES=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328431488">
</a>
<a class="indexterm" name="idm46045328429984">
</a>
<p>
Whether to install static libraries. The default is
<code class="literal">
ON
</code>
. If set to
<code class="literal">
OFF
</code>
,
these library files are not installed:
<code class="filename">
libmysqlclient.a
</code>
,
<code class="filename">
libmysqlservices.a
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_install_supportfilesdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_install_supportfilesdir">
<code class="option">
-DINSTALL_SUPPORTFILESDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328422704">
</a>
<a class="indexterm" name="idm46045328421200">
</a>
<p>
Where to install extra support files.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_link_randomize">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_link_randomize">
<code class="option">
-DLINK_RANDOMIZE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328416704">
</a>
<a class="indexterm" name="idm46045328415216">
</a>
<p>
Whether to randomize the order of symbols in the
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
binary. The default is
<code class="literal">
OFF
</code>
. This option should be enabled only
for debugging purposes.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_link_randomize_seed">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_link_randomize_seed">
<code class="option">
-DLINK_RANDOMIZE_SEED=
<em class="replaceable">
<code>
val
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328408864">
</a>
<a class="indexterm" name="idm46045328407360">
</a>
<p>
Seed value for the
<a class="link" href="source-configuration-options.html#option_cmake_link_randomize">
<code class="option">
LINK_RANDOMIZE
</code>
</a>
option. The
value is a string. The default is
<code class="literal">
mysql
</code>
,
an arbitrary choice.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysql_datadir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysql_datadir">
<code class="option">
-DMYSQL_DATADIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328401088">
</a>
<a class="indexterm" name="idm46045328399600">
</a>
<p>
The location of the MySQL data directory.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="server-system-variables.html#sysvar_datadir">
<code class="option">
--datadir
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_odbc_includes">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_odbc_includes">
<code class="option">
-DODBC_INCLUDES=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328393728">
</a>
<a class="indexterm" name="idm46045328392240">
</a>
<p>
The location of the ODBC includes directory, which may be
used while configuring Connector/ODBC.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_odbc_lib_dir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_odbc_lib_dir">
<code class="option">
-DODBC_LIB_DIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328387744">
</a>
<a class="indexterm" name="idm46045328386256">
</a>
<p>
The location of the ODBC library directory, which may be
used while configuring Connector/ODBC.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_sysconfdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_sysconfdir">
<code class="option">
-DSYSCONFDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328381872">
</a>
<a class="indexterm" name="idm46045328380384">
</a>
<p>
The default
<code class="filename">
my.cnf
</code>
option file
directory.
</p>
<p>
This location cannot be set at server startup, but you can
start the server with a given option file using the
<a class="link" href="option-file-options.html#option_general_defaults-file">
<code class="option">
--defaults-file=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
option, where
<em class="replaceable">
<code>
file_name
</code>
</em>
is the
full path name to the file.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_systemd_pid_dir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_systemd_pid_dir">
<code class="option">
-DSYSTEMD_PID_DIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328372848">
</a>
<a class="indexterm" name="idm46045328371360">
</a>
<a class="indexterm" name="idm46045328369872">
</a>
<p>
The name of the directory in which to create the PID file
when MySQL is managed by systemd. The default is
<code class="filename">
/var/run/mysqld
</code>
; this might be changed
implicitly according to the
<a class="link" href="source-configuration-options.html#option_cmake_install_layout">
<code class="option">
INSTALL_LAYOUT
</code>
</a>
value.
</p>
<p>
This option is ignored unless
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd">
<code class="option">
WITH_SYSTEMD
</code>
</a>
is enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_systemd_service_name">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_systemd_service_name">
<code class="option">
-DSYSTEMD_SERVICE_NAME=
<em class="replaceable">
<code>
name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328362128">
</a>
<a class="indexterm" name="idm46045328360672">
</a>
<a class="indexterm" name="idm46045328359168">
</a>
<p>
The name of the MySQL service to use when MySQL is managed
by
<span class="command">
<strong>
systemd
</strong>
</span>
. The default is
<code class="literal">
mysqld
</code>
; this might be changed implicitly
according to the
<a class="link" href="source-configuration-options.html#option_cmake_install_layout">
<code class="option">
INSTALL_LAYOUT
</code>
</a>
value.
</p>
<p>
This option is ignored unless
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd">
<code class="option">
WITH_SYSTEMD
</code>
</a>
is enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_tmpdir">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_tmpdir">
<code class="option">
-DTMPDIR=
<em class="replaceable">
<code>
dir_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328350816">
</a>
<a class="indexterm" name="idm46045328349328">
</a>
<p>
The default location to use for the
<a class="link" href="server-system-variables.html#sysvar_tmpdir">
<code class="literal">
tmpdir
</code>
</a>
system variable. If
unspecified, the value defaults to
<code class="literal">
P_tmpdir
</code>
in
<code class="literal">
<stdio.h>
</code>
.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="option_cmake_storage_engine_options">
</a>
Storage Engine Options
</h4>
</div>
</div>
</div>
<p>
Storage engines are built as plugins. You can build a plugin as
a static module (compiled into the server) or a dynamic module
(built as a dynamic library that must be installed into the
server using the
<a class="link" href="install-plugin.html" title="15.7.4.4 INSTALL PLUGIN Statement">
<code class="literal">
INSTALL PLUGIN
</code>
</a>
statement or the
<a class="link" href="server-options.html#option_mysqld_plugin-load">
<code class="option">
--plugin-load
</code>
</a>
option before it can be used). Some plugins might not support
static or dynamic building.
</p>
<p>
The
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
,
<a class="link" href="myisam-storage-engine.html" title="18.2 The MyISAM Storage Engine">
<code class="literal">
MyISAM
</code>
</a>
,
<a class="link" href="merge-storage-engine.html" title="18.7 The MERGE Storage Engine">
<code class="literal">
MERGE
</code>
</a>
,
<a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine">
<code class="literal">
MEMORY
</code>
</a>
, and
<a class="link" href="csv-storage-engine.html" title="18.4 The CSV Storage Engine">
<code class="literal">
CSV
</code>
</a>
engines are mandatory (always
compiled into the server) and need not be installed explicitly.
</p>
<p>
To compile a storage engine statically into the server, use
<code class="option">
-DWITH_
<em class="replaceable">
<code>
engine
</code>
</em>
_STORAGE_ENGINE=1
</code>
.
Some permissible
<em class="replaceable">
<code>
engine
</code>
</em>
values are
<code class="literal">
ARCHIVE
</code>
,
<code class="literal">
BLACKHOLE
</code>
,
<code class="literal">
EXAMPLE
</code>
, and
<code class="literal">
FEDERATED
</code>
.
Examples:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa39212742"><div class="copy-help left">Press ⌘+C to 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">-DWITH_ARCHIVE_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>1</span>
<span class="token constant">-DWITH_BLACKHOLE_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>1</span></code></pre>
</div>
<p>
To build MySQL with support for NDB Cluster, use the
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb">
<code class="option">
WITH_NDB
</code>
</a>
option.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
It is not possible to compile without Performance Schema
support. If it is desired to compile without particular types
of instrumentation, that can be done with the following
<span class="command">
<strong>
CMake
</strong>
</span>
options:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa48586264"><div class="copy-help left">Press ⌘+C to 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">DISABLE_PSI_COND
DISABLE_PSI_DATA_LOCK
DISABLE_PSI_ERROR
DISABLE_PSI_FILE
DISABLE_PSI_IDLE
DISABLE_PSI_MEMORY
DISABLE_PSI_METADATA
DISABLE_PSI_MUTEX
DISABLE_PSI_PS
DISABLE_PSI_RWLOCK
DISABLE_PSI_SOCKET
DISABLE_PSI_SP
DISABLE_PSI_STAGE
DISABLE_PSI_STATEMENT
DISABLE_PSI_STATEMENT_DIGEST
DISABLE_PSI_TABLE
DISABLE_PSI_THREAD
DISABLE_PSI_TRANSACTION</code></pre>
</div>
<p>
For example, to compile without mutex instrumentation,
configure MySQL using
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_mutex">
<code class="option">
-DDISABLE_PSI_MUTEX=1
</code>
</a>
.
</p>
</div>
<p>
To exclude a storage engine from the build, use
<code class="option">
-DWITH_
<em class="replaceable">
<code>
engine
</code>
</em>
_STORAGE_ENGINE=0
</code>
.
Examples:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa35975126"><div class="copy-help left">Press ⌘+C to 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">-DWITH_ARCHIVE_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>0</span>
<span class="token constant">-DWITH_EXAMPLE_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>0</span>
<span class="token constant">-DWITH_FEDERATED_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>0</span></code></pre>
</div>
<p>
It is also possible to exclude a storage engine from the build
using
<code class="option">
-DWITHOUT_
<em class="replaceable">
<code>
engine
</code>
</em>
_STORAGE_ENGINE=1
</code>
(but
<code class="option">
-DWITH_
<em class="replaceable">
<code>
engine
</code>
</em>
_STORAGE_ENGINE=0
</code>
is preferred). Examples:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa89287624"><div class="copy-help left">Press ⌘+C to 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">-DWITHOUT_ARCHIVE_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>1</span>
<span class="token constant">-DWITHOUT_EXAMPLE_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>1</span>
<span class="token constant">-DWITHOUT_FEDERATED_STORAGE_ENGINE</span><span class="token attr-value"><span class="token punctuation">=</span>1</span></code></pre>
</div>
<p>
If neither
<code class="option">
-DWITH_
<em class="replaceable">
<code>
engine
</code>
</em>
_STORAGE_ENGINE
</code>
nor
<code class="option">
-DWITHOUT_
<em class="replaceable">
<code>
engine
</code>
</em>
_STORAGE_ENGINE
</code>
are specified for a given storage engine, the engine is built as
a shared module, or excluded if it cannot be built as a shared
module.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="cmake-feature-options">
</a>
Feature Options
</h4>
</div>
</div>
</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_cmake_add_gdb_index">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_add_gdb_index">
<code class="option">
-DADD_GDB_INDEX=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328309248">
</a>
<a class="indexterm" name="idm46045328307760">
</a>
<p>
This option determines whether to enable generation of a
<code class="literal">
.gdb_index
</code>
section in binaries, which
makes loading them in a debugger faster. The option is
disabled by default.
<span class="command">
<strong>
lld
</strong>
</span>
linker is used,
and is disabled by It has no effect if a linker other than
<span class="command">
<strong>
lld
</strong>
</span>
or GNU
<span class="command">
<strong>
gold
</strong>
</span>
is
used.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_compilation_comment">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment">
<code class="option">
-DCOMPILATION_COMMENT=
<em class="replaceable">
<code>
string
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328300240">
</a>
<a class="indexterm" name="idm46045328298784">
</a>
<p>
A descriptive comment about the compilation environment.
While
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
uses
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment_server">
<code class="option">
COMPILATION_COMMENT_SERVER
</code>
</a>
,
other programs use
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment">
<code class="option">
COMPILATION_COMMENT
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_compress_debug_sections">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_compress_debug_sections">
<code class="option">
-DCOMPRESS_DEBUG_SECTIONS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328291024">
</a>
<a class="indexterm" name="idm46045328289520">
</a>
<p>
Whether to compress the debug sections of binary executables
(Linux only). Compressing executable debug sections saves
space at the cost of extra CPU time during the build
process.
</p>
<p>
The default is
<code class="literal">
OFF
</code>
. If this option is not
set explicitly but the
<code class="literal">
COMPRESS_DEBUG_SECTIONS
</code>
environment
variable is set, the option takes its value from that
variable.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_compilation_comment_server">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment_server">
<code class="option">
-DCOMPILATION_COMMENT_SERVER=
<em class="replaceable">
<code>
string
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328282896">
</a>
<a class="indexterm" name="idm46045328281392">
</a>
<p>
A descriptive comment about the compilation environment for
use by
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
(for example, to set the
<a class="link" href="server-system-variables.html#sysvar_version_comment">
<code class="literal">
version_comment
</code>
</a>
system
variable). Programs other than the server use
<a class="link" href="source-configuration-options.html#option_cmake_compilation_comment">
<code class="option">
COMPILATION_COMMENT
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_default_charset">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_default_charset">
<code class="option">
-DDEFAULT_CHARSET=
<em class="replaceable">
<code>
charset_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328273216">
</a>
<a class="indexterm" name="idm46045328271728">
</a>
<p>
The server character set. By default, MySQL uses the
<code class="literal">
utf8mb4
</code>
character set.
</p>
<p>
<em class="replaceable">
<code>
charset_name
</code>
</em>
may be one of
<code class="literal">
binary
</code>
,
<code class="literal">
armscii8
</code>
,
<code class="literal">
ascii
</code>
,
<code class="literal">
big5
</code>
,
<code class="literal">
cp1250
</code>
,
<code class="literal">
cp1251
</code>
,
<code class="literal">
cp1256
</code>
,
<code class="literal">
cp1257
</code>
,
<code class="literal">
cp850
</code>
,
<code class="literal">
cp852
</code>
,
<code class="literal">
cp866
</code>
,
<code class="literal">
cp932
</code>
,
<code class="literal">
dec8
</code>
,
<code class="literal">
eucjpms
</code>
,
<code class="literal">
euckr
</code>
,
<code class="literal">
gb2312
</code>
,
<code class="literal">
gbk
</code>
,
<code class="literal">
geostd8
</code>
,
<code class="literal">
greek
</code>
,
<code class="literal">
hebrew
</code>
,
<code class="literal">
hp8
</code>
,
<code class="literal">
keybcs2
</code>
,
<code class="literal">
koi8r
</code>
,
<code class="literal">
koi8u
</code>
,
<code class="literal">
latin1
</code>
,
<code class="literal">
latin2
</code>
,
<code class="literal">
latin5
</code>
,
<code class="literal">
latin7
</code>
,
<code class="literal">
macce
</code>
,
<code class="literal">
macroman
</code>
,
<code class="literal">
sjis
</code>
,
<code class="literal">
swe7
</code>
,
<code class="literal">
tis620
</code>
,
<code class="literal">
ucs2
</code>
,
<code class="literal">
ujis
</code>
,
<code class="literal">
utf8mb3
</code>
,
<code class="literal">
utf8mb4
</code>
,
<code class="literal">
utf16
</code>
,
<code class="literal">
utf16le
</code>
,
<code class="literal">
utf32
</code>
.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="server-system-variables.html#sysvar_character_set_server">
<code class="option">
--character-set-server
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_default_collation">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_default_collation">
<code class="option">
-DDEFAULT_COLLATION=
<em class="replaceable">
<code>
collation_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328235888">
</a>
<a class="indexterm" name="idm46045328234432">
</a>
<p>
The server collation. By default, MySQL uses
<code class="literal">
utf8mb4_0900_ai_ci
</code>
. Use the
<a class="link" href="show-collation.html" title="15.7.7.5 SHOW COLLATION Statement">
<code class="literal">
SHOW COLLATION
</code>
</a>
statement to
determine which collations are available for each character
set.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="server-system-variables.html#sysvar_collation_server">
<code class="option">
--collation_server
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_cond">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_cond">
<code class="option">
-DDISABLE_PSI_COND=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328226208">
</a>
<a class="indexterm" name="idm46045328224720">
</a>
<p>
Whether to exclude the Performance Schema condition
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_file">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_file">
<code class="option">
-DDISABLE_PSI_FILE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328219536">
</a>
<a class="indexterm" name="idm46045328218048">
</a>
<p>
Whether to exclude the Performance Schema file
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_idle">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_idle">
<code class="option">
-DDISABLE_PSI_IDLE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328212864">
</a>
<a class="indexterm" name="idm46045328211376">
</a>
<p>
Whether to exclude the Performance Schema idle
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_memory">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_memory">
<code class="option">
-DDISABLE_PSI_MEMORY=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328206256">
</a>
<a class="indexterm" name="idm46045328204800">
</a>
<p>
Whether to exclude the Performance Schema memory
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_metadata">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_metadata">
<code class="option">
-DDISABLE_PSI_METADATA=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328199616">
</a>
<a class="indexterm" name="idm46045328198160">
</a>
<p>
Whether to exclude the Performance Schema metadata
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_mutex">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_mutex">
<code class="option">
-DDISABLE_PSI_MUTEX=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328192912">
</a>
<a class="indexterm" name="idm46045328191456">
</a>
<p>
Whether to exclude the Performance Schema mutex
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_rwlock">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_rwlock">
<code class="option">
-DDISABLE_PSI_RWLOCK=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328186272">
</a>
<a class="indexterm" name="idm46045328184816">
</a>
<p>
Whether to exclude the Performance Schema rwlock
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_socket">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_socket">
<code class="option">
-DDISABLE_PSI_SOCKET=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328179632">
</a>
<a class="indexterm" name="idm46045328178176">
</a>
<p>
Whether to exclude the Performance Schema socket
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_sp">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_sp">
<code class="option">
-DDISABLE_PSI_SP=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328172928">
</a>
<a class="indexterm" name="idm46045328171440">
</a>
<p>
Whether to exclude the Performance Schema stored program
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_stage">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_stage">
<code class="option">
-DDISABLE_PSI_STAGE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328166320">
</a>
<a class="indexterm" name="idm46045328164864">
</a>
<p>
Whether to exclude the Performance Schema stage
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_statement">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_statement">
<code class="option">
-DDISABLE_PSI_STATEMENT=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328159712">
</a>
<a class="indexterm" name="idm46045328158208">
</a>
<p>
Whether to exclude the Performance Schema statement
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_statement_digest">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_statement_digest">
<code class="option">
-DDISABLE_PSI_STATEMENT_DIGEST=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328152864">
</a>
<a class="indexterm" name="idm46045328151360">
</a>
<p>
Whether to exclude the Performance Schema statement digest
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_table">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_table">
<code class="option">
-DDISABLE_PSI_TABLE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328146176">
</a>
<a class="indexterm" name="idm46045328144720">
</a>
<p>
Whether to exclude the Performance Schema table
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_ps">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_ps">
<code class="option">
-DDISABLE_PSI_PS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328139536">
</a>
<a class="indexterm" name="idm46045328138048">
</a>
<p>
Exclude the Performance Schema prepared statements instances
instrumentation. The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_thread">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_thread">
<code class="option">
-DDISABLE_PSI_THREAD=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328132864">
</a>
<a class="indexterm" name="idm46045328131408">
</a>
<p>
Exclude the Performance Schema thread instrumentation. The
default is
<code class="literal">
OFF
</code>
(include).
</p>
<p>
Only disable threads when building without any
instrumentation, because other instrumentations have a
dependency on threads.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_transaction">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_transaction">
<code class="option">
-DDISABLE_PSI_TRANSACTION=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328125712">
</a>
<a class="indexterm" name="idm46045328124208">
</a>
<p>
Exclude the Performance Schema transaction instrumentation.
The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_data_lock">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_data_lock">
<code class="option">
-DDISABLE_PSI_DATA_LOCK=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328119024">
</a>
<a class="indexterm" name="idm46045328117520">
</a>
<p>
Exclude the performance schema data lock instrumentation.
The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_disable_psi_error">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_disable_psi_error">
<code class="option">
-DDISABLE_PSI_ERROR=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328112304">
</a>
<a class="indexterm" name="idm46045328110848">
</a>
<p>
Exclude the performance schema server error instrumentation.
The default is
<code class="literal">
OFF
</code>
(include).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_enable_experimental_sysvars">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_enable_experimental_sysvars">
<code class="option">
-DENABLE_EXPERIMENTAL_SYSVARS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328105536">
</a>
<a class="indexterm" name="idm46045328104032">
</a>
<a class="indexterm" name="idm46045328102528">
</a>
<p>
Whether to enable experimental
<code class="literal">
InnoDB
</code>
system variables. Experimental system variables are intended
for those engaged in MySQL development, should only be used
in a development or test environment, and may be removed
without notice in a future MySQL release. For information
about experimental system variables, refer to
<code class="filename">
/storage/innobase/handler/ha_innodb.cc
</code>
in the MySQL source tree. Experimental system variables can
be identified by searching for
<span class="quote">
“
<span class="quote">
PLUGIN_VAR_EXPERIMENTAL
</span>
”
</span>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_without_server">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_without_server">
<code class="option">
-DWITHOUT_SERVER=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328096176">
</a>
<a class="indexterm" name="idm46045328094688">
</a>
<p>
Whether to build without MySQL Server. The default is OFF,
which does build the server.
</p>
<p>
This is considered an experimental option; it is preferred
to build with the server.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_enable_gcov">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_enable_gcov">
<code class="option">
-DENABLE_GCOV=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328089664">
</a>
<a class="indexterm" name="idm46045328088176">
</a>
<p>
Whether to include
<span class="command">
<strong>
gcov
</strong>
</span>
support (Linux
only).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_enable_gprof">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_enable_gprof">
<code class="option">
-DENABLE_GPROF=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328083088">
</a>
<a class="indexterm" name="idm46045328081600">
</a>
<p>
Whether to enable
<span class="command">
<strong>
gprof
</strong>
</span>
(optimized Linux
builds only).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_enabled_local_infile">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_enabled_local_infile">
<code class="option">
-DENABLED_LOCAL_INFILE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328076512">
</a>
<a class="indexterm" name="idm46045328075056">
</a>
<p>
This option controls the compiled-in default
<code class="literal">
LOCAL
</code>
capability for the MySQL client
library. Clients that make no explicit arrangements
therefore have
<code class="literal">
LOCAL
</code>
capability disabled
or enabled according to the
<a class="link" href="source-configuration-options.html#option_cmake_enabled_local_infile">
<code class="option">
ENABLED_LOCAL_INFILE
</code>
</a>
setting
specified at MySQL build time.
</p>
<p>
By default, the client library in MySQL binary distributions
is compiled with
<a class="link" href="source-configuration-options.html#option_cmake_enabled_local_infile">
<code class="option">
ENABLED_LOCAL_INFILE
</code>
</a>
disabled.
If you compile MySQL from source, configure it with
<a class="link" href="source-configuration-options.html#option_cmake_enabled_local_infile">
<code class="option">
ENABLED_LOCAL_INFILE
</code>
</a>
disabled
or enabled based on whether clients that make no explicit
arrangements should have
<code class="literal">
LOCAL
</code>
capability
disabled or enabled, respectively.
</p>
<p>
<a class="link" href="source-configuration-options.html#option_cmake_enabled_local_infile">
<code class="option">
ENABLED_LOCAL_INFILE
</code>
</a>
controls
the default for client-side
<code class="literal">
LOCAL
</code>
capability. For the server, the
<a class="link" href="server-system-variables.html#sysvar_local_infile">
<code class="literal">
local_infile
</code>
</a>
system
variable controls server-side
<code class="literal">
LOCAL
</code>
capability. To explicitly cause the server to refuse or
permit
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
LOCAL
</code>
</a>
statements (regardless of how client
programs and libraries are configured at build time or
runtime), start
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with
<a class="link" href="server-system-variables.html#sysvar_local_infile">
<code class="option">
--local-infile
</code>
</a>
disabled or
enabled, respectively.
<a class="link" href="server-system-variables.html#sysvar_local_infile">
<code class="literal">
local_infile
</code>
</a>
can also be
set at runtime. 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_cmake_enabled_profiling">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_enabled_profiling">
<code class="option">
-DENABLED_PROFILING=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328054400">
</a>
<a class="indexterm" name="idm46045328052944">
</a>
<p>
Whether to enable query profiling code (for the
<a class="link" href="show-profile.html" title="15.7.7.32 SHOW PROFILE Statement">
<code class="literal">
SHOW PROFILE
</code>
</a>
and
<a class="link" href="show-profiles.html" title="15.7.7.33 SHOW PROFILES Statement">
<code class="literal">
SHOW PROFILES
</code>
</a>
statements).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_force_unsupported_compiler">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_force_unsupported_compiler">
<code class="option">
-DFORCE_UNSUPPORTED_COMPILER=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328045680">
</a>
<a class="indexterm" name="idm46045328044176">
</a>
<p>
By default,
<span class="command">
<strong>
CMake
</strong>
</span>
checks for minimum
versions of
<a class="link" href="source-installation-prerequisites.html" title="2.8.2 Source Installation Prerequisites">
supported
compilers
</a>
; to disable this check, use
<a class="link" href="source-configuration-options.html#option_cmake_force_unsupported_compiler">
<code class="option">
-DFORCE_UNSUPPORTED_COMPILER=ON
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_show_suppressed_compiler_warnings">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_show_suppressed_compiler_warnings">
<code class="option">
-DSHOW_SUPPRESSED_COMPILER_WARNINGS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328036928">
</a>
<a class="indexterm" name="idm46045328035472">
</a>
<p>
Show suppressed compiler warnings, and do so without failing
with
<code class="literal">
-Werror
</code>
. Defaults to
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_fprofile_generate">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_generate">
<code class="option">
-DFPROFILE_GENERATE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328029568">
</a>
<a class="indexterm" name="idm46045328028112">
</a>
<p>
Whether to generate profile guided optimization (PGO) data.
This option is available for experimenting with PGO with
GCC. See
<code class="filename">
cmake/fprofile.cmake
</code>
in the
MySQL source distribution for information about using
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_generate">
<code class="option">
FPROFILE_GENERATE
</code>
</a>
and
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_use">
<code class="option">
FPROFILE_USE
</code>
</a>
. These options
have been tested with GCC 8 and 9.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_fprofile_use">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_use">
<code class="option">
-DFPROFILE_USE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328020688">
</a>
<a class="indexterm" name="idm46045328019200">
</a>
<p>
Whether to use profile guided optimization (PGO) data. This
option is available for experimenting with PGO with GCC. See
the
<code class="filename">
cmake/fprofile.cmake
</code>
file in a
MySQL source distribution for information about using
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_generate">
<code class="option">
FPROFILE_GENERATE
</code>
</a>
and
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_use">
<code class="option">
FPROFILE_USE
</code>
</a>
. These options
have been tested with GCC 8 and 9.
</p>
<p>
Enabling
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_use">
<code class="option">
FPROFILE_USE
</code>
</a>
also
enables
<a class="link" href="source-configuration-options.html#option_cmake_with_lto">
<code class="option">
WITH_LTO
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_have_psi_memory_interface">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_have_psi_memory_interface">
<code class="option">
-DHAVE_PSI_MEMORY_INTERFACE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328009536">
</a>
<a class="indexterm" name="idm46045328008032">
</a>
<a class="indexterm" name="idm46045328006528">
</a>
<p>
Whether to enable the performance schema memory tracing
module for memory allocation functions
(
<code class="literal">
ut::aligned_
<em class="replaceable">
<code>
name
</code>
</em>
</code>
library functions) used in dynamic storage of over-aligned
types.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_ignore_aio_check">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_ignore_aio_check">
<code class="option">
-DIGNORE_AIO_CHECK=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045328001296">
</a>
<a class="indexterm" name="idm46045327999808">
</a>
<a class="indexterm" name="idm46045327998320">
</a>
<p>
If the
<a class="link" href="source-configuration-options.html#option_cmake_build_config">
<code class="option">
-DBUILD_CONFIG=mysql_release
</code>
</a>
option is given on Linux, the
<code class="literal">
libaio
</code>
library must be linked in by default. If you do not have
<code class="literal">
libaio
</code>
or do not want to install it, you
can suppress the check for it by specifying
<a class="link" href="source-configuration-options.html#option_cmake_ignore_aio_check">
<code class="option">
-DIGNORE_AIO_CHECK=1
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_max_indexes">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_max_indexes">
<code class="option">
-DMAX_INDEXES=
<em class="replaceable">
<code>
num
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327990752">
</a>
<a class="indexterm" name="idm46045327989264">
</a>
<p>
The maximum number of indexes per table. The default is 64.
The maximum is 255. Values smaller than 64 are ignored and
the default of 64 is used.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysql_maintainer_mode">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysql_maintainer_mode">
<code class="option">
-DMYSQL_MAINTAINER_MODE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327984800">
</a>
<a class="indexterm" name="idm46045327983296">
</a>
<p>
Whether to enable a MySQL maintainer-specific development
environment. If enabled, this option causes compiler
warnings to become errors.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_developer_entitlements">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_developer_entitlements">
<code class="option">
-DWITH_DEVELOPER_ENTITLEMENTS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327978576">
</a>
<a class="indexterm" name="idm46045327977072">
</a>
<p>
Whether to add the
<code class="literal">
get-task-allow
</code>
entitlement to all executables to generate a core dump in
the event of an unexpected server halt.
</p>
<p>
On macOS 11+, core dumps are limited to processes with the
<code class="literal">
com.apple.security.get-task-allow
</code>
entitlement, which this CMake option enables. The
entitlement allows other processes to attach and read/modify
the processes memory, and allows
<a class="link" href="server-options.html#option_mysqld_core-file">
<code class="option">
--core-file
</code>
</a>
to function as
expected.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mutex_type">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mutex_type">
<code class="option">
-DMUTEX_TYPE=
<em class="replaceable">
<code>
type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327969504">
</a>
<a class="indexterm" name="idm46045327968016">
</a>
<p>
The mutex type used by
<code class="literal">
InnoDB
</code>
. Options
include:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
event
</code>
: Use event mutexes. This is the
default value and the original
<code class="literal">
InnoDB
</code>
mutex implementation.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
sys
</code>
: Use POSIX mutexes on UNIX
systems. Use
<code class="literal">
CRITICAL_SECTION
</code>
objects
on Windows, if available.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
futex
</code>
: Use Linux futexes instead of
condition variables to schedule waiting threads.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysqlx_tcp_port">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysqlx_tcp_port">
<code class="option">
-DMYSQLX_TCP_PORT=
<em class="replaceable">
<code>
port_num
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327956224">
</a>
<a class="indexterm" name="idm46045327954736">
</a>
<a class="indexterm" name="idm46045327953248">
</a>
<a class="indexterm" name="idm46045327952176">
</a>
<a class="indexterm" name="idm46045327951104">
</a>
<p>
The port number on which X Plugin listens for TCP/IP
connections. The default is 33060.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port">
<code class="literal">
mysqlx_port
</code>
</a>
system
variable.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysqlx_unix_addr">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysqlx_unix_addr">
<code class="option">
-DMYSQLX_UNIX_ADDR=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327945152">
</a>
<a class="indexterm" name="idm46045327943664">
</a>
<p>
The Unix socket file path on which the server listens for
X Plugin socket connections. This must be an absolute path
name. The default is
<code class="filename">
/tmp/mysqlx.sock
</code>
.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port">
<code class="literal">
mysqlx_port
</code>
</a>
system
variable.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysql_project_name">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysql_project_name">
<code class="option">
-DMYSQL_PROJECT_NAME=
<em class="replaceable">
<code>
name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327936656">
</a>
<a class="indexterm" name="idm46045327935200">
</a>
<p>
For Windows or macOS, the project name to incorporate into
the project file name.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysql_tcp_port">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysql_tcp_port">
<code class="option">
-DMYSQL_TCP_PORT=
<em class="replaceable">
<code>
port_num
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327930720">
</a>
<a class="indexterm" name="idm46045327929232">
</a>
<a class="indexterm" name="idm46045327927744">
</a>
<a class="indexterm" name="idm46045327926672">
</a>
<a class="indexterm" name="idm46045327925600">
</a>
<p>
The port number on which the server listens for TCP/IP
connections. The default is 3306.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="server-options.html#option_mysqld_port">
<code class="option">
--port
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_mysql_unix_addr">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_mysql_unix_addr">
<code class="option">
-DMYSQL_UNIX_ADDR=
<em class="replaceable">
<code>
file_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327920144">
</a>
<a class="indexterm" name="idm46045327918656">
</a>
<p>
The Unix socket file path on which the server listens for
socket connections. This must be an absolute path name. The
default is
<code class="filename">
/tmp/mysql.sock
</code>
.
</p>
<p>
This value can be set at server startup with the
<a class="link" href="server-options.html#option_mysqld_socket">
<code class="option">
--socket
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_optimizer_trace">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_optimizer_trace">
<code class="option">
-DOPTIMIZER_TRACE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327911968">
</a>
<a class="indexterm" name="idm46045327910480">
</a>
<p>
Whether to support optimizer tracing. See
<a class="xref" href="optimizer-tracing.html" title="10.15 Tracing the Optimizer">
Section 10.15, “Tracing the Optimizer”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_reproducible_build">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_reproducible_build">
<code class="option">
-DREPRODUCIBLE_BUILD=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327905248">
</a>
<a class="indexterm" name="idm46045327903792">
</a>
<p>
For builds on Linux systems, this option controls whether to
take extra care to create a build result independent of
build location and time.
</p>
<p>
This option defaults to
<code class="literal">
ON
</code>
for
<code class="literal">
RelWithDebInfo
</code>
builds.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ld">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ld">
<code class="option">
-DWITH_LD=
<em class="replaceable">
<code>
string
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327897504">
</a>
<a class="indexterm" name="idm46045327896016">
</a>
<p>
<span class="command">
<strong>
CMake
</strong>
</span>
uses the standard linker by
default. Optionally pass in
<code class="literal">
lld
</code>
or
<code class="literal">
mold
</code>
to specify an alternative linker.
<span class="command">
<strong>
mold
</strong>
</span>
must be version 2 or newer.
</p>
<p>
This option can be used on Linux-based systems other than
Enterprise Linux, which always uses the
<span class="command">
<strong>
ld
</strong>
</span>
linker.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
Previously, the option
<code class="option">
USE_LD_LLD
</code>
could
be used to enable (the default) or disable explicitly the
LLVM
<span class="command">
<strong>
lld
</strong>
</span>
linker for Clang. In MySQL
8.3,
<code class="option">
USE_LD_LLD
</code>
has been removed.
</p>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_win_debug_no_inline">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_win_debug_no_inline">
<code class="option">
-DWIN_DEBUG_NO_INLINE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327884880">
</a>
<a class="indexterm" name="idm46045327883424">
</a>
<p>
Whether to disable function inlining on Windows. The default
is
<code class="literal">
OFF
</code>
(inlining enabled).
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ant">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ant">
<code class="option">
-DWITH_ANT=
<em class="replaceable">
<code>
path_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327878304">
</a>
<a class="indexterm" name="idm46045327876816">
</a>
<p>
Set the path to Ant, required when building GCS Java
wrapper. Set
<a class="link" href="source-configuration-options.html#option_cmake_with_ant">
<code class="option">
WITH_ANT
</code>
</a>
to the
path of a directory where the Ant tarball or unpacked
archive is saved. When
<a class="link" href="source-configuration-options.html#option_cmake_with_ant">
<code class="option">
WITH_ANT
</code>
</a>
is not set, or is set
with the special value
<code class="literal">
system
</code>
, the build
process assumes a binary
<code class="literal">
ant
</code>
exists in
<code class="literal">
$PATH
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_asan">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_asan">
<code class="option">
-DWITH_ASAN=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327868240">
</a>
<a class="indexterm" name="idm46045327866752">
</a>
<p>
Whether to enable the AddressSanitizer, for compilers that
support it. The default is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_asan_scope">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_asan_scope">
<code class="option">
-DWITH_ASAN_SCOPE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327861600">
</a>
<a class="indexterm" name="idm46045327860112">
</a>
<p>
Whether to enable the AddressSanitizer
<code class="literal">
-fsanitize-address-use-after-scope
</code>
Clang
flag for use-after-scope detection. The default is off. To
use this option,
<a class="link" href="source-configuration-options.html#option_cmake_with_asan">
<code class="option">
-DWITH_ASAN
</code>
</a>
must also be enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_authentication_client_plugins">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_authentication_client_plugins">
<code class="option">
-DWITH_AUTHENTICATION_CLIENT_PLUGINS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327853760">
</a>
<a class="indexterm" name="idm46045327852304">
</a>
<p>
This option is enabled automatically if any corresponding
server authentication plugins are built. Its value thus
depends on other
<span class="command">
<strong>
CMake
</strong>
</span>
options and it
should not be set explicitly.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_authentication_ldap">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_authentication_ldap">
<code class="option">
-DWITH_AUTHENTICATION_LDAP=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327846944">
</a>
<a class="indexterm" name="idm46045327845440">
</a>
<a class="indexterm" name="idm46045327843936">
</a>
<p>
Whether to report an error if the LDAP authentication
plugins cannot be built:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
If this option is disabled (the default), the LDAP
plugins are built if the required header files and
libraries are found. If they are not,
<span class="command">
<strong>
CMake
</strong>
</span>
displays a note about it.
</p>
</li>
<li class="listitem">
<p>
If this option is enabled, a failure to find the
required header file and libraries causes CMake to
produce an error, preventing the server from being
built.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_authentication_pam">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_authentication_pam">
<code class="option">
-DWITH_AUTHENTICATION_PAM=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327836272">
</a>
<a class="indexterm" name="idm46045327834768">
</a>
<p>
Whether to build the PAM authentication plugin, for source
trees that include this plugin. (See
<a class="xref" href="pam-pluggable-authentication.html" title="8.4.1.5 PAM Pluggable Authentication">
Section 8.4.1.5, “PAM Pluggable Authentication”
</a>
.) If this
option is specified and the plugin cannot be compiled, the
build fails.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_aws_sdk">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_aws_sdk">
<code class="option">
-DWITH_AWS_SDK=
<em class="replaceable">
<code>
path_name
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327829296">
</a>
<a class="indexterm" name="idm46045327827808">
</a>
<p>
The location of the Amazon Web Services software development
kit.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_client_protocol_tracing">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_client_protocol_tracing">
<code class="option">
-DWITH_CLIENT_PROTOCOL_TRACING=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327823312">
</a>
<a class="indexterm" name="idm46045327821808">
</a>
<p>
Whether to build the client-side protocol tracing framework
into the client library. By default, this option is enabled.
</p>
<p>
For information about writing protocol trace client plugins,
see
<a class="ulink" href="/doc/extending-mysql/8.4/en/writing-protocol-trace-plugins.html" target="_top">
Writing Protocol Trace Plugins
</a>
.
</p>
<p>
See also the
<a class="link" href="source-configuration-options.html#option_cmake_with_test_trace_plugin">
<code class="option">
WITH_TEST_TRACE_PLUGIN
</code>
</a>
option.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_curl">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_curl">
<code class="option">
-DWITH_CURL=
<em class="replaceable">
<code>
curl_type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327814672">
</a>
<a class="indexterm" name="idm46045327813184">
</a>
<p>
The location of the
<code class="literal">
curl
</code>
library.
<em class="replaceable">
<code>
curl_type
</code>
</em>
can be
<code class="literal">
system
</code>
(use the system
<code class="literal">
curl
</code>
library), a path name to the
<code class="literal">
curl
</code>
library,
<code class="literal">
no
</code>
|
<code class="literal">
off
</code>
|
<code class="literal">
none
</code>
to disable curl support, or
<code class="literal">
bundled
</code>
to
use the bundled curl distribution in
<code class="filename">
extra/curl/
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_debug">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
-DWITH_DEBUG=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327801984">
</a>
<a class="indexterm" name="idm46045327800496">
</a>
<p>
Whether to include debugging support.
</p>
<p>
Configuring MySQL with debugging support enables you to use
the
<a class="link" href="server-options.html#option_mysqld_debug">
<code class="option">
--debug="d,parser_debug"
</code>
</a>
option when you start the server. This causes the Bison
parser that is used to process SQL statements to dump a
parser trace to the server's standard error output.
Typically, this output is written to the error log.
</p>
<p>
Sync debug checking for the
<code class="literal">
InnoDB
</code>
storage engine is defined under
<code class="literal">
UNIV_DEBUG
</code>
and is available when
debugging support is compiled in using the
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
WITH_DEBUG
</code>
</a>
option. When
debugging support is compiled in, the
<a class="link" href="innodb-parameters.html#sysvar_innodb_sync_debug">
<code class="literal">
innodb_sync_debug
</code>
</a>
configuration option can be used to enable or disable
<code class="literal">
InnoDB
</code>
sync debug checking.
</p>
<p>
Enabling
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
WITH_DEBUG
</code>
</a>
also
enables Debug Sync. This facility is used for testing and
debugging. When compiled in, Debug Sync is disabled by
default at runtime. To enable it, start
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with the
<a class="link" href="server-options.html#option_mysqld_debug-sync-timeout">
<code class="option">
--debug-sync-timeout=
<em class="replaceable">
<code>
N
</code>
</em>
</code>
</a>
option, where
<em class="replaceable">
<code>
N
</code>
</em>
is a timeout
value greater than 0. (The default value is 0, which
disables Debug Sync.)
<em class="replaceable">
<code>
N
</code>
</em>
becomes
the default timeout for individual synchronization points.
</p>
<p>
Sync debug checking for the
<code class="literal">
InnoDB
</code>
storage engine is available when debugging support is
compiled in using the
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
WITH_DEBUG
</code>
</a>
option.
</p>
<p>
For a description of the Debug Sync facility and how to use
synchronization points, see
<a class="ulink" href="/doc/internals/en/test-synchronization.html" target="_top">
MySQL
Internals: Test Synchronization
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_editline">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_editline">
<code class="option">
-DWITH_EDITLINE=
<em class="replaceable">
<code>
value
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327780272">
</a>
<a class="indexterm" name="idm46045327778784">
</a>
<p>
Which
<code class="literal">
libedit
</code>
/
<code class="literal">
editline
</code>
library to use. The permitted values are
<code class="literal">
bundled
</code>
(the default) and
<code class="literal">
system
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_icu">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_icu">
<code class="option">
-DWITH_ICU={
<em class="replaceable">
<code>
icu_type
</code>
</em>
|
<em class="replaceable">
<code>
path_name
</code>
</em>
}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327771056">
</a>
<a class="indexterm" name="idm46045327769568">
</a>
<p>
MySQL uses International Components for Unicode (ICU) to
support regular expression operations. The
<code class="option">
WITH_ICU
</code>
option indicates the type of ICU
support to include or the path name to the ICU installation
to use.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<em class="replaceable">
<code>
icu_type
</code>
</em>
can be one of the
following values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
<code class="literal">
bundled
</code>
: Use the ICU library
bundled with the distribution. This is the default,
and is the only supported option for Windows.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the system ICU
library.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
path_name
</code>
</em>
is the path name to
the ICU installation to use. This can be preferable to
using the
<em class="replaceable">
<code>
icu_type
</code>
</em>
value of
<code class="literal">
system
</code>
because it can prevent CMake
from detecting and using an older or incorrect ICU
version installed on the system. (Another permitted way
to do the same thing is to set
<code class="option">
WITH_ICU
</code>
to
<code class="literal">
system
</code>
and set the
<code class="option">
CMAKE_PREFIX_PATH
</code>
option to
<em class="replaceable">
<code>
path_name
</code>
</em>
.)
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_innodb_extra_debug">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_innodb_extra_debug">
<code class="option">
-DWITH_INNODB_EXTRA_DEBUG=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327754448">
</a>
<a class="indexterm" name="idm46045327752944">
</a>
<p>
Whether to include extra InnoDB debugging support.
</p>
<p>
Enabling
<code class="literal">
WITH_INNODB_EXTRA_DEBUG
</code>
turns on
extra InnoDB debug checks. This option can only be enabled
when
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
WITH_DEBUG
</code>
</a>
is enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_jemalloc">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_jemalloc">
<code class="option">
-DWITH_JEMALLOC=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327746256">
</a>
<a class="indexterm" name="idm46045327744768">
</a>
<p>
Whether to link with
<code class="option">
-ljemalloc
</code>
. If
enabled, built-in
<code class="literal">
malloc()
</code>
,
<code class="literal">
calloc()
</code>
,
<code class="literal">
realloc()
</code>
,
and
<code class="literal">
free()
</code>
routines are disabled. The
default is
<code class="literal">
OFF
</code>
.
</p>
<p>
<a class="link" href="source-configuration-options.html#option_cmake_with_jemalloc">
<code class="option">
WITH_JEMALLOC
</code>
</a>
and
<a class="link" href="source-configuration-options.html#option_cmake_with_tcmalloc">
<code class="option">
WITH_TCMALLOC
</code>
</a>
are mutually
exclusive.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_win_jemalloc">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_win_jemalloc">
<code class="option">
-DWITH_WIN_JEMALLOC=
<em class="replaceable">
<code>
string
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327733936">
</a>
<a class="indexterm" name="idm46045327732480">
</a>
<p>
On Windows, pass in a path to a directory containing
<code class="filename">
jemalloc.dll
</code>
to enable jemalloc
functionality. The build system copies
<code class="filename">
jemalloc.dll
</code>
to the same directory as
<code class="filename">
mysqld.exe
</code>
and/or
<code class="filename">
mysqld-debug.exe
</code>
and utilizes it for
memory management operations. Standard memory functions are
used if
<code class="filename">
jemalloc.dll
</code>
is not found or
does not export the required functions. An INFORMATION level
log message records whether or not jemalloc is found and
used.
</p>
<p>
This option is enabled for official MySQL binaries for
Windows.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_libevent">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_libevent">
<code class="option">
-DWITH_LIBEVENT=
<em class="replaceable">
<code>
string
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327722720">
</a>
<a class="indexterm" name="idm46045327721232">
</a>
<p>
Which
<code class="literal">
libevent
</code>
library to use. Permitted
values are
<code class="literal">
bundled
</code>
(default) and
<code class="literal">
system
</code>
. If
<code class="literal">
system
</code>
is
specified and no system
<code class="literal">
libevent
</code>
library
can be found, an error occurs regardless, and the bundled
<code class="literal">
libevent
</code>
is not used.
</p>
<p>
The
<code class="literal">
libevent
</code>
library is required by
X Plugin and MySQL Router.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_libwrap">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_libwrap">
<code class="option">
-DWITH_LIBWRAP=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327711216">
</a>
<a class="indexterm" name="idm46045327709728">
</a>
<p>
Whether to include
<code class="literal">
libwrap
</code>
(TCP wrappers)
support.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_lock_order">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_lock_order">
<code class="option">
-DWITH_LOCK_ORDER=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327704640">
</a>
<a class="indexterm" name="idm46045327703152">
</a>
<p>
Whether to enable LOCK_ORDER tooling. By default, this
option is disabled and server builds contain no tooling. If
tooling is enabled, the LOCK_ORDER tool is available and can
be used as described in
<a class="xref" href="lock-order-tool.html" title="7.9.3 The LOCK_ORDER Tool">
Section 7.9.3, “The LOCK_ORDER Tool”
</a>
.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
With the
<a class="link" href="source-configuration-options.html#option_cmake_with_lock_order">
<code class="option">
WITH_LOCK_ORDER
</code>
</a>
option enabled, MySQL builds require the
<span class="command">
<strong>
flex
</strong>
</span>
program.
</p>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_lsan">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_lsan">
<code class="option">
-DWITH_LSAN=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327695216">
</a>
<a class="indexterm" name="idm46045327693728">
</a>
<p>
Whether to run LeakSanitizer, without AddressSanitizer. The
default is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_lto">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_lto">
<code class="option">
-DWITH_LTO=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327688640">
</a>
<a class="indexterm" name="idm46045327687152">
</a>
<p>
Whether to enable the link-time optimizer, if the compiler
supports it. The default is
<code class="literal">
OFF
</code>
unless
<a class="link" href="source-configuration-options.html#option_cmake_fprofile_use">
<code class="option">
FPROFILE_USE
</code>
</a>
is enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_lz4">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_lz4">
<code class="option">
-DWITH_LZ4=
<em class="replaceable">
<code>
lz4_type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327681056">
</a>
<a class="indexterm" name="idm46045327679568">
</a>
<p>
The
<a class="link" href="source-configuration-options.html#option_cmake_with_lz4">
<code class="option">
WITH_LZ4
</code>
</a>
option indicates
the source of
<code class="literal">
zlib
</code>
support:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
bundled
</code>
: Use the
<code class="literal">
lz4
</code>
library bundled with the
distribution. This is the default.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the system
<code class="literal">
lz4
</code>
library.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_mecab">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_mecab">
<code class="option">
-DWITH_MECAB={disabled|system|
<em class="replaceable">
<code>
path_name
</code>
</em>
}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327668528">
</a>
<a class="indexterm" name="idm46045327667040">
</a>
<p>
Use this option to compile the MeCab parser. If you have
installed MeCab to its default installation directory, set
<code class="option">
-DWITH_MECAB=system
</code>
. The
<code class="literal">
system
</code>
option applies to MeCab
installations performed from source or from binaries using a
native package management utility. If you installed MeCab to
a custom installation directory, specify the path to the
MeCab installation, for example,
<code class="option">
-DWITH_MECAB=/opt/mecab
</code>
. If the
<code class="literal">
system
</code>
option does not work, specifying
the MeCab installation path should work in all cases.
</p>
<p>
For related information, see
<a class="xref" href="fulltext-search-mecab.html" title="14.9.9 MeCab Full-Text Parser Plugin">
Section 14.9.9, “MeCab Full-Text Parser Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_msan">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_msan">
<code class="option">
-DWITH_MSAN=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327658560">
</a>
<a class="indexterm" name="idm46045327657072">
</a>
<p>
Whether to enable MemorySanitizer, for compilers that
support it. The default is off.
</p>
<p>
For this option to have an effect if enabled, all libraries
linked to MySQL must also have been compiled with the option
enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_mscrt_debug">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_mscrt_debug">
<code class="option">
-DWITH_MSCRT_DEBUG=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327651952">
</a>
<a class="indexterm" name="idm46045327650464">
</a>
<p>
Whether to enable Visual Studio CRT memory leak tracing. The
default is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_msvc_cppcheck">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_msvc_cppcheck">
<code class="option">
-DMSVC_CPPCHECK=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327645376">
</a>
<a class="indexterm" name="idm46045327643888">
</a>
<p>
Whether to enable MSVC code analysis. The default is
<code class="literal">
ON
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_mysqlx">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_mysqlx">
<code class="option">
-DWITH_MYSQLX=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327638752">
</a>
<a class="indexterm" name="idm46045327637264">
</a>
<p>
Whether to build with support for X Plugin. The default is
<code class="literal">
ON
</code>
. See
<a class="xref" href="document-store.html" title="Chapter 22 Using MySQL as a Document Store">
Chapter 22,
<i>
Using MySQL as a Document Store
</i>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_numa">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_numa">
<code class="option">
-DWITH_NUMA=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327631392">
</a>
<a class="indexterm" name="idm46045327629904">
</a>
<p>
Explicitly set the NUMA memory allocation policy.
<span class="command">
<strong>
CMake
</strong>
</span>
sets the default
<a class="link" href="source-configuration-options.html#option_cmake_with_numa">
<code class="option">
WITH_NUMA
</code>
</a>
value based on
whether the current platform has
<code class="literal">
NUMA
</code>
support. For platforms without NUMA support,
<span class="command">
<strong>
CMake
</strong>
</span>
behaves as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
With no NUMA option (the normal case),
<span class="command">
<strong>
CMake
</strong>
</span>
continues normally, producing
only this warning:
<span class="errortext">
NUMA library missing or
required version not available
</span>
.
</p>
</li>
<li class="listitem">
<p>
With
<a class="link" href="source-configuration-options.html#option_cmake_with_numa">
<code class="option">
-DWITH_NUMA=ON
</code>
</a>
,
<span class="command">
<strong>
CMake
</strong>
</span>
aborts with this error:
<span class="errortext">
NUMA library missing or required version not
available
</span>
.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_package_flags">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_package_flags">
<code class="option">
-DWITH_PACKAGE_FLAGS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327616704">
</a>
<a class="indexterm" name="idm46045327615248">
</a>
<p>
For flags typically used for RPM and Debian packages,
whether to add them to standalone builds on those platforms.
The default is
<code class="literal">
ON
</code>
for nondebug builds.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_protobuf">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_protobuf">
<code class="option">
-DWITH_PROTOBUF=
<em class="replaceable">
<code>
protobuf_type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327609952">
</a>
<a class="indexterm" name="idm46045327608464">
</a>
<p>
Which Protocol Buffers package to use.
<em class="replaceable">
<code>
protobuf_type
</code>
</em>
can be one of the
following values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
bundled
</code>
: Use the package bundled with
the distribution. This is the default. Optionally use
<a class="link" href="source-configuration-options.html#option_cmake_install_priv_libdir">
<code class="option">
INSTALL_PRIV_LIBDIR
</code>
</a>
to
modify the dynamic Protobuf library directory.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the package installed on
the system.
</p>
</li>
</ul>
</div>
<p>
Other values are ignored, with a fallback to
<code class="literal">
bundled
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_rapid">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_rapid">
<code class="option">
-DWITH_RAPID=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327597888">
</a>
<a class="indexterm" name="idm46045327596400">
</a>
<p>
Whether to build the rapid development cycle plugins. When
enabled, a
<code class="filename">
rapid
</code>
directory is created
in the build tree containing these plugins. When disabled,
no
<code class="filename">
rapid
</code>
directory is created in the
build tree. The default is
<code class="literal">
ON
</code>
, unless the
<code class="filename">
rapid
</code>
directory is removed from the
source tree, in which case the default becomes
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_rapidjson">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_rapidjson">
<code class="option">
-DWITH_RAPIDJSON=
<em class="replaceable">
<code>
rapidjson_type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327588112">
</a>
<a class="indexterm" name="idm46045327586624">
</a>
<p>
The type of RapidJSON library support to include.
<em class="replaceable">
<code>
rapidjson_type
</code>
</em>
can be one of the
following values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
bundled
</code>
: Use the RapidJSON library
bundled with the distribution. This is the default.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the system RapidJSON
library. Version 1.1.0 or later is required.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_router">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_router">
<code class="option">
-DWITH_ROUTER=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327578208">
</a>
<a class="indexterm" name="idm46045327576720">
</a>
<p>
Whether to build MySQL Router. The default is
<code class="literal">
ON
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_sasl">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_sasl">
<code class="option">
-DWITH_SASL=
<em class="replaceable">
<code>
value
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327571776">
</a>
<a class="indexterm" name="idm46045327570288">
</a>
<p>
Internal use only. Not supported on Windows.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ssl">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ssl">
<code class="option">
-DWITH_SSL={
<em class="replaceable">
<code>
ssl_type
</code>
</em>
</code>
</a>
|
<em class="replaceable">
<code>
path_name
</code>
</em>
}
</p>
<a class="indexterm" name="idm46045327565472">
</a>
<a class="indexterm" name="idm46045327563984">
</a>
<p>
For support of encrypted connections, entropy for random
number generation, and other encryption-related operations,
MySQL must be built using an SSL library. This option
specifies which SSL library to use.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<em class="replaceable">
<code>
ssl_type
</code>
</em>
can be one of the
following values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the system OpenSSL
library. This is the default.
</p>
<p>
On macOS and Windows, using
<code class="literal">
system
</code>
configures MySQL to build
as if CMake was invoked with
<em class="replaceable">
<code>
path_name
</code>
</em>
points to a
manually installed OpenSSL library. This is because
they do not have system SSL libraries. On macOS,
<span class="emphasis">
<em>
brew install openssl
</em>
</span>
installs
to
<code class="filename">
/usr/local/opt/openssl
</code>
so
that
<code class="literal">
system
</code>
can find it. On
Windows, it checks
<code class="filename">
%ProgramFiles%/OpenSSL
</code>
,
<code class="filename">
%ProgramFiles%/OpenSSL-Win32
</code>
,
<code class="filename">
%ProgramFiles%/OpenSSL-Win64
</code>
,
<code class="filename">
C:/OpenSSL
</code>
,
<code class="filename">
C:/OpenSSL-Win32
</code>
, and
<code class="filename">
C:/OpenSSL-Win64
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
yes
</code>
: This is a synonym for
<code class="literal">
system
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
openssl
<em class="replaceable">
<code>
version
</code>
</em>
</code>
:
Use an alternate OpenSSL system package such as
<code class="literal">
openssl11
</code>
on EL7, or
<code class="literal">
openssl3
</code>
(or
<code class="literal">
openssl3-fips
</code>
) on EL8.
</p>
<p>
Authentication plugins, such as LDAP and Kerberos,
are disabled as they do not support these
alternative versions of OpenSSL.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
path_name
</code>
</em>
is the path name to
the OpenSSL installation to use. This can be preferable
to using the
<em class="replaceable">
<code>
ssl_type
</code>
</em>
value
<code class="literal">
system
</code>
because it can prevent CMake
from detecting and using an older or incorrect OpenSSL
version installed on the system. (Another permitted way
to do the same thing is to set
<code class="option">
WITH_SSL
</code>
to
<code class="literal">
system
</code>
and set the
<code class="option">
CMAKE_PREFIX_PATH
</code>
option to
<em class="replaceable">
<code>
path_name
</code>
</em>
.)
</p>
</li>
</ul>
</div>
<p>
For additional information about configuring the SSL
library, see
<a class="xref" href="source-ssl-library-configuration.html" title="2.8.6 Configuring SSL Library Support">
Section 2.8.6, “Configuring SSL Library Support”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_show_parse_tree">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_show_parse_tree">
<code class="option">
-DWITH_SHOW_PARSE_TREE=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327534544">
</a>
<a class="indexterm" name="idm46045327533088">
</a>
<a class="indexterm" name="idm46045327531584">
</a>
<p>
Enables support for
<a class="link" href="show-parse-tree.html" title="15.7.7.26 SHOW PARSE_TREE Statement">
<code class="literal">
SHOW
PARSE_TREE
</code>
</a>
in the server, used in development and
debugging only. Not used for release builds or supported in
production.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_systemd">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd">
<code class="option">
-DWITH_SYSTEMD=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327525808">
</a>
<a class="indexterm" name="idm46045327524320">
</a>
<a class="indexterm" name="idm46045327522832">
</a>
<p>
Whether to enable installation of
<span class="command">
<strong>
systemd
</strong>
</span>
support files. By default, this option is disabled. When
enabled,
<span class="command">
<strong>
systemd
</strong>
</span>
support files are
installed, and scripts such as
<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>
and the System V
initialization script are not installed. On platforms where
<span class="command">
<strong>
systemd
</strong>
</span>
is not available, enabling
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd">
<code class="option">
WITH_SYSTEMD
</code>
</a>
results in an
error from
<span class="command">
<strong>
CMake
</strong>
</span>
.
</p>
<p>
When the server was built using this option, MySQL includes
all
<span class="command">
<strong>
systemd
</strong>
</span>
messages in the server's
error log (see
<a class="xref" href="error-log.html" title="7.4.2 The Error Log">
Section 7.4.2, “The Error Log”
</a>
).
</p>
<p>
For more information about using
<span class="command">
<strong>
systemd
</strong>
</span>
,
see
<a class="xref" href="using-systemd.html" title="2.5.9 Managing MySQL Server with systemd">
Section 2.5.9, “Managing MySQL Server with systemd”
</a>
. That section also
includes information about specifying options otherwise
specified in
<code class="literal">
[mysqld_safe]
</code>
option groups.
Because
<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>
is not installed when
<span class="command">
<strong>
systemd
</strong>
</span>
is used, such options must be
specified another way.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_system_libs">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_system_libs">
<code class="option">
-DWITH_SYSTEM_LIBS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327506464">
</a>
<a class="indexterm" name="idm46045327504976">
</a>
<p>
This option serves as an
<span class="quote">
“
<span class="quote">
umbrella
</span>
”
</span>
option to
set the
<code class="literal">
system
</code>
value of any of the
following
<span class="command">
<strong>
CMake
</strong>
</span>
options that are not set
explicitly:
<a class="link" href="source-configuration-options.html#option_cmake_with_curl">
<code class="option">
WITH_CURL
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_editline">
<code class="option">
WITH_EDITLINE
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_icu">
<code class="option">
WITH_ICU
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_libevent">
<code class="option">
WITH_LIBEVENT
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_lz4">
<code class="option">
WITH_LZ4
</code>
</a>
,
<a class="ulink" href="/doc/refman/8.0/en/source-configuration-options.html#option_cmake_with_lzma" target="_top">
<code class="option">
WITH_LZMA
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_protobuf">
<code class="option">
WITH_PROTOBUF
</code>
</a>
,
<a class="ulink" href="/doc/refman/8.0/en/source-configuration-options.html#option_cmake_with_re2" target="_top">
<code class="option">
WITH_RE2
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_ssl">
<code class="option">
WITH_SSL
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_zlib">
<code class="option">
WITH_ZLIB
</code>
</a>
,
<a class="link" href="source-configuration-options.html#option_cmake_with_zstd">
<code class="option">
WITH_ZSTD
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_systemd_debug">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_systemd_debug">
<code class="option">
-DWITH_SYSTEMD_DEBUG=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327488016">
</a>
<a class="indexterm" name="idm46045327486560">
</a>
<p>
Whether to produce additional
<span class="command">
<strong>
systemd
</strong>
</span>
debugging information, for platforms on which
<span class="command">
<strong>
systemd
</strong>
</span>
is used to run MySQL. The default
is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_tcmalloc">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_tcmalloc">
<code class="option">
-DWITH_TCMALLOC=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327479872">
</a>
<a class="indexterm" name="idm46045327478384">
</a>
<p>
Whether to link with
<code class="option">
-ltcmalloc
</code>
. If
enabled, built-in
<code class="literal">
malloc()
</code>
,
<code class="literal">
calloc()
</code>
,
<code class="literal">
realloc()
</code>
,
and
<code class="literal">
free()
</code>
routines are disabled. The
default is
<code class="literal">
OFF
</code>
.
</p>
<p>
Beginning with MySQL 8.4.1, a
<code class="literal">
tcmalloc
</code>
library is included in the source; you can cause the build
to use the bundled version by setting this option to
<code class="literal">
BUNDLED
</code>
.
<code class="literal">
BUNDLED
</code>
is
supported on Linux systems only.
</p>
<p>
<a class="link" href="source-configuration-options.html#option_cmake_with_tcmalloc">
<code class="option">
WITH_TCMALLOC
</code>
</a>
and
<a class="link" href="source-configuration-options.html#option_cmake_with_jemalloc">
<code class="option">
WITH_JEMALLOC
</code>
</a>
are mutually
exclusive.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_test_trace_plugin">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_test_trace_plugin">
<code class="option">
-DWITH_TEST_TRACE_PLUGIN=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327464832">
</a>
<a class="indexterm" name="idm46045327463328">
</a>
<p>
Whether to build the test protocol trace client plugin (see
<a class="ulink" href="/doc/extending-mysql/8.4/en/test-protocol-trace-plugin.html" target="_top">
Using the Test Protocol Trace Plugin
</a>
). By default,
this option is disabled. Enabling this option has no effect
unless the
<a class="link" href="source-configuration-options.html#option_cmake_with_client_protocol_tracing">
<code class="option">
WITH_CLIENT_PROTOCOL_TRACING
</code>
</a>
option is enabled. If MySQL is configured with both options
enabled, the
<code class="literal">
libmysqlclient
</code>
client
library is built with the test protocol trace plugin built
in, and all the standard MySQL clients load the plugin.
However, even when the test plugin is enabled, it has no
effect by default. Control over the plugin is afforded using
environment variables; see
<a class="ulink" href="/doc/extending-mysql/8.4/en/test-protocol-trace-plugin.html" target="_top">
Using the Test Protocol Trace Plugin
</a>
.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
Do
<span class="emphasis">
<em>
not
</em>
</span>
enable the
<a class="link" href="source-configuration-options.html#option_cmake_with_test_trace_plugin">
<code class="option">
WITH_TEST_TRACE_PLUGIN
</code>
</a>
option if you want to use your own protocol trace plugins
because only one such plugin can be loaded at a time and
an error occurs for attempts to load a second one. If you
have already built MySQL with the test protocol trace
plugin enabled to see how it works, you must rebuild MySQL
without it before you can use your own plugins.
</p>
</div>
<p>
For information about writing trace plugins, see
<a class="ulink" href="/doc/extending-mysql/8.4/en/writing-protocol-trace-plugins.html" target="_top">
Writing Protocol Trace Plugins
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_tsan">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_tsan">
<code class="option">
-DWITH_TSAN=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327451136">
</a>
<a class="indexterm" name="idm46045327449648">
</a>
<p>
Whether to enable the ThreadSanitizer, for compilers that
support it. The default is off.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ubsan">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ubsan">
<code class="option">
-DWITH_UBSAN=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327445216">
</a>
<a class="indexterm" name="idm46045327443728">
</a>
<p>
Whether to enable the Undefined Behavior Sanitizer, for
compilers that support it. The default is off.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_unit_tests">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_unit_tests">
<code class="option">
-DWITH_UNIT_TESTS={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327439552">
</a>
<a class="indexterm" name="idm46045327438064">
</a>
<p>
If enabled, compile MySQL with unit tests. The default is
<code class="literal">
ON
</code>
unless the server is not being
compiled.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_unixodbc">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_unixodbc">
<code class="option">
-DWITH_UNIXODBC=
<em class="replaceable">
<code>
1
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327432864">
</a>
<a class="indexterm" name="idm46045327431376">
</a>
<p>
Enables unixODBC support, for Connector/ODBC.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_valgrind">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_valgrind">
<code class="option">
-DWITH_VALGRIND=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327427008">
</a>
<a class="indexterm" name="idm46045327425520">
</a>
<p>
Whether to compile in the Valgrind header files, which
exposes the Valgrind API to MySQL code. The default is
<code class="literal">
OFF
</code>
.
</p>
<p>
To generate a Valgrind-aware debug build,
<a class="link" href="source-configuration-options.html#option_cmake_with_valgrind">
<code class="option">
-DWITH_VALGRIND=1
</code>
</a>
normally is
combined with
<a class="link" href="source-configuration-options.html#option_cmake_with_debug">
<code class="option">
-DWITH_DEBUG=1
</code>
</a>
.
See
<a class="ulink" href="/doc/internals/en/debug-configurations.html" target="_top">
Building
Debug Configurations
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_zlib">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_zlib">
<code class="option">
-DWITH_ZLIB=
<em class="replaceable">
<code>
zlib_type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327417184">
</a>
<a class="indexterm" name="idm46045327415696">
</a>
<p>
Some features require that the server be built with
compression library support, such as the
<a class="link" href="encryption-functions.html#function_compress">
<code class="literal">
COMPRESS()
</code>
</a>
and
<a class="link" href="encryption-functions.html#function_uncompress">
<code class="literal">
UNCOMPRESS()
</code>
</a>
functions, and
compression of the client/server protocol. The
<a class="link" href="source-configuration-options.html#option_cmake_with_zlib">
<code class="option">
WITH_ZLIB
</code>
</a>
option indicates the
source of
<code class="literal">
zlib
</code>
support:
</p>
<p>
The minimum supported version of
<code class="literal">
zlib
</code>
is
1.2.13.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
bundled
</code>
: Use the
<code class="literal">
zlib
</code>
library bundled with the
distribution. This is the default.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the system
<code class="literal">
zlib
</code>
library.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_zstd">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_zstd">
<code class="option">
-DWITH_ZSTD=
<em class="replaceable">
<code>
zstd_type
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327400608">
</a>
<a class="indexterm" name="idm46045327399120">
</a>
<p>
Connection compression using the
<code class="literal">
zstd
</code>
algorithm (see
<a class="xref" href="connection-compression-control.html" title="6.2.8 Connection Compression Control">
Section 6.2.8, “Connection Compression Control”
</a>
) requires
that the server be built with
<code class="literal">
zstd
</code>
library support. The
<a class="link" href="source-configuration-options.html#option_cmake_with_zstd">
<code class="option">
WITH_ZSTD
</code>
</a>
option indicates the source of
<code class="literal">
zstd
</code>
support:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
bundled
</code>
: Use the
<code class="literal">
zstd
</code>
library bundled with the
distribution. This is the default.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
system
</code>
: Use the system
<code class="literal">
zstd
</code>
library.
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="cmake-compiler-flags">
</a>
Compiler Flags
</h4>
</div>
</div>
</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_cmake_cmake_c_flags">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_cmake_c_flags">
<code class="option">
-DCMAKE_C_FLAGS="
<em class="replaceable">
<code>
flags
</code>
</em>
</code>
</a>
"
</p>
<a class="indexterm" name="idm46045327383952">
</a>
<a class="indexterm" name="idm46045327382464">
</a>
<p>
Flags for the C compiler.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_cmake_cxx_flags">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_cmake_cxx_flags">
<code class="option">
-DCMAKE_CXX_FLAGS="
<em class="replaceable">
<code>
flags
</code>
</em>
</code>
</a>
"
</p>
<a class="indexterm" name="idm46045327378016">
</a>
<a class="indexterm" name="idm46045327376528">
</a>
<p>
Flags for the C++ compiler.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_default_compiler_options">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_default_compiler_options">
<code class="option">
-DWITH_DEFAULT_COMPILER_OPTIONS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327372016">
</a>
<a class="indexterm" name="idm46045327370512">
</a>
<p>
Whether to use the flags from
<code class="filename">
cmake/build_configurations/compiler_options.cmake
</code>
.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
All optimization flags are carefully chosen and tested by
the MySQL build team. Overriding them can lead to
unexpected results and is done at your own risk.
</p>
</div>
</li>
<li class="listitem">
<p>
<a name="option_cmake_optimize_sanitizer_builds">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_optimize_sanitizer_builds">
<code class="option">
-DOPTIMIZE_SANITIZER_BUILDS=
<em class="replaceable">
<code>
bool
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327364384">
</a>
<a class="indexterm" name="idm46045327362880">
</a>
<p>
Whether to add
<code class="option">
-O1 -fno-inline
</code>
to sanitizer
builds. The default is
<code class="literal">
ON
</code>
.
</p>
</li>
</ul>
</div>
<p>
To specify your own C and C++ compiler flags, for flags that do
not affect optimization, use the
<a class="link" href="source-configuration-options.html#option_cmake_cmake_c_flags">
<code class="option">
CMAKE_C_FLAGS
</code>
</a>
and
<a class="link" href="source-configuration-options.html#option_cmake_cmake_cxx_flags">
<code class="option">
CMAKE_CXX_FLAGS
</code>
</a>
CMake options.
</p>
<p>
When providing your own compiler flags, you might want to
specify
<a class="link" href="source-configuration-options.html#option_cmake_cmake_build_type">
<code class="option">
CMAKE_BUILD_TYPE
</code>
</a>
as well.
</p>
<p>
For example, to create a 32-bit release build on a 64-bit Linux
machine, do this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa75358492"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mkdir</span> build
<span class="token prompt">$> </span><span class="token command">cd</span> build
<span class="token prompt">$> </span><span class="token command">cmake</span> <span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token constant">-DCMAKE_C_FLAGS</span><span class="token attr-value"><span class="token punctuation">=</span>-m32</span> \
<span class="token constant">-DCMAKE_CXX_FLAGS</span><span class="token attr-value"><span class="token punctuation">=</span>-m32</span> \
<span class="token constant">-DCMAKE_BUILD_TYPE</span><span class="token attr-value"><span class="token punctuation">=</span>RelWithDebInfo</span></code></pre>
</div>
<p>
If you set flags that affect optimization
(
<code class="option">
-O
<em class="replaceable">
<code>
number
</code>
</em>
</code>
), you must
set the
<code class="option">
CMAKE_C_FLAGS_
<em class="replaceable">
<code>
build_type
</code>
</em>
</code>
and/or
<code class="option">
CMAKE_CXX_FLAGS_
<em class="replaceable">
<code>
build_type
</code>
</em>
</code>
options, where
<em class="replaceable">
<code>
build_type
</code>
</em>
corresponds
to the
<a class="link" href="source-configuration-options.html#option_cmake_cmake_build_type">
<code class="option">
CMAKE_BUILD_TYPE
</code>
</a>
value. To
specify a different optimization for the default build type
(
<code class="literal">
RelWithDebInfo
</code>
) set the
<code class="option">
CMAKE_C_FLAGS_RELWITHDEBINFO
</code>
and
<code class="option">
CMAKE_CXX_FLAGS_RELWITHDEBINFO
</code>
options. For
example, to compile on Linux with
<code class="option">
-O3
</code>
and with
debug symbols, do this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa27946346"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">cmake</span> <span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token constant">-DCMAKE_C_FLAGS_RELWITHDEBINFO</span>=<span class="token atrule">"-O3 -g"</span> \
<span class="token constant">-DCMAKE_CXX_FLAGS_RELWITHDEBINFO</span>=<span class="token atrule">"-O3 -g"</span></code></pre>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="cmake-mysql-cluster-options">
</a>
CMake Options for Compiling NDB Cluster
</h4>
</div>
</div>
</div>
<p>
To compile with support for NDB Cluster, you can use
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb">
<code class="option">
-DWITH_NDB
</code>
</a>
, which causes the build
to include the NDB storage engine and all NDB programs. This
option is enabled by default. To prevent building of the NDB
storage engine plugin, use
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbcluster_storage_engine">
<code class="option">
-DWITH_NDBCLUSTER_STORAGE_ENGINE=OFF
</code>
</a>
.
Other aspects of the build can be controlled using the other
options listed in this section.
</p>
<p>
The following options apply when building the MySQL sources with
NDB Cluster support.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_cmake_ndb_utils_link_dynamic">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_ndb_utils_link_dynamic">
<code class="option">
-DNDB_UTILS_LINK_DYNAMIC={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327334816">
</a>
<a class="indexterm" name="idm46045327333328">
</a>
<p>
Controls whether NDB utilities such as
<a class="link" href="mysql-cluster-programs-ndb-drop-table.html" title="25.5.11 ndb_drop_table — Drop an NDB Table">
<span class="command">
<strong>
ndb_drop_table
</strong>
</span>
</a>
are linked with
<code class="literal">
ndbclient
</code>
statically
(
<code class="literal">
OFF
</code>
) or dynamically
(
<code class="literal">
ON
</code>
);
<code class="literal">
OFF
</code>
(static
linking) is the default. Normally static linking is used
when building these to avoid problems with
<code class="literal">
LD_LIBRARY_PATH
</code>
, or when multiple
versions of
<code class="literal">
ndbclient
</code>
are installed. This
option is intended for creating Docker images and possibly
other cases in which the target environment is subject to
precise control and it is desirable to reduce image size.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_classpath">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_classpath">
<code class="option">
-DWITH_CLASSPATH=
<em class="replaceable">
<code>
path
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327322784">
</a>
<a class="indexterm" name="idm46045327321296">
</a>
<p>
Sets the classpath for building MySQL NDB Cluster Connector for Java. The default is
empty. This option is ignored if
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_java">
<code class="option">
-DWITH_NDB_JAVA=OFF
</code>
</a>
is used.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_error_insert">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_error_insert">
<code class="option">
-DWITH_ERROR_INSERT={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327316096">
</a>
<a class="indexterm" name="idm46045327314592">
</a>
<p>
Enables error injection in the
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
kernel. For testing only;
not intended for use in building production binaries. The
default is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndb">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb">
<code class="option">
-DWITH_NDB={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327308496">
</a>
<a class="indexterm" name="idm46045327307008">
</a>
<p>
Build MySQL NDB Cluster; build the NDB plugin and all NDB
Cluster programs.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndbapi_examples">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbapi_examples">
<code class="option">
-DWITH_NDBAPI_EXAMPLES={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327302800">
</a>
<a class="indexterm" name="idm46045327301296">
</a>
<p>
Build NDB API example programs in
<code class="filename">
storage/ndb/ndbapi-examples/
</code>
. See
<a class="ulink" href="/doc/ndbapi/en/ndb-examples.html" target="_top">
NDB API Examples
</a>
, for information about these.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndbcluster_storage_engine">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbcluster_storage_engine">
<code class="option">
-DWITH_NDBCLUSTER_STORAGE_ENGINE={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327295520">
</a>
<a class="indexterm" name="idm46045327294016">
</a>
<p>
Controls (only) whether the
<code class="literal">
NDBCLUSTER
</code>
storage engine is included in the build;
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb">
<code class="option">
WITH_NDB
</code>
</a>
enables this option
automatically, so it is recommended that you use
<code class="option">
WITH_NDB
</code>
instead.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndbcluster">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbcluster">
<code class="option">
-DWITH_NDBCLUSTER={ON|OFF}
</code>
</a>
(DEPRECATED)
</p>
<a class="indexterm" name="idm46045327287552">
</a>
<a class="indexterm" name="idm46045327286064">
</a>
<p>
Build and link in support for the
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
storage engine in
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
.
</p>
<p>
This option is deprecated and subject to eventual removal;
use
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb">
<code class="option">
WITH_NDB
</code>
</a>
instead.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndbmtd">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndbmtd">
<code class="option">
-DWITH_NDBMTD={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327277968">
</a>
<a class="indexterm" name="idm46045327276480">
</a>
<p>
Build the multithreaded data node executable
<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
</strong>
</span>
</a>
. The default is
<code class="literal">
ON
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndb_debug">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_debug">
<code class="option">
-DWITH_NDB_DEBUG={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327270224">
</a>
<a class="indexterm" name="idm46045327268736">
</a>
<p>
Enable building the debug versions of the NDB Cluster
binaries. This is
<code class="literal">
OFF
</code>
by default.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndb_java">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_java">
<code class="option">
-DWITH_NDB_JAVA={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327263920">
</a>
<a class="indexterm" name="idm46045327262432">
</a>
<p>
Enable building NDB Cluster with Java support, including
support for ClusterJ (see
<a class="ulink" href="/doc/ndbapi/en/mccj.html" target="_top">
MySQL NDB Cluster Connector for Java
</a>
).
</p>
<p>
This option is
<code class="literal">
ON
</code>
by default. If you do
not wish to compile NDB Cluster with Java support, you must
disable it explicitly by specifying
<code class="option">
-DWITH_NDB_JAVA=OFF
</code>
when running
<span class="command">
<strong>
CMake
</strong>
</span>
. Otherwise, if Java cannot be
found, configuration of the build fails.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndb_port">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_port">
<code class="option">
-DWITH_NDB_PORT=
<em class="replaceable">
<code>
port
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327254608">
</a>
<a class="indexterm" name="idm46045327253120">
</a>
<p>
Causes the NDB Cluster management server
(
<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>
) that is built to use this
<em class="replaceable">
<code>
port
</code>
</em>
by default. If this option
is unset, the resulting management server tries to use port
1186 by default.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndb_test">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_test">
<code class="option">
-DWITH_NDB_TEST={ON|OFF}
</code>
</a>
</p>
<a class="indexterm" name="idm46045327247024">
</a>
<a class="indexterm" name="idm46045327245536">
</a>
<p>
If enabled, include a set of NDB API test programs. The
default is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_cmake_with_ndb_tls_search_path">
</a>
<a class="link" href="source-configuration-options.html#option_cmake_with_ndb_tls_search_path">
<code class="option">
-DWITH_NDB_TLS_SEARCH_PATH=
<em class="replaceable">
<code>
path
</code>
</em>
</code>
</a>
</p>
<a class="indexterm" name="idm46045327240368">
</a>
<a class="indexterm" name="idm46045327238864">
</a>
<p>
Set the default path searched by
<a class="link" href="mysql-cluster-programs-ndb-sign-keys.html" title="25.5.28 ndb_sign_keys — Create, Sign, and Manage TLS Keys and Certificates for NDB Cluster">
<span class="command">
<strong>
ndb_sign_keys
</strong>
</span>
</a>
and other
<code class="literal">
NDB
</code>
programs for TLS certificate and key
files.
</p>
<p>
The default for Windows platforms is
<code class="literal">
$HOMEDIR/ndb-tls
</code>
; for other platforms,
such as Linux, it is
<code class="literal">
$HOME/ndb-tls
</code>
.
</p>
</li>
</ul>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/sql-server-administration-statements.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="sql-server-administration-statements">
</a>
15.7 Database Administration Statements
</h2>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<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>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/json.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="json">
</a>
13.5 The JSON Data Type
</h2>
</div>
</div>
</div>
<a class="indexterm" name="idm46045211477120">
</a>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="json.html#json-values" title="Creating JSON Values">
Creating JSON Values
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="json.html#json-normalization" title="Normalization, Merging, and Autowrapping of JSON Values">
Normalization, Merging, and Autowrapping of JSON Values
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="json.html#json-paths" title="Searching and Modifying JSON Values">
Searching and Modifying JSON Values
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="json.html#json-path-syntax" title="JSON Path Syntax">
JSON Path Syntax
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="json.html#json-comparison" title="Comparison and Ordering of JSON Values">
Comparison and Ordering of JSON Values
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="json.html#json-converting-between-types" title="Converting between JSON and non-JSON values">
Converting between JSON and non-JSON values
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="json.html#json-aggregation" title="Aggregation of JSON Values">
Aggregation of JSON Values
</a>
</p>
</li>
</ul>
</div>
<p>
MySQL supports a native
<code class="literal">
JSON
</code>
data type defined
by
<a class="ulink" href="https://tools.ietf.org/html/rfc7159" target="_blank">
RFC
7159
</a>
that enables efficient access to data in JSON
(JavaScript Object Notation) documents. The
<code class="literal">
JSON
</code>
data type provides these advantages over
storing JSON-format strings in a string column:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Automatic validation of JSON documents stored in
<code class="literal">
JSON
</code>
columns. Invalid documents produce an
error.
</p>
</li>
<li class="listitem">
<p>
Optimized storage format. JSON documents stored in
<code class="literal">
JSON
</code>
columns are converted to an internal
format that permits quick read access to document elements.
When the server later must read a JSON value stored in this
binary format, the value need not be parsed from a text
representation. The binary format is structured to enable the
server to look up subobjects or nested values directly by key
or array index without reading all values before or after them
in the document.
</p>
</li>
</ul>
</div>
<p>
MySQL 8.4 also supports the
<span class="emphasis">
<em>
JSON Merge
Patch
</em>
</span>
format defined in
<a class="ulink" href="https://tools.ietf.org/html/rfc7396" target="_blank">
RFC 7396
</a>
,
using the
<a class="link" href="json-modification-functions.html#function_json-merge-patch">
<code class="literal">
JSON_MERGE_PATCH()
</code>
</a>
function. See the description of this function, as well as
<a class="xref" href="json.html#json-normalization" title="Normalization, Merging, and Autowrapping of JSON Values">
Normalization, Merging, and Autowrapping of JSON Values
</a>
, for examples and further
information.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
This discussion uses
<code class="literal">
JSON
</code>
in monotype to
indicate specifically the JSON data type and
<span class="quote">
“
<span class="quote">
JSON
</span>
”
</span>
in regular font to indicate JSON data in general.
</p>
</div>
<p>
The space required to store a
<code class="literal">
JSON
</code>
document is
roughly the same as for
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGBLOB
</code>
</a>
or
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGTEXT
</code>
</a>
; see
<a class="xref" href="storage-requirements.html" title="13.7 Data Type Storage Requirements">
Section 13.7, “Data Type Storage Requirements”
</a>
, for more information. It
is important to keep in mind that the size of any JSON document
stored in a
<code class="literal">
JSON
</code>
column is limited to the 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. (When the server is manipulating a JSON value internally
in memory, it can be larger than this; the limit applies when the
server stores it.) You can obtain the amount of space required to
store a JSON document using the
<a class="link" href="json-utility-functions.html#function_json-storage-size">
<code class="literal">
JSON_STORAGE_SIZE()
</code>
</a>
function; note
that for a
<a class="link" href="json.html" title="13.5 The JSON Data Type">
<code class="literal">
JSON
</code>
</a>
column, the storage
size—and thus the value returned by this function—is
that used by the column prior to any partial updates that may have
been performed on it (see the discussion of the JSON partial
update optimization later in this section).
</p>
<p>
Along with the
<code class="literal">
JSON
</code>
data type, a set of SQL
functions is available to enable operations on JSON values, such
as creation, manipulation, and searching. The following discussion
shows examples of these operations. For details about individual
functions, see
<a class="xref" href="json-functions.html" title="14.17 JSON Functions">
Section 14.17, “JSON Functions”
</a>
.
</p>
<p>
A set of spatial functions for operating on GeoJSON values is also
available. See
<a class="xref" href="spatial-geojson-functions.html" title="14.16.11 Spatial GeoJSON Functions">
Section 14.16.11, “Spatial GeoJSON Functions”
</a>
.
</p>
<p>
<code class="literal">
JSON
</code>
columns, like columns of other binary
types, are not indexed directly; instead, you can create an index
on a generated column that extracts a scalar value from the
<code class="literal">
JSON
</code>
column. See
<a class="xref" href="create-table-secondary-indexes.html#json-column-indirect-index" title="Indexing a Generated Column to Provide a JSON Column Index">
Indexing a Generated Column to Provide a JSON Column Index
</a>
, for a detailed
example.
</p>
<p>
The MySQL optimizer also looks for compatible indexes on virtual
columns that match JSON expressions.
</p>
<p>
The
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
storage engine supports
multi-valued indexes on JSON arrays. See
<a class="xref" href="create-index.html#create-index-multi-valued" title="Multi-Valued Indexes">
Multi-Valued Indexes
</a>
.
</p>
<p>
MySQL NDB Cluster supports
<code class="literal">
JSON
</code>
columns and
MySQL JSON functions, including creation of an index on a column
generated from a
<code class="literal">
JSON
</code>
column as a workaround
for being unable to index a
<code class="literal">
JSON
</code>
column. A
maximum of 3
<code class="literal">
JSON
</code>
columns per
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
table is supported.
</p>
<h3>
<a name="json-partial-updates">
</a>
Partial Updates of JSON Values
</h3>
<p>
In MySQL 8.4, the optimizer can perform a partial,
in-place update of a
<code class="literal">
JSON
</code>
column instead of
removing the old document and writing the new document in its
entirety to the column. This optimization can be performed for an
update that meets the following conditions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The column being updated was declared as
<code class="literal">
JSON
</code>
.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="update.html" title="15.2.17 UPDATE Statement">
<code class="literal">
UPDATE
</code>
</a>
statement uses any
of the three functions
<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>
, or
<a class="link" href="json-modification-functions.html#function_json-remove">
<code class="literal">
JSON_REMOVE()
</code>
</a>
to update the
column. A direct assignment of the column value (for example,
<code class="literal">
UPDATE mytable SET jcol = '{"a": 10, "b":
25}'
</code>
) cannot be performed as a partial update.
</p>
<p>
Updates of multiple
<code class="literal">
JSON
</code>
columns in a
single
<code class="literal">
UPDATE
</code>
statement can be optimized in
this fashion; MySQL can perform partial updates of only those
columns whose values are updated using the three functions
just listed.
</p>
</li>
<li class="listitem">
<p>
The input column and the target column must be the same
column; a statement such as
<code class="literal">
UPDATE mytable SET jcol1
= JSON_SET(jcol2, '$.a', 100)
</code>
cannot be performed as
a partial update.
</p>
<p>
The update can use nested calls to any of the functions listed
in the previous item, in any combination, as long as the input
and target columns are the same.
</p>
</li>
<li class="listitem">
<p>
All changes replace existing array or object values with new
ones, and do not add any new elements to the parent object or
array.
</p>
</li>
<li class="listitem">
<p>
The value being replaced must be at least as large as the
replacement value. In other words, the new value cannot be any
larger than the old one.
</p>
<p>
A possible exception to this requirement occurs when a
previous partial update has left sufficient space for the
larger value. You can use the function
<a class="link" href="json-utility-functions.html#function_json-storage-free">
<code class="literal">
JSON_STORAGE_FREE()
</code>
</a>
see how
much space has been freed by any partial updates of a
<code class="literal">
JSON
</code>
column.
</p>
</li>
</ul>
</div>
<p>
Such partial updates can be written to the binary log using a
compact format that saves space; this can be enabled by setting
the
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_value_options">
<code class="literal">
binlog_row_value_options
</code>
</a>
system variable to
<code class="literal">
PARTIAL_JSON
</code>
.
</p>
<p>
It is important to distinguish the partial update of a
<code class="literal">
JSON
</code>
column value stored in a table from
writing the partial update of a row to the binary log. It is
possible for the complete update of a
<code class="literal">
JSON
</code>
column to be recorded in the binary log as a partial update. This
can happen when either (or both) of the last two conditions from
the previous list is not met but the other conditions are
satisfied.
</p>
<p>
See also the description of
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_row_value_options">
<code class="literal">
binlog_row_value_options
</code>
</a>
.
</p>
<p>
The next few sections provide basic information regarding the
creation and manipulation of JSON values.
</p>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-values">
</a>
Creating JSON Values
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045211402704">
</a>
<a class="indexterm" name="idm46045211401216">
</a>
<a class="indexterm" name="idm46045211399728">
</a>
<a class="indexterm" name="idm46045211398240">
</a>
<a class="indexterm" name="idm46045211396752">
</a>
<a class="indexterm" name="idm46045211395264">
</a>
<a class="indexterm" name="idm46045211393776">
</a>
<a class="indexterm" name="idm46045211392288">
</a>
<a class="indexterm" name="idm46045211390800">
</a>
<a class="indexterm" name="idm46045211389312">
</a>
<a class="indexterm" name="idm46045211387824">
</a>
<a class="indexterm" name="idm46045211386336">
</a>
<a class="indexterm" name="idm46045211384848">
</a>
<a class="indexterm" name="idm46045211383360">
</a>
<a class="indexterm" name="idm46045211381872">
</a>
<a class="indexterm" name="idm46045211380384">
</a>
<p>
A JSON array contains a list of values separated by commas and
enclosed within
<code class="literal">
[
</code>
and
<code class="literal">
]
</code>
characters:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-json"><div class="docs-select-all right" id="sa91705086"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">[</span><span class="token string">"abc"</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token null">null</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">]</span></code></pre>
</div>
<p>
A JSON object contains a set of key-value pairs separated by
commas and enclosed within
<code class="literal">
{
</code>
and
<code class="literal">
}
</code>
characters:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-json"><div class="docs-select-all right" id="sa29829402"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">{</span><span class="token property">"k1"</span><span class="token operator">:</span> <span class="token string">"value"</span><span class="token punctuation">,</span> <span class="token property">"k2"</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">}</span></code></pre>
</div>
<p>
As the examples illustrate, JSON arrays and objects can contain
scalar values that are strings or numbers, the JSON null
literal, or the JSON boolean true or false literals. Keys in
JSON objects must be strings. Temporal (date, time, or datetime)
scalar values are also permitted:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-json"><div class="docs-select-all right" id="sa63375450"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">[</span><span class="token string">"12:18:29.000000"</span><span class="token punctuation">,</span> <span class="token string">"2015-07-29"</span><span class="token punctuation">,</span> <span class="token string">"2015-07-29 12:18:29.000000"</span><span class="token punctuation">]</span></code></pre>
</div>
<p>
Nesting is permitted within JSON array elements and JSON object
key values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-json"><div class="docs-select-all right" id="sa83875838"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">[</span><span class="token number">99</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token property">"id"</span><span class="token operator">:</span> <span class="token string">"HK500"</span><span class="token punctuation">,</span> <span class="token property">"cost"</span><span class="token operator">:</span> <span class="token number">75.99</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">"hot"</span><span class="token punctuation">,</span> <span class="token string">"cold"</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
<span class="token punctuation">{</span><span class="token property">"k1"</span><span class="token operator">:</span> <span class="token string">"value"</span><span class="token punctuation">,</span> <span class="token property">"k2"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">]</span><span class="token punctuation">}</span></code></pre>
</div>
<p>
You can also obtain JSON values from a number of functions
supplied by MySQL for this purpose (see
<a class="xref" href="json-creation-functions.html" title="14.17.2 Functions That Create JSON Values">
Section 14.17.2, “Functions That Create JSON Values”
</a>
) as well as by casting
values of other types to the
<code class="literal">
JSON
</code>
type using
<a class="link" href="cast-functions.html#function_cast">
<code class="literal">
CAST(
<em class="replaceable">
<code>
value
</code>
</em>
AS
JSON)
</code>
</a>
(see
<a class="xref" href="json.html#json-converting-between-types" title="Converting between JSON and non-JSON values">
Converting between JSON and non-JSON values
</a>
). The next
several paragraphs describe how MySQL handles JSON values
provided as input.
</p>
<a class="indexterm" name="idm46045211365232">
</a>
<a class="indexterm" name="idm46045211364160">
</a>
<p>
In MySQL, JSON values are written as strings. MySQL parses any
string used in a context that requires a JSON value, and
produces an error if it is not valid as JSON. These contexts
include inserting a value into a column that has the
<code class="literal">
JSON
</code>
data type and passing an argument to a
function that expects a JSON value (usually shown as
<em class="replaceable">
<code>
json_doc
</code>
</em>
or
<em class="replaceable">
<code>
json_val
</code>
</em>
in the documentation for
MySQL JSON functions), as the following examples demonstrate:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Attempting to insert a value into a
<code class="literal">
JSON
</code>
column succeeds if the value is a valid JSON value, but
fails if it is not:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35706153"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1 <span class="token punctuation">(</span>jdoc <span class="token datatype">JSON</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.20 sec)</span>
<span class="token prompt">mysql></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 string">'{"key1": "value1", "key2": "value2"}'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 1 row affected (0.01 sec)</span>
<span class="token prompt">mysql></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 string">'[1, 2,'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">ERROR 3140 (22032) at line 2<span class="token punctuation">:</span> Invalid JSON text<span class="token punctuation">:</span>
"Invalid value." at position 6 in value (or column) '[1, 2,'.</span></code></pre>
</div>
<p>
Positions for
<span class="quote">
“
<span class="quote">
at position
<em class="replaceable">
<code>
N
</code>
</em>
</span>
”
</span>
in such error messages
are 0-based, but should be considered rough indications of
where the problem in a value actually occurs.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="json-attribute-functions.html#function_json-type">
<code class="literal">
JSON_TYPE()
</code>
</a>
function
expects a JSON argument and attempts to parse it into a JSON
value. It returns the value's JSON type if it is valid
and produces an error otherwise:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa83089559"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_TYPE</span><span class="token punctuation">(</span><span class="token string">'["a", "b", 1]'</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> JSON_TYPE('["a", "b", 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>
<span class="token output"><span class="token punctuation">|</span> ARRAY <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 prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_TYPE</span><span class="token punctuation">(</span><span class="token string">'"hello"'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_TYPE('"hello"') <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> STRING <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 prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_TYPE</span><span class="token punctuation">(</span><span class="token string">'hello'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">ERROR 3146 (22032)<span class="token punctuation">:</span> Invalid data type for JSON data in argument 1
to function json_type; a JSON string or JSON type is required.</span></code></pre>
</div>
</li>
</ul>
</div>
<p>
MySQL handles strings used in JSON context using the
<code class="literal">
utf8mb4
</code>
character set and
<code class="literal">
utf8mb4_bin
</code>
collation. Strings in other
character sets are converted to
<code class="literal">
utf8mb4
</code>
as
necessary. (For strings in the
<code class="literal">
ascii
</code>
or
<code class="literal">
utf8mb3
</code>
character sets, no conversion is
needed because
<code class="literal">
ascii
</code>
and
<code class="literal">
utf8mb3
</code>
are subsets of
<code class="literal">
utf8mb4
</code>
.)
</p>
<p>
As an alternative to writing JSON values using literal strings,
functions exist for composing JSON values from component
elements.
<a class="link" href="json-creation-functions.html#function_json-array">
<code class="literal">
JSON_ARRAY()
</code>
</a>
takes a
(possibly empty) list of values and returns a JSON array
containing those values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa97797173"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_ARRAY</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token function">NOW</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>
<span class="token output"><span class="token punctuation">|</span> JSON_ARRAY('a', 1, NOW()) <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> ["a", 1, "2015<span class="token punctuation">-</span>07<span class="token punctuation">-</span>27 09:43:47.000000"] <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></code></pre>
</div>
<p>
<a class="link" href="json-creation-functions.html#function_json-object">
<code class="literal">
JSON_OBJECT()
</code>
</a>
takes a (possibly
empty) list of key-value pairs and returns a JSON object
containing those pairs:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa62602742"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'key1'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'key2'</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> JSON_OBJECT('key1', 1, 'key2', '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>
<span class="token output"><span class="token punctuation">|</span> {"key1": 1, "key2": "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></code></pre>
</div>
<p>
<a class="link" href="json-modification-functions.html#function_json-merge-preserve">
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
</a>
takes two
or more JSON documents and returns the combined result:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68870711"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_MERGE_PRESERVE</span><span class="token punctuation">(</span><span class="token string">'["a", 1]'</span><span class="token punctuation">,</span> <span class="token string">'{"key": "value"}'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_MERGE_PRESERVE('["a", 1]', '{"key": "value"}') <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ["a", 1, {"key": "value"}] <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
For information about the merging rules, see
<a class="xref" href="json.html#json-normalization" title="Normalization, Merging, and Autowrapping of JSON Values">
Normalization, Merging, and Autowrapping of JSON Values
</a>
.
</p>
<p>
(MySQL also supports
<a class="link" href="json-modification-functions.html#function_json-merge-patch">
<code class="literal">
JSON_MERGE_PATCH()
</code>
</a>
, which has
somewhat different behavior. See
<a class="xref" href="json-modification-functions.html#json-merge-patch-json-merge-preserve-compared" title="JSON_MERGE_PATCH() compared with JSON_MERGE_PRESERVE()">
JSON_MERGE_PATCH() compared with JSON_MERGE_PRESERVE()
</a>
,
for information about the differences between these two
functions.)
</p>
<p>
JSON values can be assigned to user-defined variables:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa13219347"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token variable">@j</span> <span class="token operator">=</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'key'</span><span class="token punctuation">,</span> <span class="token string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token variable">@j</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>
<span class="token output"><span class="token punctuation">|</span> @j <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>
<span class="token output"><span class="token punctuation">|</span> {"key": "value"} <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></code></pre>
</div>
<p>
However, user-defined variables cannot be of
<code class="literal">
JSON
</code>
data type, so although
<code class="literal">
@j
</code>
in the preceding example looks like a JSON
value and has the same character set and collation as a JSON
value, it does
<span class="emphasis">
<em>
not
</em>
</span>
have the
<code class="literal">
JSON
</code>
data type. Instead, the result from
<a class="link" href="json-creation-functions.html#function_json-object">
<code class="literal">
JSON_OBJECT()
</code>
</a>
is converted to a
string when assigned to the variable.
</p>
<p>
Strings produced by converting JSON values have a character set
of
<code class="literal">
utf8mb4
</code>
and a collation of
<code class="literal">
utf8mb4_bin
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38756740"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">CHARSET</span><span class="token punctuation">(</span><span class="token variable">@j</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">COLLATION</span><span class="token punctuation">(</span><span class="token variable">@j</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> CHARSET(@j) <span class="token punctuation">|</span> COLLATION(@j) <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> utf8mb4 <span class="token punctuation">|</span> utf8mb4_bin <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>
<p>
Because
<code class="literal">
utf8mb4_bin
</code>
is a binary collation,
comparison of JSON values is case-sensitive.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16032522"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_ARRAY</span><span class="token punctuation">(</span><span class="token string">'x'</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token function">JSON_ARRAY</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> JSON_ARRAY('x') = JSON_ARRAY('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> 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></code></pre>
</div>
<a class="indexterm" name="idm46045211311200">
</a>
<p>
Case sensitivity also applies to the JSON
<code class="literal">
null
</code>
,
<code class="literal">
true
</code>
, and
<code class="literal">
false
</code>
literals, which always must be written
in lowercase:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa93824205"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_VALID</span><span class="token punctuation">(</span><span class="token string">'null'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">JSON_VALID</span><span class="token punctuation">(</span><span class="token string">'Null'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">JSON_VALID</span><span class="token punctuation">(</span><span class="token string">'NULL'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_VALID('null') <span class="token punctuation">|</span> JSON_VALID('Null') <span class="token punctuation">|</span> JSON_VALID('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 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> 0 <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>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">CAST</span><span class="token punctuation">(</span><span class="token string">'null'</span> <span class="token keyword">AS</span> <span class="token datatype">JSON</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>
<span class="token output"><span class="token punctuation">|</span> CAST('null' AS JSON) <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> 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>
<span class="token output">1 row in set (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">CAST</span><span class="token punctuation">(</span><span class="token string">'NULL'</span> <span class="token keyword">AS</span> <span class="token datatype">JSON</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">ERROR 3141 (22032)<span class="token punctuation">:</span> Invalid JSON text in argument 1 to function cast_as_json<span class="token punctuation">:</span>
"Invalid value." at position 0 in 'NULL'.</span></code></pre>
</div>
<p>
Case sensitivity of the JSON literals differs from that of the
SQL
<code class="literal">
NULL
</code>
,
<code class="literal">
TRUE
</code>
, and
<code class="literal">
FALSE
</code>
literals, which can be written in any
lettercase:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74763494"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">ISNULL</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 function">ISNULL</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 function">ISNULL</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 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> ISNULL(null) <span class="token punctuation">|</span> ISNULL(Null) <span class="token punctuation">|</span> ISNULL(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>
<span class="token output"><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></code></pre>
</div>
<a class="indexterm" name="idm46045211298256">
</a>
<p>
Sometimes it may be necessary or desirable to insert quote
characters (
<code class="literal">
"
</code>
or
<code class="literal">
'
</code>
) into a
JSON document. Assume for this example that you want to insert
some JSON objects containing strings representing sentences that
state some facts about MySQL, each paired with an appropriate
keyword, into a table created using the SQL statement shown
here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa64337527"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> facts <span class="token punctuation">(</span>sentence <span class="token datatype">JSON</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Among these keyword-sentence pairs is this one:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa87809980"><div class="copy-help left">Press ⌘+C to 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">mascot<span class="token operator">:</span> The MySQL mascot is a dolphin named "Sakila"<span class="token punctuation">.</span></code></pre>
</div>
<p>
One way to insert this as a JSON object into the
<code class="literal">
facts
</code>
table is to use the MySQL
<a class="link" href="json-creation-functions.html#function_json-object">
<code class="literal">
JSON_OBJECT()
</code>
</a>
function. In this
case, you must escape each quote character using a backslash, as
shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa62648737"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> facts <span class="token keyword">VALUES</span>
<span class="token operator">></span> <span class="token punctuation">(</span><span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">"mascot"</span><span class="token punctuation">,</span> <span class="token string">"Our mascot is a dolphin named \"Sakila\"."</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
This does not work in the same way if you insert the value as a
JSON object literal, in which case, you must use the double
backslash escape sequence, like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa97328696"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> facts <span class="token keyword">VALUES</span>
<span class="token operator">></span> <span class="token punctuation">(</span><span class="token string">'{"mascot": "Our mascot is a dolphin named \\"Sakila\\"."}'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Using the double backslash keeps MySQL from performing escape
sequence processing, and instead causes it to pass the string
literal to the storage engine for processing. After inserting
the JSON object in either of the ways just shown, you can see
that the backslashes are present in the JSON column value by
doing a simple
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
, like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa37482119"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> sentence <span class="token keyword">FROM</span> facts<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> sentence <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> {"mascot": "Our mascot is a dolphin named \"Sakila\"."} <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></code></pre>
</div>
<p>
To look up this particular sentence employing
<code class="literal">
mascot
</code>
as the key, you can use the
column-path operator
<a class="link" href="json-search-functions.html#operator_json-column-path">
<code class="literal">
->
</code>
</a>
,
as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa30887842"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> col<span class="token operator">-</span><span class="token operator">></span><span class="token string">"$.mascot"</span> <span class="token keyword">FROM</span> qtest<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> col<span class="token punctuation">-</span>>"$.mascot" <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> "Our mascot is a dolphin named \"Sakila\"." <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
This leaves the backslashes intact, along with the surrounding
quote marks. To display the desired value using
<code class="literal">
mascot
</code>
as the key, but without including the
surrounding quote marks or any escapes, use the inline path
operator
<a class="link" href="json-search-functions.html#operator_json-inline-path">
<code class="literal">
->>
</code>
</a>
,
like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa51819213"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> sentence<span class="token operator">-</span><span class="token operator">>></span><span class="token string">"$.mascot"</span> <span class="token keyword">FROM</span> facts<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>
<span class="token output"><span class="token punctuation">|</span> sentence<span class="token punctuation">-</span>>>"$.mascot" <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>
<span class="token output"><span class="token punctuation">|</span> Our mascot is a dolphin named "Sakila". <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></code></pre>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
The previous example does not work as shown if the
<a class="link" href="sql-mode.html#sqlmode_no_backslash_escapes">
<code class="literal">
NO_BACKSLASH_ESCAPES
</code>
</a>
server
SQL mode is enabled. If this mode is set, a single backslash
instead of double backslashes can be used to insert the JSON
object literal, and the backslashes are preserved. If you use
the
<code class="literal">
JSON_OBJECT()
</code>
function when performing
the insert and this mode is set, you must alternate single and
double quotes, like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84813147"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> facts <span class="token keyword">VALUES</span>
<span class="token operator">></span> <span class="token punctuation">(</span><span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'mascot'</span><span class="token punctuation">,</span> <span class="token string">'Our mascot is a dolphin named "Sakila".'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
See the description of the
<a class="link" href="json-modification-functions.html#function_json-unquote">
<code class="literal">
JSON_UNQUOTE()
</code>
</a>
function for
more information about the effects of this mode on escaped
characters in JSON values.
</p>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-normalization">
</a>
Normalization, Merging, and Autowrapping of JSON Values
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045211261312">
</a>
<a class="indexterm" name="idm46045211259856">
</a>
<a class="indexterm" name="idm46045211258784">
</a>
<a class="indexterm" name="idm46045211257296">
</a>
<a class="indexterm" name="idm46045211256224">
</a>
<a class="indexterm" name="idm46045211254736">
</a>
<p>
When a string is parsed and found to be a valid JSON document,
it is also normalized. This means that members with keys that
duplicate a key found later in the document, reading from left
to right, are discarded. The object value produced by the
following
<a class="link" href="json-creation-functions.html#function_json-object">
<code class="literal">
JSON_OBJECT()
</code>
</a>
call
includes only the second
<code class="literal">
key1
</code>
element because
that key name occurs earlier in the value, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40851271"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_OBJECT</span><span class="token punctuation">(</span><span class="token string">'key1'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'key2'</span><span class="token punctuation">,</span> <span class="token string">'abc'</span><span class="token punctuation">,</span> <span class="token string">'key1'</span><span class="token punctuation">,</span> <span class="token string">'def'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_OBJECT('key1', 1, 'key2', 'abc', 'key1', 'def') <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>
<span class="token output"><span class="token punctuation">|</span> {"key1": "def", "key2": "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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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>
Normalization is also performed when values are inserted into
JSON columns, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49953411"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1 <span class="token punctuation">(</span>c1 <span class="token datatype">JSON</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t1 <span class="token keyword">VALUES</span>
<span class="token operator">></span> <span class="token punctuation">(</span><span class="token string">'{"x": 17, "x": "red"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token operator">></span> <span class="token punctuation">(</span><span class="token string">'{"x": 17, "x": "red", "x": [3, 5, 7]}'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> c1 <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>
<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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> {"x": "red"} <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> {"x": [3, 5, 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 class="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
<span class="quote">
“
<span class="quote">
last duplicate key wins
</span>
”
</span>
behavior is
suggested by
<a class="ulink" href="https://tools.ietf.org/html/rfc7159" target="_blank">
RFC
7159
</a>
and is implemented by most JavaScript parsers. (Bug
#86866, Bug #26369555)
</p>
<p>
MySQL discards extra whitespace between keys, values, or
elements in the original JSON document, and leaves (or inserts,
when necessary) a single space following each comma
(
<code class="literal">
,
</code>
) or colon (
<code class="literal">
:
</code>
) when
displaying it. This is done to enhance readability.
</p>
<p>
MySQL functions that produce JSON values (see
<a class="xref" href="json-creation-functions.html" title="14.17.2 Functions That Create JSON Values">
Section 14.17.2, “Functions That Create JSON Values”
</a>
) always return
normalized values.
</p>
<p>
To make lookups more efficient, MySQL also sorts the keys of a
JSON object.
<span class="emphasis">
<em>
You should be aware that the result of
this ordering is subject to change and not guaranteed to be
consistent across releases
</em>
</span>
.
</p>
<h4>
<a name="json-merging">
</a>
Merging JSON Values
</h4>
<a class="indexterm" name="idm46045211235824">
</a>
<a class="indexterm" name="idm46045211234752">
</a>
<a class="indexterm" name="idm46045211233680">
</a>
<a class="indexterm" name="idm46045211232608">
</a>
<p>
Two merging algorithms are supported, implemented by the
functions
<a class="link" href="json-modification-functions.html#function_json-merge-preserve">
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
</a>
and
<a class="link" href="json-modification-functions.html#function_json-merge-patch">
<code class="literal">
JSON_MERGE_PATCH()
</code>
</a>
. These
differ in how they handle duplicate keys:
<a class="link" href="json-modification-functions.html#function_json-merge-preserve">
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
</a>
retains
values for duplicate keys, while
<a class="link" href="json-modification-functions.html#function_json-merge-patch">
<code class="literal">
JSON_MERGE_PATCH()
</code>
</a>
discards all
but the last value. The next few paragraphs explain how each of
these two functions handles the merging of different
combinations of JSON documents (that is, of objects and arrays).
</p>
<p>
<b>
Merging arrays.
</b>
In contexts that combine multiple arrays, the arrays are
merged into a single array.
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
does this by
concatenating arrays named later to the end of the first
array.
<code class="literal">
JSON_MERGE_PATCH()
</code>
considers each
argument as an array consisting of a single element (thus
having 0 as its index) and then applies
<span class="quote">
“
<span class="quote">
last duplicate
key wins
</span>
”
</span>
logic to select only the last argument. You
can compare the results shown by this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47027224"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PRESERVE</span><span class="token punctuation">(</span><span class="token string">'[1, 2]'</span><span class="token punctuation">,</span> <span class="token string">'["a", "b", "c"]'</span><span class="token punctuation">,</span> <span class="token string">'[true, false]'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">Preserve</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PATCH</span><span class="token punctuation">(</span><span class="token string">'[1, 2]'</span><span class="token punctuation">,</span> <span class="token string">'["a", "b", "c"]'</span><span class="token punctuation">,</span> <span class="token string">'[true, false]'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> Patch\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>
Preserve<span class="token punctuation">:</span> [1, 2, "a", "b", "c", true, false]
Patch<span class="token punctuation">:</span> [true, false]</span></code></pre>
</div>
<p>
Multiple objects when merged produce a single object.
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
handles multiple
objects having the same key by combining all unique values for
that key in an array; this array is then used as the value for
that key in the result.
<code class="literal">
JSON_MERGE_PATCH()
</code>
discards values for which duplicate keys are found, working from
left to right, so that the result contains only the last value
for that key. The following query illustrates the difference in
the results for the duplicate key
<code class="literal">
a
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41568547"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PRESERVE</span><span class="token punctuation">(</span><span class="token string">'{"a": 1, "b": 2}'</span><span class="token punctuation">,</span> <span class="token string">'{"c": 3, "a": 4}'</span><span class="token punctuation">,</span> <span class="token string">'{"c": 5, "d": 3}'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">Preserve</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PATCH</span><span class="token punctuation">(</span><span class="token string">'{"a": 3, "b": 2}'</span><span class="token punctuation">,</span> <span class="token string">'{"c": 3, "a": 4}'</span><span class="token punctuation">,</span> <span class="token string">'{"c": 5, "d": 3}'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> Patch\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>
Preserve<span class="token punctuation">:</span> {"a"<span class="token punctuation">:</span> [1, 4], "b"<span class="token punctuation">:</span> 2, "c"<span class="token punctuation">:</span> [3, 5], "d"<span class="token punctuation">:</span> 3}
Patch<span class="token punctuation">:</span> {"a"<span class="token punctuation">:</span> 4, "b"<span class="token punctuation">:</span> 2, "c"<span class="token punctuation">:</span> 5, "d"<span class="token punctuation">:</span> 3}</span></code></pre>
</div>
<p>
Nonarray values used in a context that requires an array value
are autowrapped: The value is surrounded by
<code class="literal">
[
</code>
and
<code class="literal">
]
</code>
characters to convert it to an array.
In the following statement, each argument is autowrapped as an
array (
<code class="literal">
[1]
</code>
,
<code class="literal">
[2]
</code>
). These
are then merged to produce a single result array; as in the
previous two cases,
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
combines values having the same key while
<code class="literal">
JSON_MERGE_PATCH()
</code>
discards values for all
duplicate keys except the last, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61842770"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PRESERVE</span><span class="token punctuation">(</span><span class="token string">'1'</span><span class="token punctuation">,</span> <span class="token string">'2'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">Preserve</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PATCH</span><span class="token punctuation">(</span><span class="token string">'1'</span><span class="token punctuation">,</span> <span class="token string">'2'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> Patch\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>
Preserve<span class="token punctuation">:</span> [1, 2]
Patch<span class="token punctuation">:</span> 2</span></code></pre>
</div>
<p>
Array and object values are merged by autowrapping the object as
an array and merging the arrays by combining values or by
<span class="quote">
“
<span class="quote">
last duplicate key wins
</span>
”
</span>
according to the choice
of merging function (
<code class="literal">
JSON_MERGE_PRESERVE()
</code>
or
<code class="literal">
JSON_MERGE_PATCH()
</code>
, respectively), as can be
seen in this example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44999392"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PRESERVE</span><span class="token punctuation">(</span><span class="token string">'[10, 20]'</span><span class="token punctuation">,</span> <span class="token string">'{"a": "x", "b": "y"}'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">Preserve</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> <span class="token function">JSON_MERGE_PATCH</span><span class="token punctuation">(</span><span class="token string">'[10, 20]'</span><span class="token punctuation">,</span> <span class="token string">'{"a": "x", "b": "y"}'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> Patch\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>
Preserve<span class="token punctuation">:</span> [10, 20, {"a"<span class="token punctuation">:</span> "x", "b"<span class="token punctuation">:</span> "y"}]
Patch<span class="token punctuation">:</span> {"a"<span class="token punctuation">:</span> "x", "b"<span class="token punctuation">:</span> "y"}</span></code></pre>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-paths">
</a>
Searching and Modifying JSON Values
</h3>
</div>
</div>
</div>
<p>
A JSON path expression selects a value within a JSON document.
</p>
<p>
Path expressions are useful with functions that extract parts of
or modify a JSON document, to specify where within that document
to operate. For example, the following query extracts from a
JSON document the value of the member with the
<code class="literal">
name
</code>
key:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40792412"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span><span class="token string">'{"id": 14, "name": "Aztalan"}'</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 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> JSON_EXTRACT('{"id": 14, "name": "Aztalan"}', '$.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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> "Aztalan" <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></code></pre>
</div>
<p>
Path syntax uses a leading
<code class="literal">
$
</code>
character to
represent the JSON document under consideration, optionally
followed by selectors that indicate successively more specific
parts of the document:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
A period followed by a key name names the member in an
object with the given key. The key name must be specified
within double quotation marks if the name without quotes is
not legal within path expressions (for example, if it
contains a space).
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
[
<em class="replaceable">
<code>
N
</code>
</em>
]
</code>
appended
to a
<em class="replaceable">
<code>
path
</code>
</em>
that selects an array
names the value at position
<em class="replaceable">
<code>
N
</code>
</em>
within the array. Array positions are integers beginning
with zero. If
<em class="replaceable">
<code>
path
</code>
</em>
does not
select an array value,
<em class="replaceable">
<code>
path
</code>
</em>
[0]
evaluates to the same value as
<em class="replaceable">
<code>
path
</code>
</em>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14715258"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_SET</span><span class="token punctuation">(</span><span class="token string">'"x"'</span><span class="token punctuation">,</span> <span class="token string">'$[0]'</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 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>
<span class="token output"><span class="token punctuation">|</span> JSON_SET('"x"', '$[0]', 'a') <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>
<span class="token output"><span class="token punctuation">|</span> "a" <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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
[
<em class="replaceable">
<code>
M
</code>
</em>
to
<em class="replaceable">
<code>
N
</code>
</em>
]
</code>
specifies a subset
or range of array values starting with the value at position
<em class="replaceable">
<code>
M
</code>
</em>
, and ending with the value at
position
<em class="replaceable">
<code>
N
</code>
</em>
.
</p>
<p>
<code class="literal">
last
</code>
is supported as a synonym for the
index of the rightmost array element. Relative addressing of
array elements is also supported. If
<em class="replaceable">
<code>
path
</code>
</em>
does not select an array
value,
<em class="replaceable">
<code>
path
</code>
</em>
[last] evaluates to
the same value as
<em class="replaceable">
<code>
path
</code>
</em>
, as shown
later in this section (see
<a class="xref" href="json.html#json-paths-last" title="Rightmost array element">
Rightmost array element
</a>
).
</p>
</li>
<li class="listitem">
<p>
Paths can contain
<code class="literal">
*
</code>
or
<code class="literal">
**
</code>
wildcards:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
.[*]
</code>
evaluates to the values of all
members in a JSON object.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
[*]
</code>
evaluates to the values of all
elements in a JSON array.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
<em class="replaceable">
<code>
prefix
</code>
</em>
**
<em class="replaceable">
<code>
suffix
</code>
</em>
</code>
evaluates to all paths that begin with the named prefix
and end with the named suffix.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
A path that does not exist in the document (evaluates to
nonexistent data) evaluates to
<code class="literal">
NULL
</code>
.
</p>
</li>
</ul>
</div>
<p>
Let
<code class="literal">
$
</code>
refer to this JSON array with three
elements:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-json"><div class="docs-select-all right" id="sa67381214"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token property">"a"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"b"</span><span class="token operator">:</span> <span class="token number">10</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">99</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">]</span><span class="token punctuation">]</span></code></pre>
</div>
<p>
Then:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
$[0]
</code>
evaluates to
<code class="literal">
3
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$[1]
</code>
evaluates to
<code class="literal">
{"a": [5, 6],
"b": 10}
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$[2]
</code>
evaluates to
<code class="literal">
[99,
100]
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$[3]
</code>
evaluates to
<code class="literal">
NULL
</code>
(it refers to the fourth array element, which does not
exist).
</p>
</li>
</ul>
</div>
<p>
Because
<code class="literal">
$[1]
</code>
and
<code class="literal">
$[2]
</code>
evaluate to nonscalar values, they can be used as the basis for
more-specific path expressions that select nested values.
Examples:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
$[1].a
</code>
evaluates to
<code class="literal">
[5,
6]
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$[1].a[1]
</code>
evaluates to
<code class="literal">
6
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$[1].b
</code>
evaluates to
<code class="literal">
10
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$[2][0]
</code>
evaluates to
<code class="literal">
99
</code>
.
</p>
</li>
</ul>
</div>
<p>
As mentioned previously, path components that name keys must be
quoted if the unquoted key name is not legal in path
expressions. Let
<code class="literal">
$
</code>
refer to this value:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-json"><div class="docs-select-all right" id="sa14100894"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-json"><span class="token punctuation">{</span><span class="token property">"a fish"</span><span class="token operator">:</span> <span class="token string">"shark"</span><span class="token punctuation">,</span> <span class="token property">"a bird"</span><span class="token operator">:</span> <span class="token string">"sparrow"</span><span class="token punctuation">}</span></code></pre>
</div>
<p>
The keys both contain a space and must be quoted:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
$."a fish"
</code>
evaluates to
<code class="literal">
shark
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
$."a bird"
</code>
evaluates to
<code class="literal">
sparrow
</code>
.
</p>
</li>
</ul>
</div>
<p>
Paths that use wildcards evaluate to an array that can contain
multiple values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21049783"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span><span class="token string">'{"a": 1, "b": 2, "c": [3, 4, 5]}'</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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, 2, [3, 4, 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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span><span class="token string">'{"a": 1, "b": 2, "c": [3, 4, 5]}'</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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, 4, 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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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 the following example, the path
<code class="literal">
$**.b
</code>
evaluates to multiple paths (
<code class="literal">
$.a.b
</code>
and
<code class="literal">
$.c.b
</code>
) and produces an array of the matching
path values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42658586"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span><span class="token string">'{"a": {"b": 1}, "c": {"b": 2}}'</span><span class="token punctuation">,</span> <span class="token string">'$**.b'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_EXTRACT('{"a": {"b": 1}, "c": {"b": 2}}', '$**.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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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, 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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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 name="json-paths-ranges">
</a>
<b>
Ranges from JSON arrays.
</b>
You can use ranges with the
<code class="literal">
to
</code>
keyword to
specify subsets of JSON arrays. For example,
<code class="literal">
$[1 to
3]
</code>
includes the second, third, and fourth elements
of an array, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa71426916"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span><span class="token string">'[1, 2, 3, 4, 5]'</span><span class="token punctuation">,</span> <span class="token string">'$[1 to 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> JSON_EXTRACT('[1, 2, 3, 4, 5]', '$[1 to 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> [2, 3, 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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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 syntax is
<code class="literal">
<em class="replaceable">
<code>
M
</code>
</em>
to
<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, respectively, the first and last indexes of a range of
elements from a JSON array.
<em class="replaceable">
<code>
N
</code>
</em>
must be
greater than
<em class="replaceable">
<code>
M
</code>
</em>
;
<em class="replaceable">
<code>
M
</code>
</em>
must be greater than or equal to 0.
Array elements are indexed beginning with 0.
</p>
<p>
You can use ranges in contexts where wildcards are supported.
</p>
<p>
<a name="json-paths-last">
</a>
<b>
Rightmost array element.
</b>
The
<code class="literal">
last
</code>
keyword is supported as a synonym
for the index of the last element in an array. Expressions of
the form
<code class="literal">
last -
<em class="replaceable">
<code>
N
</code>
</em>
</code>
can be used for
relative addressing, and within range definitions, like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa20377254"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span><span class="token string">'[1, 2, 3, 4, 5]'</span><span class="token punctuation">,</span> <span class="token string">'$[last-3 to last-1]'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_EXTRACT('[1, 2, 3, 4, 5]', '$[last<span class="token punctuation">-</span>3 to last<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>
<span class="token output"><span class="token punctuation">|</span> [2, 3, 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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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.01 sec)</span></code></pre>
</div>
<p>
If the path is evaluated against a value that is not an array,
the result of the evaluation is the same as if the value had
been wrapped in a single-element array:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59248973"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_REPLACE</span><span class="token punctuation">(</span><span class="token string">'"Sakila"'</span><span class="token punctuation">,</span> <span class="token string">'$[last]'</span><span class="token punctuation">,</span> <span class="token number">10</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>
<span class="token output"><span class="token punctuation">|</span> JSON_REPLACE('"Sakila"', '$[last]', 10) <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>
<span class="token output"><span class="token punctuation">|</span> 10 <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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
You can use
<a class="link" href="json-search-functions.html#operator_json-column-path">
<code class="literal">
<em class="replaceable">
<code>
column
</code>
</em>
->
<em class="replaceable">
<code>
path
</code>
</em>
</code>
</a>
with a JSON column identifier and JSON path expression as a
synonym for
<a class="link" href="json-search-functions.html#function_json-extract">
<code class="literal">
JSON_EXTRACT(
<em class="replaceable">
<code>
column
</code>
</em>
,
<em class="replaceable">
<code>
path
</code>
</em>
)
</code>
</a>
. See
<a class="xref" href="json-search-functions.html" title="14.17.3 Functions That Search JSON Values">
Section 14.17.3, “Functions That Search JSON Values”
</a>
, for more information.
See also
<a class="xref" href="create-table-secondary-indexes.html#json-column-indirect-index" title="Indexing a Generated Column to Provide a JSON Column Index">
Indexing a Generated Column to Provide a JSON Column Index
</a>
.
</p>
<p>
Some functions take an existing JSON document, modify it in some
way, and return the resulting modified document. Path
expressions indicate where in the document to make changes. For
example, the
<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-insert">
<code class="literal">
JSON_INSERT()
</code>
</a>
, and
<a class="link" href="json-modification-functions.html#function_json-replace">
<code class="literal">
JSON_REPLACE()
</code>
</a>
functions each
take a JSON document, plus one or more path-value pairs that
describe where to modify the document and the values to use. The
functions differ in how they handle existing and nonexisting
values within the document.
</p>
<p>
Consider this document:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa47099315"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token variable">@j</span> <span class="token operator">=</span> <span class="token string">'["a", {"b": [true, false]}, [10, 20]]'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
<a class="link" href="json-modification-functions.html#function_json-set">
<code class="literal">
JSON_SET()
</code>
</a>
replaces values for
paths that exist and adds values for paths that do not exist:.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa19157409"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_SET</span><span class="token punctuation">(</span><span class="token variable">@j</span><span class="token punctuation">,</span> <span class="token string">'$[1].b[0]'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'$[2][2]'</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 class="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> JSON_SET(@j, '$[1].b[0]', 1, '$[2][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>
<span class="token output"><span class="token punctuation">|</span> ["a", {"b": [1, false]}, [10, 20, 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></code></pre>
</div>
<p>
In this case, the path
<code class="literal">
$[1].b[0]
</code>
selects an
existing value (
<code class="literal">
true
</code>
), which is replaced with
the value following the path argument (
<code class="literal">
1
</code>
).
The path
<code class="literal">
$[2][2]
</code>
does not exist, so the
corresponding value (
<code class="literal">
2
</code>
) is added to the value
selected by
<code class="literal">
$[2]
</code>
.
</p>
<p>
<a class="link" href="json-modification-functions.html#function_json-insert">
<code class="literal">
JSON_INSERT()
</code>
</a>
adds new values but
does not replace existing values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53410349"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_INSERT</span><span class="token punctuation">(</span><span class="token variable">@j</span><span class="token punctuation">,</span> <span class="token string">'$[1].b[0]'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'$[2][2]'</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> JSON_INSERT(@j, '$[1].b[0]', 1, '$[2][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 class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ["a", {"b": [true, false]}, [10, 20, 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 class="token punctuation">+</span></span></code></pre>
</div>
<p>
<a class="link" href="json-modification-functions.html#function_json-replace">
<code class="literal">
JSON_REPLACE()
</code>
</a>
replaces existing
values and ignores new values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17668207"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_REPLACE</span><span class="token punctuation">(</span><span class="token variable">@j</span><span class="token punctuation">,</span> <span class="token string">'$[1].b[0]'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'$[2][2]'</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> JSON_REPLACE(@j, '$[1].b[0]', 1, '$[2][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 class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ["a", {"b": [1, false]}, [10, 20]] <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>
<p>
The path-value pairs are evaluated left to right. The document
produced by evaluating one pair becomes the new value against
which the next pair is evaluated.
</p>
<p>
<code class="literal">
JSON_REMOVE()
</code>
takes a JSON document and one
or more paths that specify values to be removed from the
document. The return value is the original document minus the
values selected by paths that exist within the document:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32757688"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">JSON_REMOVE</span><span class="token punctuation">(</span><span class="token variable">@j</span><span class="token punctuation">,</span> <span class="token string">'$[2]'</span><span class="token punctuation">,</span> <span class="token string">'$[1].b[1]'</span><span class="token punctuation">,</span> <span class="token string">'$[1].b[1]'</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>
<span class="token output"><span class="token punctuation">|</span> JSON_REMOVE(@j, '$[2]', '$[1].b[1]', '$[1].b[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>
<span class="token output"><span class="token punctuation">|</span> ["a", {"b": [true]}] <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>
The paths have these effects:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
$[2]
</code>
matches
<code class="literal">
[10, 20]
</code>
and removes it.
</p>
</li>
<li class="listitem">
<p>
The first instance of
<code class="literal">
$[1].b[1]
</code>
matches
<code class="literal">
false
</code>
in the
<code class="literal">
b
</code>
element
and removes it.
</p>
</li>
<li class="listitem">
<p>
The second instance of
<code class="literal">
$[1].b[1]
</code>
matches
nothing: That element has already been removed, the path no
longer exists, and has no effect.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-path-syntax">
</a>
JSON Path Syntax
</h3>
</div>
</div>
</div>
<p>
Many of the JSON functions supported by MySQL and described
elsewhere in this Manual (see
<a class="xref" href="json-functions.html" title="14.17 JSON Functions">
Section 14.17, “JSON Functions”
</a>
)
require a path expression in order to identify a specific
element in a JSON document. A path consists of the path's
scope followed by one or more path legs. For paths used in MySQL
JSON functions, the scope is always the document being searched
or otherwise operated on, represented by a leading
<code class="literal">
$
</code>
character. Path legs are separated by
period characters (
<code class="literal">
.
</code>
). Cells in arrays are
represented by
<code class="literal">
[
<em class="replaceable">
<code>
N
</code>
</em>
]
</code>
, where
<em class="replaceable">
<code>
N
</code>
</em>
is a non-negative integer. Names of
keys must be double-quoted strings or valid ECMAScript
identifiers (see
<a class="ulink" href="http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" target="_blank">
<em class="citetitle">
Identifier
Names and Identifiers
</em>
</a>
, in the
<em class="citetitle">
ECMAScript Language Specification
</em>
). Path
expressions, like JSON text, should be encoded using the
<code class="literal">
ascii
</code>
,
<code class="literal">
utf8mb3
</code>
, or
<code class="literal">
utf8mb4
</code>
character set. Other character
encodings are implicitly coerced to
<code class="literal">
utf8mb4
</code>
.
The complete syntax is shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-clike"><div class="docs-select-all right" id="sa97235376"><div class="copy-help left">Press ⌘+C to 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"><em class="replaceable">pathExpression</em><span class="token punctuation">:</span>
<em class="replaceable">scope</em><span class="token punctuation">[</span><span class="token punctuation">(</span><em class="replaceable">pathLeg</em><span class="token punctuation">)</span><span class="token operator">*</span><span class="token punctuation">]</span>
<em class="replaceable">pathLeg</em><span class="token punctuation">:</span>
<em class="replaceable">member</em> <span class="token operator">|</span> <em class="replaceable">arrayLocation</em> <span class="token operator">|</span> <em class="replaceable">doubleAsterisk</em>
<em class="replaceable">member</em><span class="token punctuation">:</span>
<em class="replaceable">period</em> <span class="token punctuation">(</span> <em class="replaceable">keyName</em> <span class="token operator">|</span> <em class="replaceable">asterisk</em> <span class="token punctuation">)</span>
<em class="replaceable">arrayLocation</em><span class="token punctuation">:</span>
<em class="replaceable">leftBracket</em> <span class="token punctuation">(</span> <em class="replaceable">nonNegativeInteger</em> <span class="token operator">|</span> <em class="replaceable">asterisk</em> <span class="token punctuation">)</span> <em class="replaceable">rightBracket</em>
<em class="replaceable">keyName</em><span class="token punctuation">:</span>
<em class="replaceable">ESIdentifier</em> <span class="token operator">|</span> <em class="replaceable">doubleQuotedString</em>
<em class="replaceable">doubleAsterisk</em><span class="token punctuation">:</span>
<span class="token string">'**'</span>
<em class="replaceable">period</em><span class="token punctuation">:</span>
<span class="token string">'.'</span>
<em class="replaceable">asterisk</em><span class="token punctuation">:</span>
<span class="token string">'*'</span>
<em class="replaceable">leftBracket</em><span class="token punctuation">:</span>
<span class="token string">'['</span>
<em class="replaceable">rightBracket</em><span class="token punctuation">:</span>
<span class="token string">']'</span></code></pre>
</div>
<p>
As noted previously, in MySQL, the scope of the path is always
the document being operated on, represented as
<code class="literal">
$
</code>
. You can use
<code class="literal">
'$'
</code>
as a
synonym for the document in JSON path expressions.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
Some implementations support column references for scopes of
JSON paths; MySQL 8.4 does not support these.
</p>
</div>
<p>
The wildcard
<code class="literal">
*
</code>
and
<code class="literal">
**
</code>
tokens are used as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
.*
</code>
represents the values of all members
in the object.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
[*]
</code>
represents the values of all cells in
the array.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
[
<em class="replaceable">
<code>
prefix
</code>
</em>
]**
<em class="replaceable">
<code>
suffix
</code>
</em>
</code>
represents all paths beginning with
<em class="replaceable">
<code>
prefix
</code>
</em>
and ending with
<em class="replaceable">
<code>
suffix
</code>
</em>
.
<em class="replaceable">
<code>
prefix
</code>
</em>
is optional, while
<em class="replaceable">
<code>
suffix
</code>
</em>
is required; in other
words, a path may not end in
<code class="literal">
**
</code>
.
</p>
<p>
In addition, a path may not contain the sequence
<code class="literal">
***
</code>
.
</p>
</li>
</ul>
</div>
<p>
For path syntax examples, see the descriptions of the various
JSON functions that take paths as arguments, such as
<a class="link" href="json-search-functions.html#function_json-contains-path">
<code class="literal">
JSON_CONTAINS_PATH()
</code>
</a>
,
<a class="link" href="json-modification-functions.html#function_json-set">
<code class="literal">
JSON_SET()
</code>
</a>
, and
<a class="link" href="json-modification-functions.html#function_json-replace">
<code class="literal">
JSON_REPLACE()
</code>
</a>
. For examples
which include the use of the
<code class="literal">
*
</code>
and
<code class="literal">
**
</code>
wildcards, see the description of the
<a class="link" href="json-search-functions.html#function_json-search">
<code class="literal">
JSON_SEARCH()
</code>
</a>
function.
</p>
<p>
MySQL also supports range notation for subsets of JSON arrays
using the
<code class="literal">
to
</code>
keyword (such as
<code class="literal">
$[2 to
10]
</code>
), as well as the
<code class="literal">
last
</code>
keyword
as a synonym for the rightmost element of an array. See
<a class="xref" href="json.html#json-paths" title="Searching and Modifying JSON Values">
Searching and Modifying JSON Values
</a>
, for more information and examples.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-comparison">
</a>
Comparison and Ordering of JSON Values
</h3>
</div>
</div>
</div>
<p>
JSON values can be compared using the
<a class="link" href="comparison-operators.html#operator_equal">
<code class="literal">
=
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_less-than">
<code class="literal">
<
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_less-than-or-equal">
<code class="literal">
<=
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_greater-than">
<code class="literal">
>
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_greater-than-or-equal">
<code class="literal">
>=
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_not-equal">
<code class="literal">
<>
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_not-equal">
<code class="literal">
!=
</code>
</a>
, and
<a class="link" href="comparison-operators.html#operator_equal-to">
<code class="literal">
<=>
</code>
</a>
operators.
</p>
<p>
The following comparison operators and functions are not yet
supported with JSON values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="comparison-operators.html#operator_between">
<code class="literal">
BETWEEN
</code>
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="comparison-operators.html#operator_in">
<code class="literal">
IN()
</code>
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="comparison-operators.html#function_greatest">
<code class="literal">
GREATEST()
</code>
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="comparison-operators.html#function_least">
<code class="literal">
LEAST()
</code>
</a>
</p>
</li>
</ul>
</div>
<p>
A workaround for the comparison operators and functions just
listed is to cast JSON values to a native MySQL numeric or
string data type so they have a consistent non-JSON scalar type.
</p>
<p>
Comparison of JSON values takes place at two levels. The first
level of comparison is based on the JSON types of the compared
values. If the types differ, the comparison result is determined
solely by which type has higher precedence. If the two values
have the same JSON type, a second level of comparison occurs
using type-specific rules.
</p>
<p>
The following list shows the precedences of JSON types, from
highest precedence to the lowest. (The type names are those
returned by the
<a class="link" href="json-attribute-functions.html#function_json-type">
<code class="literal">
JSON_TYPE()
</code>
</a>
function.) Types shown together on a line have the same
precedence. Any value having a JSON type listed earlier in the
list compares greater than any value having a JSON type listed
later in the list.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa61545935"><div class="copy-help left">Press ⌘+C to 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">BLOB
BIT
OPAQUE
DATETIME
TIME
DATE
BOOLEAN
ARRAY
OBJECT
STRING
INTEGER<span class="token punctuation">,</span> DOUBLE
NULL</code></pre>
</div>
<p>
For JSON values of the same precedence, the comparison rules are
type specific:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
BLOB
</code>
</p>
<p>
The first
<em class="replaceable">
<code>
N
</code>
</em>
bytes of the two
values are compared, where
<em class="replaceable">
<code>
N
</code>
</em>
is
the number of bytes in the shorter value. If the first
<em class="replaceable">
<code>
N
</code>
</em>
bytes of the two values are
identical, the shorter value is ordered before the longer
value.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
BIT
</code>
</p>
<p>
Same rules as for
<code class="literal">
BLOB
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
OPAQUE
</code>
</p>
<p>
Same rules as for
<code class="literal">
BLOB
</code>
.
<code class="literal">
OPAQUE
</code>
values are values that are not
classified as one of the other types.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
DATETIME
</code>
</p>
<p>
A value that represents an earlier point in time is ordered
before a value that represents a later point in time. If two
values originally come from the MySQL
<code class="literal">
DATETIME
</code>
and
<code class="literal">
TIMESTAMP
</code>
types, respectively, they are equal if they represent the
same point in time.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
TIME
</code>
</p>
<p>
The smaller of two time values is ordered before the larger
one.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
DATE
</code>
</p>
<p>
The earlier date is ordered before the more recent date.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
ARRAY
</code>
</p>
<p>
Two JSON arrays are equal if they have the same length and
values in corresponding positions in the arrays are equal.
</p>
<p>
If the arrays are not equal, their order is determined by
the elements in the first position where there is a
difference. The array with the smaller value in that
position is ordered first. If all values of the shorter
array are equal to the corresponding values in the longer
array, the shorter array is ordered first.
</p>
<p>
Example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa31843701"><div class="copy-help left">Press ⌘+C to 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> <span class="token operator"><</span> <span class="token punctuation">[</span>"a"<span class="token punctuation">]</span> <span class="token operator"><</span> <span class="token punctuation">[</span>"ab"<span class="token punctuation">]</span> <span class="token operator"><</span> <span class="token punctuation">[</span>"ab"<span class="token punctuation">,</span> "cd"<span class="token punctuation">,</span> "ef"<span class="token punctuation">]</span> <span class="token operator"><</span> <span class="token punctuation">[</span>"ab"<span class="token punctuation">,</span> "ef"<span class="token punctuation">]</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
BOOLEAN
</code>
</p>
<p>
The JSON false literal is less than the JSON true literal.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
OBJECT
</code>
</p>
<p>
Two JSON objects are equal if they have the same set of
keys, and each key has the same value in both objects.
</p>
<p>
Example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa36024542"><div class="copy-help left">Press ⌘+C to 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>"a"<span class="token operator">:</span> 1<span class="token punctuation">,</span> "b"<span class="token operator">:</span> 2<span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token punctuation">{</span>"b"<span class="token operator">:</span> 2<span class="token punctuation">,</span> "a"<span class="token operator">:</span> 1<span class="token punctuation">}</span></code></pre>
</div>
<p>
The order of two objects that are not equal is unspecified
but deterministic.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
STRING
</code>
</p>
<p>
Strings are ordered lexically on the first
<em class="replaceable">
<code>
N
</code>
</em>
bytes of the
<code class="literal">
utf8mb4
</code>
representation of the two strings
being compared, where
<em class="replaceable">
<code>
N
</code>
</em>
is the
length of the shorter string. If the first
<em class="replaceable">
<code>
N
</code>
</em>
bytes of the two strings are
identical, the shorter string is considered smaller than the
longer string.
</p>
<p>
Example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa24660352"><div class="copy-help left">Press ⌘+C to 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">"a" <span class="token operator"><</span> "ab" <span class="token operator"><</span> "b" <span class="token operator"><</span> "bc"</code></pre>
</div>
<p>
This ordering is equivalent to the ordering of SQL strings
with collation
<code class="literal">
utf8mb4_bin
</code>
. Because
<code class="literal">
utf8mb4_bin
</code>
is a binary collation,
comparison of JSON values is case-sensitive:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa22557406"><div class="copy-help left">Press ⌘+C to 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">"A" <span class="token operator"><</span> "a"</code></pre>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
INTEGER
</code>
,
<code class="literal">
DOUBLE
</code>
</p>
<p>
JSON values can contain exact-value numbers and
approximate-value numbers. For a general discussion of these
types of numbers, see
<a class="xref" href="number-literals.html" title="11.1.2 Numeric Literals">
Section 11.1.2, “Numeric Literals”
</a>
.
</p>
<p>
The rules for comparing native MySQL numeric types are
discussed in
<a class="xref" href="type-conversion.html" title="14.3 Type Conversion in Expression Evaluation">
Section 14.3, “Type Conversion in Expression Evaluation”
</a>
, but the
rules for comparing numbers within JSON values differ
somewhat:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
In a comparison between two columns that use the native
MySQL
<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>
and
<a class="link" href="floating-point-types.html" title="13.1.4 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE">
<code class="literal">
DOUBLE
</code>
</a>
numeric types,
respectively, it is known that all comparisons involve
an integer and a double, so the integer is converted to
double for all rows. That is, exact-value numbers are
converted to approximate-value numbers.
</p>
</li>
<li class="listitem">
<p>
On the other hand, if the query compares two JSON
columns containing numbers, it cannot be known in
advance whether numbers are integer or double. To
provide the most consistent behavior across all rows,
MySQL converts approximate-value numbers to exact-value
numbers. The resulting ordering is consistent and does
not lose precision for the exact-value numbers. For
example, given the scalars 9223372036854775805,
9223372036854775806, 9223372036854775807 and
9.223372036854776e18, the order is such as this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65680751"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token number">9223372036854775805</span> <span class="token operator"><</span> <span class="token number">9223372036854775806</span> <span class="token operator"><</span> <span class="token number">9223372036854775807</span>
<span class="token operator"><</span> <span class="token number">9.223372036854776e18</span> <span class="token operator">=</span> <span class="token number">9223372036854776000</span> <span class="token operator"><</span> <span class="token number">9223372036854776001</span></code></pre>
</div>
</li>
</ul>
</div>
<p>
Were JSON comparisons to use the non-JSON numeric comparison
rules, inconsistent ordering could occur. The usual MySQL
comparison rules for numbers yield these orderings:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
Integer comparison:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa14710781"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token number">9223372036854775805</span> <span class="token operator"><</span> <span class="token number">9223372036854775806</span> <span class="token operator"><</span> <span class="token number">9223372036854775807</span></code></pre>
</div>
<p>
(not defined for 9.223372036854776e18)
</p>
</li>
<li class="listitem">
<p>
Double comparison:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa36601697"><div class="copy-help left">Press ⌘+C to 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">9223372036854775805 <span class="token operator">=</span> 9223372036854775806 <span class="token operator">=</span> 9223372036854775807 <span class="token operator">=</span> 9<span class="token punctuation">.</span>223372036854776e18</code></pre>
</div>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>
For comparison of any JSON value to SQL
<code class="literal">
NULL
</code>
,
the result is
<code class="literal">
UNKNOWN
</code>
.
</p>
<p>
For comparison of JSON and non-JSON values, the non-JSON value
is converted to JSON according to the rules in the following
table, then the values compared as described previously.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-converting-between-types">
</a>
Converting between JSON and non-JSON values
</h3>
</div>
</div>
</div>
<p>
The following table provides a summary of the rules that MySQL
follows when casting between JSON values and values of other
types:
</p>
<div class="oracle-all">
<a name="json-conversion-rules">
</a>
<p class="title">
<b>
Table 13.3 JSON Conversion Rules
</b>
</p>
<div class="oracle-all-contents">
<table summary="Conversion rules for the JSON data type">
<colgroup>
<col style="width: 20%"/>
<col style="width: 40%"/>
<col style="width: 40%"/>
</colgroup>
<thead>
<tr>
<th scope="col">
other type
</th>
<th scope="col">
CAST(other type AS JSON)
</th>
<th scope="col">
CAST(JSON AS other type)
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
JSON
</th>
<td>
No change
</td>
<td>
No change
</td>
</tr>
<tr>
<th scope="row">
utf8 character type (
<code class="literal">
utf8mb4
</code>
,
<code class="literal">
utf8mb3
</code>
,
<code class="literal">
ascii
</code>
)
</th>
<td>
The string is parsed into a JSON value.
</td>
<td>
The JSON value is serialized into a
<code class="literal">
utf8mb4
</code>
string.
</td>
</tr>
<tr>
<th scope="row">
Other character types
</th>
<td>
Other character encodings are implicitly converted to
<code class="literal">
utf8mb4
</code>
and treated as described for
this character type.
</td>
<td>
The JSON value is serialized into a
<code class="literal">
utf8mb4
</code>
string,
then cast to the other character encoding. The result may
not be meaningful.
</td>
</tr>
<tr>
<th scope="row">
<code class="literal">
NULL
</code>
</th>
<td>
Results in a
<code class="literal">
NULL
</code>
value of type JSON.
</td>
<td>
Not applicable.
</td>
</tr>
<tr>
<th scope="row">
Geometry types
</th>
<td>
The geometry value is converted into a JSON document by calling
<a class="link" href="spatial-geojson-functions.html#function_st-asgeojson">
<code class="literal">
ST_AsGeoJSON()
</code>
</a>
.
</td>
<td>
Illegal operation. Workaround: Pass the result of
<a class="link" href="cast-functions.html#function_cast">
<code class="literal">
CAST(
<em class="replaceable">
<code>
json_val
</code>
</em>
AS CHAR)
</code>
</a>
to
<a class="link" href="spatial-geojson-functions.html#function_st-geomfromgeojson">
<code class="literal">
ST_GeomFromGeoJSON()
</code>
</a>
.
</td>
</tr>
<tr>
<th scope="row">
All other types
</th>
<td>
Results in a JSON document consisting of a single scalar value.
</td>
<td>
Succeeds if the JSON document consists of a single scalar value of the
target type and that scalar value can be cast to the
target type. Otherwise, returns
<code class="literal">
NULL
</code>
and produces a warning.
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="oracle-all-break"/>
<p>
<code class="literal">
ORDER BY
</code>
and
<code class="literal">
GROUP BY
</code>
for
JSON values works according to these principles:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Ordering of scalar JSON values uses the same rules as in the
preceding discussion.
</p>
</li>
<li class="listitem">
<p>
For ascending sorts, SQL
<code class="literal">
NULL
</code>
orders
before all JSON values, including the JSON null literal; for
descending sorts, SQL
<code class="literal">
NULL
</code>
orders after
all JSON values, including the JSON null literal.
</p>
</li>
<li class="listitem">
<p>
Sort keys for JSON values are bound by the value of the
<a class="link" href="server-system-variables.html#sysvar_max_sort_length">
<code class="literal">
max_sort_length
</code>
</a>
system
variable, so keys that differ only after the first
<a class="link" href="server-system-variables.html#sysvar_max_sort_length">
<code class="literal">
max_sort_length
</code>
</a>
bytes
compare as equal.
</p>
</li>
<li class="listitem">
<p>
Sorting of nonscalar values is not currently supported and a
warning occurs.
</p>
</li>
</ul>
</div>
<p>
For sorting, it can be beneficial to cast a JSON scalar to some
other native MySQL type. For example, if a column named
<code class="literal">
jdoc
</code>
contains JSON objects having a member
consisting of an
<code class="literal">
id
</code>
key and a nonnegative
value, use this expression to sort by
<code class="literal">
id
</code>
values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa25768355"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">ORDER</span> <span class="token keyword">BY</span> <span class="token function">CAST</span><span class="token punctuation">(</span><span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span>jdoc<span class="token punctuation">,</span> <span class="token string">'$.id'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">UNSIGNED</span><span class="token punctuation">)</span></code></pre>
</div>
<p>
If there happens to be a generated column defined to use the
same expression as in the
<code class="literal">
ORDER BY
</code>
, the MySQL
optimizer recognizes that and considers using the index for the
query execution plan. See
<a class="xref" href="generated-column-index-optimizations.html" title="10.3.11 Optimizer Use of Generated Column Indexes">
Section 10.3.11, “Optimizer Use of Generated Column Indexes”
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h3 class="title">
<a name="json-aggregation">
</a>
Aggregation of JSON Values
</h3>
</div>
</div>
</div>
<p>
For aggregation of JSON values, SQL
<code class="literal">
NULL
</code>
values are ignored as for other data types.
Non-
<code class="literal">
NULL
</code>
values are converted to a numeric
type and aggregated, except for
<a class="link" href="aggregate-functions.html#function_min">
<code class="literal">
MIN()
</code>
</a>
,
<a class="link" href="aggregate-functions.html#function_max">
<code class="literal">
MAX()
</code>
</a>
, and
<a class="link" href="aggregate-functions.html#function_group-concat">
<code class="literal">
GROUP_CONCAT()
</code>
</a>
. The conversion to
number should produce a meaningful result for JSON values that
are numeric scalars, although (depending on the values)
truncation and loss of precision may occur. Conversion to number
of other JSON values may not produce a meaningful result.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/information-schema-optimizer-trace-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="information-schema-optimizer-trace-table">
</a>
28.3.19 The INFORMATION_SCHEMA OPTIMIZER_TRACE Table
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045079462448">
</a>
<p>
The
<a class="link" href="information-schema-optimizer-trace-table.html" title="28.3.19 The INFORMATION_SCHEMA OPTIMIZER_TRACE Table">
<code class="literal">
OPTIMIZER_TRACE
</code>
</a>
table provides
information produced by the optimizer tracing capability for
traced statements. To enable tracking, use the
<a class="link" href="server-system-variables.html#sysvar_optimizer_trace">
<code class="literal">
optimizer_trace
</code>
</a>
system variable.
For details, see
<a class="xref" href="optimizer-tracing.html" title="10.15 Tracing the Optimizer">
Section 10.15, “Tracing the Optimizer”
</a>
.
</p>
<p>
The
<a class="link" href="information-schema-optimizer-trace-table.html" title="28.3.19 The INFORMATION_SCHEMA OPTIMIZER_TRACE Table">
<code class="literal">
OPTIMIZER_TRACE
</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">
QUERY
</code>
</p>
<p>
The text of the traced statement.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
TRACE
</code>
</p>
<p>
The trace, in
<code class="literal">
JSON
</code>
format.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MISSING_BYTES_BEYOND_MAX_MEM_SIZE
</code>
</p>
<p>
Each remembered trace is a string that is extended as
optimization progresses and appends data to it. The
<a class="link" href="server-system-variables.html#sysvar_optimizer_trace_max_mem_size">
<code class="literal">
optimizer_trace_max_mem_size
</code>
</a>
variable sets a limit on the total amount of memory used by
all currently remembered traces. If this limit is reached, the
current trace is not extended (and thus is incomplete), and
the
<code class="literal">
MISSING_BYTES_BEYOND_MAX_MEM_SIZE
</code>
column shows the number of bytes missing from the trace.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
INSUFFICIENT_PRIVILEGES
</code>
</p>
<p>
If a traced query uses views or stored routines that have
<code class="literal">
SQL SECURITY
</code>
with a value of
<code class="literal">
DEFINER
</code>
, it may be that a user other than
the definer is denied from seeing the trace of the query. In
that case, the trace is shown as empty and
<code class="literal">
INSUFFICIENT_PRIVILEGES
</code>
has a value of 1.
Otherwise, the value is 0.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-shell-tutorial-python-relational-tables.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="mysql-shell-tutorial-python-relational-tables">
</a>
22.4.4 Relational Tables
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="mysql-shell-tutorial-python-table-insert.html">
22.4.4.1 Insert Records into Tables
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-shell-tutorial-python-table-select.html">
22.4.4.2 Select Tables
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-shell-tutorial-python-table-update.html">
22.4.4.3 Update Tables
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-shell-tutorial-python-table-delete.html">
22.4.4.4 Delete Tables
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045126946816">
</a>
<p>
You can also use X DevAPI to work with relational tables. In
MySQL, each relational table is associated with a particular
storage engine. The examples in this section use
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
tables in the
<code class="literal">
world_x
</code>
schema.
</p>
<h4>
<a name="idm46045126942768">
</a>
Confirm the Schema
</h4>
<p>
To show the schema that is assigned to the
<code class="literal">
db
</code>
global variable, issue
<code class="literal">
db
</code>
.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa80445704"><div class="copy-help left">Press ⌘+C to 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-py></span> db
<span class="token operator"><</span>Schema<span class="token punctuation">:</span>world_x<span class="token operator">></span></code></pre>
</div>
<p>
If the returned value is not
<code class="literal">
Schema:world_x
</code>
,
set the
<code class="literal">
db
</code>
variable as follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa33268964"><div class="copy-help left">Press ⌘+C to 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-py></span> \use world_x
Schema <span class="token template-string"><span class="token string">`world_x`</span></span> accessible through db<span class="token punctuation">.</span></code></pre>
</div>
<h4>
<a name="idm46045126935072">
</a>
Show All Tables
</h4>
<p>
To display all relational tables in the
<code class="literal">
world_x
</code>
schema, use the
<code class="literal">
get_tables()
</code>
method on the
<code class="literal">
db
</code>
object.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa22679206"><div class="copy-help left">Press ⌘+C to 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-py></span> db<span class="token punctuation">.</span><span class="token function">get_tables</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">[</span>
<span class="token operator"><</span>Table<span class="token punctuation">:</span>city<span class="token operator">></span><span class="token punctuation">,</span>
<span class="token operator"><</span>Table<span class="token punctuation">:</span>country<span class="token operator">></span><span class="token punctuation">,</span>
<span class="token operator"><</span>Table<span class="token punctuation">:</span>countrylanguage<span class="token operator">></span>
<span class="token punctuation">]</span></code></pre>
</div>
<h4>
<a name="idm46045126929984">
</a>
Basic Table Operations
</h4>
<p>
Basic operations scoped by tables include:
</p>
<div class="informaltable">
<table summary="CRUD operations to use interactively on tables within MySQL Shell">
<colgroup>
<col style="width: 32%"/>
<col style="width: 68%"/>
</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>
.insert()
</code>
</td>
<td>
The
<a class="link" href="mysql-shell-tutorial-python-table-insert.html" title="22.4.4.1 Insert Records into Tables">
insert()
</a>
method inserts one or more records into the named table.
</td>
</tr>
<tr>
<td>
<code class="literal">
db.
<em class="replaceable">
<code>
name
</code>
</em>
.select()
</code>
</td>
<td>
The
<a class="link" href="mysql-shell-tutorial-python-table-select.html" title="22.4.4.2 Select Tables">
select()
</a>
method returns some or all records in the named table.
</td>
</tr>
<tr>
<td>
<code class="literal">
db.
<em class="replaceable">
<code>
name
</code>
</em>
.update()
</code>
</td>
<td>
The
<a class="link" href="mysql-shell-tutorial-python-table-update.html" title="22.4.4.3 Update Tables">
update()
</a>
method updates records in the named table.
</td>
</tr>
<tr>
<td>
<code class="literal">
db.
<em class="replaceable">
<code>
name
</code>
</em>
.delete()
</code>
</td>
<td>
The
<a class="link" href="mysql-shell-tutorial-python-table-delete.html" title="22.4.4.4 Delete Tables">
delete()
</a>
method deletes one or more records from the named table.
</td>
</tr>
</tbody>
</table>
</div>
<h4>
<a name="idm46045126907296">
</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-relational-tables.html" target="_top">
Working with Relational Tables
</a>
for more information.
</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>
<li class="listitem">
<p>
See
<a class="xref" href="mysql-shell-tutorial-python-download.html" title="22.4.2 Download and Import world_x Database">
Section 22.4.2, “Download and Import world_x Database”
</a>
for
instructions on setting up the
<code class="literal">
world_x
</code>
schema sample.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/gis-geometry-class-hierarchy.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="gis-geometry-class-hierarchy">
</a>
13.4.2.1 The Geometry Class Hierarchy
</h4>
</div>
</div>
</div>
<p>
The geometry classes define a hierarchy as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
Geometry
</code>
(noninstantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
Point
</code>
(instantiable)
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Curve
</code>
(noninstantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
<code class="literal">
LineString
</code>
(instantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
Line
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
LinearRing
</code>
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
Surface
</code>
(noninstantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
<code class="literal">
Polygon
</code>
(instantiable)
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
GeometryCollection
</code>
(instantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
<code class="literal">
MultiPoint
</code>
(instantiable)
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MultiCurve
</code>
(noninstantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
MultiLineString
</code>
(instantiable)
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
MultiSurface
</code>
(noninstantiable)
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
MultiPolygon
</code>
(instantiable)
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>
It is not possible to create objects in noninstantiable
classes. It is possible to create objects in instantiable
classes. All classes have properties, and instantiable classes
may also have assertions (rules that define valid class
instances).
</p>
<p>
<code class="literal">
Geometry
</code>
is the base class. It is an
abstract class. The instantiable subclasses of
<code class="literal">
Geometry
</code>
are restricted to zero-, one-, and
two-dimensional geometric objects that exist in
two-dimensional coordinate space. All instantiable geometry
classes are defined so that valid instances of a geometry
class are topologically closed (that is, all defined
geometries include their boundary).
</p>
<p>
The base
<code class="literal">
Geometry
</code>
class has subclasses for
<code class="literal">
Point
</code>
,
<code class="literal">
Curve
</code>
,
<code class="literal">
Surface
</code>
, and
<code class="literal">
GeometryCollection
</code>
:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
Point
</code>
represents zero-dimensional
objects.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Curve
</code>
represents one-dimensional
objects, and has subclass
<code class="literal">
LineString
</code>
,
with sub-subclasses
<code class="literal">
Line
</code>
and
<code class="literal">
LinearRing
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Surface
</code>
is designed for two-dimensional
objects and has subclass
<code class="literal">
Polygon
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
GeometryCollection
</code>
has specialized
zero-, one-, and two-dimensional collection classes named
<code class="literal">
MultiPoint
</code>
,
<code class="literal">
MultiLineString
</code>
, and
<code class="literal">
MultiPolygon
</code>
for modeling geometries
corresponding to collections of
<code class="literal">
Points
</code>
,
<code class="literal">
LineStrings
</code>
, and
<code class="literal">
Polygons
</code>
, respectively.
<code class="literal">
MultiCurve
</code>
and
<code class="literal">
MultiSurface
</code>
are introduced as abstract
superclasses that generalize the collection interfaces to
handle
<code class="literal">
Curves
</code>
and
<code class="literal">
Surfaces
</code>
.
</p>
</li>
</ul>
</div>
<p>
<code class="literal">
Geometry
</code>
,
<code class="literal">
Curve
</code>
,
<code class="literal">
Surface
</code>
,
<code class="literal">
MultiCurve
</code>
, and
<code class="literal">
MultiSurface
</code>
are defined as noninstantiable
classes. They define a common set of methods for their
subclasses and are included for extensibility.
</p>
<p>
<code class="literal">
Point
</code>
,
<code class="literal">
LineString
</code>
,
<code class="literal">
Polygon
</code>
,
<code class="literal">
GeometryCollection
</code>
,
<code class="literal">
MultiPoint
</code>
,
<code class="literal">
MultiLineString
</code>
, and
<code class="literal">
MultiPolygon
</code>
are instantiable classes.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/string-type-syntax.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="string-type-syntax">
</a>
13.3.1 String Data Type Syntax
</h3>
</div>
</div>
</div>
<p>
The string data types are
<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="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>
,
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
,
<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>
.
</p>
<p>
In some cases, MySQL may change a string column to a type
different from that 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. See
<a class="xref" href="silent-column-changes.html" title="15.1.20.7 Silent Column Specification Changes">
Section 15.1.20.7, “Silent Column Specification Changes”
</a>
.
</p>
<p>
For definitions of character string 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>
, and the
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
types), MySQL interprets
length specifications in character units. For definitions of
binary string columns (
<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>
, and the
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
types), MySQL interprets
length specifications in byte units.
</p>
<p>
Column definitions for character string data types
<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>
, the
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
types,
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
,
<a class="link" href="set.html" title="13.3.6 The SET Type">
<code class="literal">
SET
</code>
</a>
, and any synonyms) can
specify the column character set and collation:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
CHARACTER SET
</code>
specifies the character
set. If desired, a collation for the character set can be
specified with the
<code class="literal">
COLLATE
</code>
attribute,
along with any other attributes. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53770851"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">20</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">,</span>
c2 <span class="token datatype">TEXT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> latin1 <span class="token keyword">COLLATE</span> latin1_general_cs
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
This table definition creates a column named
<code class="literal">
c1
</code>
that has a character set of
<code class="literal">
utf8mb4
</code>
with the default collation for
that character set, and a column named
<code class="literal">
c2
</code>
that has a character set of
<code class="literal">
latin1
</code>
and a
case-sensitive (
<code class="literal">
_cs
</code>
) collation.
</p>
<p>
The rules for assigning the character set and collation when
either or both of
<code class="literal">
CHARACTER SET
</code>
and the
<code class="literal">
COLLATE
</code>
attribute are missing are
described in
<a class="xref" href="charset-column.html" title="12.3.5 Column Character Set and Collation">
Section 12.3.5, “Column Character Set and Collation”
</a>
.
</p>
<p>
<code class="literal">
CHARSET
</code>
is a synonym for
<code class="literal">
CHARACTER SET
</code>
.
</p>
</li>
<li class="listitem">
<p>
Specifying the
<code class="literal">
CHARACTER SET binary
</code>
attribute for a character string data type causes the column
to be created as the corresponding binary string 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="sa57794921"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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="sa34965996"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
<li class="listitem">
<p>
The
<code class="literal">
BINARY
</code>
attribute is a nonstandard
MySQL extension that is shorthand for specifying the binary
(
<code class="literal">
_bin
</code>
) collation of the column character
set (or of the table default character set if no column
character set is specified). In this case, comparison and
sorting are based on numeric character code values. 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="sa349675"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> latin1 <span class="token datatype">BINARY</span><span class="token punctuation">,</span>
c2 <span class="token datatype">TEXT</span> <span class="token datatype">BINARY</span>
<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>
The resulting table has this definition:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14419717"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> latin1 <span class="token keyword">COLLATE</span> latin1_bin<span class="token punctuation">,</span>
c2 <span class="token datatype">TEXT</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4 <span class="token keyword">COLLATE</span> utf8mb4_bin
<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>
In MySQL 8.4, the
<code class="literal">
BINARY
</code>
attribute is deprecated and you should expect support for it
to be removed in a future version of MySQL. Applications
should be adjusted to use an explicit
<code class="literal">
_bin
</code>
collation instead.
</p>
<p>
The use of
<code class="literal">
BINARY
</code>
to specify a data type
or character set remains unchanged.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
ASCII
</code>
attribute is shorthand for
<code class="literal">
CHARACTER SET latin1
</code>
. Supported in older
MySQL releases,
<code class="literal">
ASCII
</code>
is deprecated; use
<code class="literal">
CHARACTER SET
</code>
instead.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
UNICODE
</code>
attribute is shorthand for
<code class="literal">
CHARACTER SET ucs2
</code>
. Supported in older
MySQL releases,
<code class="literal">
UNICODE
</code>
is deprecated;
use
<code class="literal">
CHARACTER SET
</code>
instead.
</p>
</li>
</ul>
</div>
<p>
Character column comparison and sorting are based on the
collation assigned to the column. For 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>
,
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
,
<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, you can declare a
column with a binary (
<code class="literal">
_bin
</code>
) collation or the
<code class="literal">
BINARY
</code>
attribute to cause comparison and
sorting to use the underlying character code values rather than
a lexical ordering.
</p>
<p>
For additional information about use of character sets in MySQL,
see
<a class="xref" href="charset.html" title="Chapter 12 Character Sets, Collations, Unicode">
Chapter 12,
<i>
Character Sets, Collations, Unicode
</i>
</a>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212994224">
</a>
<a class="indexterm" name="idm46045212993152">
</a>
<a class="indexterm" name="idm46045212992080">
</a>
<a class="indexterm" name="idm46045212991008">
</a>
<a class="indexterm" name="idm46045212989936">
</a>
<a class="indexterm" name="idm46045212988448">
</a>
<a class="indexterm" name="idm46045212986960">
</a>
<a class="indexterm" name="idm46045212985472">
</a>
<code class="literal">
[NATIONAL] CHAR[(
<em class="replaceable">
<code>
M
</code>
</em>
)]
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</p>
<p>
A fixed-length string that is always right-padded with
spaces to the specified length when stored.
<em class="replaceable">
<code>
M
</code>
</em>
represents the column length in
characters. The range of
<em class="replaceable">
<code>
M
</code>
</em>
is 0
to 255. If
<em class="replaceable">
<code>
M
</code>
</em>
is omitted, the
length is 1.
</p>
<a class="indexterm" name="idm46045212979968">
</a>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
Trailing spaces are removed when
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
CHAR
</code>
</a>
values are retrieved
unless the
<a class="link" href="sql-mode.html#sqlmode_pad_char_to_full_length">
<code class="literal">
PAD_CHAR_TO_FULL_LENGTH
</code>
</a>
SQL mode is enabled.
</p>
</div>
<p>
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
CHAR
</code>
</a>
is shorthand for
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
CHARACTER
</code>
</a>
.
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
NATIONAL CHAR
</code>
</a>
(or its
equivalent short form,
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
NCHAR
</code>
</a>
)
is the standard SQL way to define that a
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
CHAR
</code>
</a>
column should use some
predefined character set. MySQL uses
<code class="literal">
utf8mb3
</code>
as this predefined character set.
<a class="xref" href="charset-national.html" title="12.3.7 The National Character Set">
Section 12.3.7, “The National Character Set”
</a>
.
</p>
<p>
The
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
CHAR BYTE
</code>
</a>
data type is an
alias for the
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
BINARY
</code>
</a>
data
type. This is a compatibility feature.
</p>
<p>
MySQL permits you to create a column of type
<code class="literal">
CHAR(0)
</code>
. This is useful primarily when
you must be compliant with old applications that depend on
the existence of a column but that do not actually use its
value.
<code class="literal">
CHAR(0)
</code>
is also quite nice when
you need a column that can take only two values: A column
that is defined as
<code class="literal">
CHAR(0) NULL
</code>
occupies
only one bit and can take only the values
<code class="literal">
NULL
</code>
and
<code class="literal">
''
</code>
(the empty
string).
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212953744">
</a>
<a class="indexterm" name="idm46045212952672">
</a>
<a class="indexterm" name="idm46045212951584">
</a>
<a class="indexterm" name="idm46045212950512">
</a>
<a class="indexterm" name="idm46045212949440">
</a>
<a class="indexterm" name="idm46045212948352">
</a>
<a class="indexterm" name="idm46045212947280">
</a>
<a class="indexterm" name="idm46045212945792">
</a>
<a class="indexterm" name="idm46045212944304">
</a>
<a class="indexterm" name="idm46045212942816">
</a>
<a class="indexterm" name="idm46045212941328">
</a>
<a class="indexterm" name="idm46045212939840">
</a>
<code class="literal">
[NATIONAL] VARCHAR(
<em class="replaceable">
<code>
M
</code>
</em>
)
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</p>
<a class="indexterm" name="idm46045212936224">
</a>
<p>
A variable-length string.
<em class="replaceable">
<code>
M
</code>
</em>
represents the maximum column length in characters. The
range of
<em class="replaceable">
<code>
M
</code>
</em>
is 0 to 65,535. The
effective maximum length of a
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
is subject to the
maximum row size (65,535 bytes, which is shared among all
columns) and the character set used. For example,
<code class="literal">
utf8mb3
</code>
characters can require up to
three bytes per character, so a
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
column that uses the
<code class="literal">
utf8mb3
</code>
character set can be declared to
be a maximum of 21,844 characters. 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>
<p>
MySQL stores
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
values
as a 1-byte or 2-byte length prefix plus data. The length
prefix indicates the number of bytes in the value. A
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
column uses one
length byte if values require no more than 255 bytes, two
length bytes if values may require more than 255 bytes.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
MySQL follows the standard SQL specification, and does
<span class="emphasis">
<em>
not
</em>
</span>
remove trailing spaces from
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
values.
</p>
</div>
<p>
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
is shorthand for
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
CHARACTER VARYING
</code>
</a>
.
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
NATIONAL VARCHAR
</code>
</a>
is the
standard SQL way to define that a
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
column should use
some predefined character set. MySQL uses
<code class="literal">
utf8mb3
</code>
as this predefined character set.
<a class="xref" href="charset-national.html" title="12.3.7 The National Character Set">
Section 12.3.7, “The National Character Set”
</a>
.
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
NVARCHAR
</code>
</a>
is shorthand for
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
NATIONAL VARCHAR
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212910752">
</a>
<a class="indexterm" name="idm46045212909680">
</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>
M
</code>
</em>
)]
</code>
</a>
</p>
<p>
The
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
BINARY
</code>
</a>
type is similar to
the
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
CHAR
</code>
</a>
type, but stores
binary byte strings rather than nonbinary character strings.
An optional length
<em class="replaceable">
<code>
M
</code>
</em>
represents
the column length in bytes. If omitted,
<em class="replaceable">
<code>
M
</code>
</em>
defaults to 1.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212900064">
</a>
<a class="indexterm" name="idm46045212898992">
</a>
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
VARBINARY(
<em class="replaceable">
<code>
M
</code>
</em>
)
</code>
</a>
</p>
<p>
The
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
VARBINARY
</code>
</a>
type is similar
to the
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
type, but
stores binary byte strings rather than nonbinary character
strings.
<em class="replaceable">
<code>
M
</code>
</em>
represents the maximum
column length in bytes.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212889856">
</a>
<a class="indexterm" name="idm46045212888784">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TINYBLOB
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
column with a maximum
length of 255 (2
<sup>
8
</sup>
− 1)
bytes. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TINYBLOB
</code>
</a>
value is
stored using a 1-byte length prefix that indicates the
number of bytes in the value.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212879984">
</a>
<a class="indexterm" name="idm46045212878912">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TINYTEXT
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
column with a maximum
length of 255 (2
<sup>
8
</sup>
− 1)
characters. The effective maximum length is less if the
value contains multibyte characters. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TINYTEXT
</code>
</a>
value is stored
using a 1-byte length prefix that indicates the number of
bytes in the value.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212868992">
</a>
<a class="indexterm" name="idm46045212867920">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB[(
<em class="replaceable">
<code>
M
</code>
</em>
)]
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
column with a maximum
length of 65,535 (2
<sup>
16
</sup>
− 1)
bytes. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
value is
stored using a 2-byte length prefix that indicates the
number of bytes in the value.
</p>
<p>
An optional length
<em class="replaceable">
<code>
M
</code>
</em>
can be given
for this type. If this is done, MySQL creates the column as
the smallest
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
type large
enough to hold values
<em class="replaceable">
<code>
M
</code>
</em>
bytes
long.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212856096">
</a>
<a class="indexterm" name="idm46045212855024">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT[(
<em class="replaceable">
<code>
M
</code>
</em>
)]
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
column with a maximum
length of 65,535 (2
<sup>
16
</sup>
− 1)
characters. The effective maximum length is less if the
value contains multibyte characters. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
value is stored using a
2-byte length prefix that indicates the number of bytes in
the value.
</p>
<p>
An optional length
<em class="replaceable">
<code>
M
</code>
</em>
can be given
for this type. If this is done, MySQL creates the column as
the smallest
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
type large
enough to hold values
<em class="replaceable">
<code>
M
</code>
</em>
characters long.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212842032">
</a>
<a class="indexterm" name="idm46045212840960">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
MEDIUMBLOB
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
column with a maximum
length of 16,777,215 (2
<sup>
24
</sup>
−
1) bytes. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
MEDIUMBLOB
</code>
</a>
value is stored using a 3-byte length prefix that indicates
the number of bytes in the value.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212832144">
</a>
<a class="indexterm" name="idm46045212831072">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
MEDIUMTEXT
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
column with a maximum
length of 16,777,215 (2
<sup>
24
</sup>
−
1) characters. The effective maximum length is less if the
value contains multibyte characters. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
MEDIUMTEXT
</code>
</a>
value is stored
using a 3-byte length prefix that indicates the number of
bytes in the value.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212820432">
</a>
<a class="indexterm" name="idm46045212819360">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGBLOB
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
column with a maximum
length of 4,294,967,295 or 4GB
(2
<sup>
32
</sup>
− 1) bytes. The
effective maximum length of
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGBLOB
</code>
</a>
columns depends on
the configured maximum packet size in the client/server
protocol and available memory. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGBLOB
</code>
</a>
value is stored
using a 4-byte length prefix that indicates the number of
bytes in the value.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212809088">
</a>
<a class="indexterm" name="idm46045212808016">
</a>
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGTEXT
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</a>
</p>
<p>
A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
TEXT
</code>
</a>
column with a maximum
length of 4,294,967,295 or 4GB
(2
<sup>
32
</sup>
− 1) characters. The
effective maximum length is less if the value contains
multibyte characters. The effective maximum length of
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGTEXT
</code>
</a>
columns also depends on the configured maximum packet size
in the client/server protocol and available memory. Each
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
LONGTEXT
</code>
</a>
value is stored using a 4-byte length prefix that indicates
the number of bytes in the value.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212796640">
</a>
<a class="indexterm" name="idm46045212795568">
</a>
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM('
<em class="replaceable">
<code>
value1
</code>
</em>
','
<em class="replaceable">
<code>
value2
</code>
</em>
',...)
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</a>
</p>
<p>
An enumeration. A string object that can have only one
value, chosen from the list of values
<code class="literal">
'
<em class="replaceable">
<code>
value1
</code>
</em>
'
</code>
,
<code class="literal">
'
<em class="replaceable">
<code>
value2
</code>
</em>
'
</code>
,
<code class="literal">
...
</code>
,
<code class="literal">
NULL
</code>
or the
special
<code class="literal">
''
</code>
error value.
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
values are represented
internally as integers.
</p>
<p>
An
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
column can have a
maximum of 65,535 distinct elements.
</p>
<p>
The maximum supported length of an individual
<code class="literal">
ENUM
</code>
element is
<em class="replaceable">
<code>
M
</code>
</em>
<= 255 and
(
<em class="replaceable">
<code>
M
</code>
</em>
x
<em class="replaceable">
<code>
w
</code>
</em>
) <= 1020, where
<code class="literal">
M
</code>
is the element literal length and
<em class="replaceable">
<code>
w
</code>
</em>
is the number of bytes required
for the maximum-length character in the character set.
</p>
</li>
<li class="listitem">
<p>
<a class="indexterm" name="idm46045212776848">
</a>
<a class="indexterm" name="idm46045212775776">
</a>
<a class="link" href="set.html" title="13.3.6 The SET Type">
<code class="literal">
SET('
<em class="replaceable">
<code>
value1
</code>
</em>
','
<em class="replaceable">
<code>
value2
</code>
</em>
',...)
[CHARACTER SET
<em class="replaceable">
<code>
charset_name
</code>
</em>
]
[COLLATE
<em class="replaceable">
<code>
collation_name
</code>
</em>
]
</code>
</a>
</p>
<p>
A set. A string object that can have zero or more values,
each of which must be chosen from the list of values
<code class="literal">
'
<em class="replaceable">
<code>
value1
</code>
</em>
'
</code>
,
<code class="literal">
'
<em class="replaceable">
<code>
value2
</code>
</em>
'
</code>
,
<code class="literal">
...
</code>
<a class="link" href="set.html" title="13.3.6 The SET Type">
<code class="literal">
SET
</code>
</a>
values are represented internally as integers.
</p>
<p>
A
<a class="link" href="set.html" title="13.3.6 The SET Type">
<code class="literal">
SET
</code>
</a>
column can have a
maximum of 64 distinct members.
</p>
<p>
The maximum supported length of an individual
<code class="literal">
SET
</code>
element is
<em class="replaceable">
<code>
M
</code>
</em>
<= 255 and
(
<em class="replaceable">
<code>
M
</code>
</em>
x
<em class="replaceable">
<code>
w
</code>
</em>
) <= 1020, where
<code class="literal">
M
</code>
is the element literal length and
<em class="replaceable">
<code>
w
</code>
</em>
is the number of bytes required
for the maximum-length character in the character set.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-limitations-multiple-nodes.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="mysql-cluster-limitations-multiple-nodes">
</a>
25.2.7.10 Limitations Relating to Multiple NDB Cluster Nodes
</h4>
</div>
</div>
</div>
<p>
<b>
Multiple SQL nodes.
</b>
<a class="indexterm" name="idm46045123152960">
</a>
The following are issues relating to the use of multiple MySQL
servers as NDB Cluster SQL nodes, and are specific to the
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDBCLUSTER
</code>
</a>
storage engine:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<b>
Stored programs not distributed.
</b>
Stored procedures, stored functions, triggers, and
scheduled events are all supported by 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, but these
do
<span class="emphasis">
<em>
not
</em>
</span>
propagate automatically
between MySQL Servers acting as Cluster SQL nodes, and
must be re-created separately on each SQL node. See
<a class="xref" href="stored-program-restrictions.html#stored-routines-ndbcluster" title="Stored routines and triggers in NDB Cluster">
Stored routines and triggers in NDB Cluster
</a>
.
</p>
</li>
<li class="listitem">
<p>
<b>
No distributed table locks.
</b>
A
<a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements">
<code class="literal">
LOCK TABLES
</code>
</a>
statement or
<a class="link" href="locking-functions.html#function_get-lock">
<code class="literal">
GET_LOCK()
</code>
</a>
call works only
for the SQL node on which the lock is issued; no other SQL
node in the cluster
<span class="quote">
“
<span class="quote">
sees
</span>
”
</span>
this lock. This is
true for a lock issued by any statement that locks tables
as part of its operations. (See next item for an example.)
</p>
<p>
Implementing table locks in
<code class="literal">
NDBCLUSTER
</code>
can be done in an API application, and ensuring that all
applications start by setting
<a class="ulink" href="/doc/ndbapi/en/ndb-ndboperation.html#ndb-ndboperation-lockmode" target="_top">
<code class="literal">
LockMode
</code>
</a>
to
<code class="literal">
LM_Read
</code>
or
<code class="literal">
LM_Exclusive
</code>
. For more information about
how to do this, see the description of
<a class="ulink" href="/doc/ndbapi/en/ndb-ndboperation.html#ndb-ndboperation-getlockhandle" target="_top">
<code class="literal">
NdbOperation::getLockHandle()
</code>
</a>
in the
<em class="citetitle">
NDB Cluster API Guide
</em>
.
</p>
</li>
<li class="listitem">
<p>
<b>
ALTER TABLE operations.
</b>
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
is not fully
locking when running multiple MySQL servers (SQL nodes).
(As discussed in the previous item, NDB Cluster does not
support distributed table locks.)
</p>
</li>
</ul>
</div>
<p>
<b>
Multiple management nodes.
</b>
<a class="indexterm" name="idm46045123130560">
</a>
When using multiple management servers:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
If any of the management servers are running on the same
host, you must give nodes explicit IDs in connection strings
because automatic allocation of node IDs does not work
across multiple management servers on the same host. This is
not required if every management server resides on a
different host.
</p>
</li>
<li class="listitem">
<p>
When a management server starts, it first checks for any
other management server in the same NDB Cluster, and upon
successful connection to the other management server uses
its configuration data. This means that the management
server
<a class="link" href="mysql-cluster-programs-ndb-mgmd.html#option_ndb_mgmd_reload">
<code class="option">
--reload
</code>
</a>
and
<a class="link" href="mysql-cluster-programs-ndb-mgmd.html#option_ndb_mgmd_initial">
<code class="option">
--initial
</code>
</a>
startup options
are ignored unless the management server is the only one
running. It also means that, when performing a rolling
restart of an NDB Cluster with multiple management nodes,
the management server reads its own configuration file if
(and only if) it is the only management server running in
this NDB Cluster. See
<a class="xref" href="mysql-cluster-rolling-restart.html" title="25.6.5 Performing a Rolling Restart of an NDB Cluster">
Section 25.6.5, “Performing a Rolling Restart of an NDB Cluster”
</a>
, for more
information.
</p>
</li>
</ul>
</div>
<p>
<b>
Multiple network addresses.
</b>
Multiple network addresses per data node are not supported.
Use of these is liable to cause problems: In the event of a
data node failure, an SQL node waits for confirmation that the
data node went down but never receives it because another
route to that data node remains open. This can effectively
make the cluster inoperable.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
It is possible to use multiple network hardware
<span class="emphasis">
<em>
interfaces
</em>
</span>
(such as Ethernet cards) for a
single data node, but these must be bound to the same address.
This also means that it not possible to use more than one
<code class="literal">
[tcp]
</code>
section per connection in the
<code class="literal">
config.ini
</code>
file. See
<a class="xref" href="mysql-cluster-tcp-definition.html" title="25.4.3.10 NDB Cluster TCP/IP Connections">
Section 25.4.3.10, “NDB Cluster TCP/IP Connections”
</a>
, for more
information.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/data-dictionary-object-cache.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="data-dictionary-object-cache">
</a>
16.4 Dictionary Object Cache
</h2>
</div>
</div>
</div>
<a class="indexterm" name="idm46045167734048">
</a>
<a class="indexterm" name="idm46045167732976">
</a>
<p>
The dictionary object cache is a shared global cache that stores
previously accessed data dictionary objects in memory to enable
object reuse and minimize disk I/O. Similar to other cache
mechanisms used by MySQL, the dictionary object cache uses an
<a class="link" href="glossary.html#glos_lru" title="LRU">
LRU
</a>
-based eviction strategy to
evict least recently used objects from memory.
</p>
<p>
The dictionary object cache comprises cache partitions that store
different object types. Some cache partition size limits are
configurable, whereas others are hardcoded.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<span class="bold">
<strong>
tablespace definition cache
partition
</strong>
</span>
: Stores tablespace definition objects.
The
<a class="link" href="server-system-variables.html#sysvar_tablespace_definition_cache">
<code class="literal">
tablespace_definition_cache
</code>
</a>
option sets a limit for the number of tablespace definition
objects that can be stored in the dictionary object cache. The
default value is 256.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
schema definition cache
partition
</strong>
</span>
: Stores schema definition objects. The
<a class="link" href="server-system-variables.html#sysvar_schema_definition_cache">
<code class="literal">
schema_definition_cache
</code>
</a>
option sets a limit for the number of schema definition
objects that can be stored in the dictionary object cache. The
default value is 256.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
table definition cache
partition
</strong>
</span>
: Stores table definition objects. The
object limit is set to the value of
<a class="link" href="server-system-variables.html#sysvar_max_connections">
<code class="literal">
max_connections
</code>
</a>
, which has a
default value of 151.
</p>
<p>
The table definition cache partition exists in parallel with
the table definition cache that is configured using the
<a class="link" href="server-system-variables.html#sysvar_table_definition_cache">
<code class="literal">
table_definition_cache
</code>
</a>
configuration option. Both caches store table definitions but
serve different parts of the MySQL server. Objects in one
cache have no dependence on the existence of objects in the
other.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
stored program definition cache
partition
</strong>
</span>
: Stores stored program definition
objects. The
<a class="link" href="server-system-variables.html#sysvar_stored_program_definition_cache">
<code class="literal">
stored_program_definition_cache
</code>
</a>
option sets a limit for the number of stored program
definition objects that can be stored in the dictionary object
cache. The default value is 256.
</p>
<p>
The stored program definition cache partition exists in
parallel with the stored procedure and stored function caches
that are configured using the
<a class="link" href="server-system-variables.html#sysvar_stored_program_cache">
<code class="literal">
stored_program_cache
</code>
</a>
option.
</p>
<p>
The
<a class="link" href="server-system-variables.html#sysvar_stored_program_cache">
<code class="literal">
stored_program_cache
</code>
</a>
option sets a soft upper limit for the number of cached stored
procedures or functions per connection, and the limit is
checked each time a connection executes a stored procedure or
function. The stored program definition cache partition, on
the other hand, is a shared cache that stores stored program
definition objects for other purposes. The existence of
objects in the stored program definition cache partition has
no dependence on the existence of objects in the stored
procedure cache or stored function cache, and vice versa.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
character set definition cache
partition
</strong>
</span>
: Stores character set definition objects
and has a hardcoded object limit of 256.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
collation definition cache
partition
</strong>
</span>
: Stores collation definition objects and
has a hardcoded object limit of 256.
</p>
</li>
</ul>
</div>
<p>
For information about valid values for dictionary object cache
configuration options, refer to
<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/innodb-online-ddl-failure-conditions.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="innodb-online-ddl-failure-conditions">
</a>
17.12.7 Online DDL Failure Conditions
</h3>
</div>
</div>
</div>
<p>
The failure of an online DDL operation is typically due to one of
the following conditions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
An
<code class="literal">
ALGORITHM
</code>
clause specifies an algorithm
that is not compatible with the particular type of DDL
operation or storage engine.
</p>
</li>
<li class="listitem">
<p>
A
<code class="literal">
LOCK
</code>
clause specifies a low degree of
locking (
<code class="literal">
SHARED
</code>
or
<code class="literal">
NONE
</code>
)
that is not compatible with the particular type of DDL
operation.
</p>
</li>
<li class="listitem">
<p>
A timeout occurs while waiting for an
<a class="link" href="glossary.html#glos_exclusive_lock" title="exclusive lock">
exclusive lock
</a>
on
the table, which may be needed briefly during the initial and
final phases of the DDL operation.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="server-system-variables.html#sysvar_tmpdir">
<code class="literal">
tmpdir
</code>
</a>
or
<a class="link" href="innodb-parameters.html#sysvar_innodb_tmpdir">
<code class="literal">
innodb_tmpdir
</code>
</a>
file system
runs out of disk space, while MySQL writes temporary sort
files on disk during index creation. For more information, 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>
</li>
<li class="listitem">
<p>
The operation takes a long time and concurrent DML modifies
the table so much that the size of the temporary online log
exceeds the value of the
<a class="link" href="innodb-parameters.html#sysvar_innodb_online_alter_log_max_size">
<code class="literal">
innodb_online_alter_log_max_size
</code>
</a>
configuration option. This condition causes a
<code class="literal">
DB_ONLINE_LOG_TOO_BIG
</code>
error.
</p>
</li>
<li class="listitem">
<p>
Concurrent DML makes changes to the table that are allowed
with the original table definition, but not with the new one.
The operation only fails at the very end, when MySQL tries to
apply all the changes from concurrent DML statements. For
example, you might insert duplicate values into a column while
a unique index is being created, or you might insert
<code class="literal">
NULL
</code>
values into a column while creating a
<a class="link" href="glossary.html#glos_primary_key" title="primary key">
primary key
</a>
index on
that column. The changes made by the concurrent DML take
precedence, and the
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
operation is effectively
<a class="link" href="glossary.html#glos_rollback" title="rollback">
rolled
back
</a>
.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/show-triggers.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="show-triggers">
</a>
15.7.7.40 SHOW TRIGGERS Statement
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045169091600">
</a>
<a class="indexterm" name="idm46045169090528">
</a>
<a class="indexterm" name="idm46045169089456">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46539047"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">TRIGGERS</span>
<span class="token punctuation">[</span>{<span class="token keyword">FROM</span> <span class="token operator">|</span> <span class="token keyword">IN</span>} <em class="replaceable">db_name</em><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token operator">LIKE</span> <span class="token string">'<em class="replaceable">pattern</em>'</span> <span class="token operator">|</span> <span class="token keyword">WHERE</span> <em class="replaceable">expr</em><span class="token punctuation">]</span></code></pre>
</div>
<p>
<a class="link" href="show-triggers.html" title="15.7.7.40 SHOW TRIGGERS Statement">
<code class="literal">
SHOW TRIGGERS
</code>
</a>
lists the triggers
currently defined for tables in a database (the default database
unless a
<code class="literal">
FROM
</code>
clause is given). This
statement returns results only for databases and tables for
which you have the
<a class="link" href="privileges-provided.html#priv_trigger">
<code class="literal">
TRIGGER
</code>
</a>
privilege. The
<a class="link" href="string-comparison-functions.html#operator_like">
<code class="literal">
LIKE
</code>
</a>
clause, if
present, indicates which table names (not trigger names) to
match and causes the statement to display triggers for those
tables. The
<code class="literal">
WHERE
</code>
clause can be given to
select rows using more general conditions, as discussed in
<a class="xref" href="extended-show.html" title="28.8 Extensions to SHOW Statements">
Section 28.8, “Extensions to SHOW Statements”
</a>
.
</p>
<p>
For the
<code class="literal">
ins_sum
</code>
trigger defined in
<a class="xref" href="triggers.html" title="27.3 Using Triggers">
Section 27.3, “Using Triggers”
</a>
, the output of
<a class="link" href="show-triggers.html" title="15.7.7.40 SHOW TRIGGERS Statement">
<code class="literal">
SHOW TRIGGERS
</code>
</a>
is as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41795362"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">TRIGGERS</span> <span class="token operator">LIKE</span> <span class="token string">'acc%'</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>
Trigger<span class="token punctuation">:</span> ins_sum
Event<span class="token punctuation">:</span> INSERT
Table<span class="token punctuation">:</span> account
Statement<span class="token punctuation">:</span> SET @sum = @sum + NEW.amount
Timing<span class="token punctuation">:</span> BEFORE
Created<span class="token punctuation">:</span> 2018-08-08 10<span class="token punctuation">:</span>10<span class="token punctuation">:</span>12.61
sql_mode<span class="token punctuation">:</span> ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,
NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,
NO_ENGINE_SUBSTITUTION
Definer<span class="token punctuation">:</span> me@localhost
character_set_client<span class="token punctuation">:</span> utf8mb4
collation_connection<span class="token punctuation">:</span> utf8mb4_0900_ai_ci
Database Collation<span class="token punctuation">:</span> utf8mb4_0900_ai_ci</span></code></pre>
</div>
<p>
<a class="link" href="show-triggers.html" title="15.7.7.40 SHOW TRIGGERS Statement">
<code class="literal">
SHOW TRIGGERS
</code>
</a>
output has these
columns:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
Trigger
</code>
</p>
<p>
The name of the trigger.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Event
</code>
</p>
<p>
The trigger event. This is the type of operation on the
associated table for which the trigger activates. The value
is
<code class="literal">
INSERT
</code>
(a row was inserted),
<code class="literal">
DELETE
</code>
(a row was deleted), or
<code class="literal">
UPDATE
</code>
(a row was modified).
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Table
</code>
</p>
<p>
The table for which the trigger is defined.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Statement
</code>
</p>
<p>
The trigger body; that is, the statement executed when the
trigger activates.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Timing
</code>
</p>
<p>
Whether the trigger activates before or after the triggering
event. The value is
<code class="literal">
BEFORE
</code>
or
<code class="literal">
AFTER
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Created
</code>
</p>
<p>
The date and time when the trigger was created. This is a
<code class="literal">
TIMESTAMP(2)
</code>
value (with a fractional
part in hundredths of seconds) for triggers.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
sql_mode
</code>
</p>
<p>
The SQL mode in effect when the trigger was created, and
under which the trigger executes. For the permitted values,
see
<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>
<code class="literal">
Definer
</code>
</p>
<p>
The account of the user who created the trigger, in
<code class="literal">
'
<em class="replaceable">
<code>
user_name
</code>
</em>
'@'
<em class="replaceable">
<code>
host_name
</code>
</em>
'
</code>
format.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
character_set_client
</code>
</p>
<p>
The session value of the
<a class="link" href="server-system-variables.html#sysvar_character_set_client">
<code class="literal">
character_set_client
</code>
</a>
system
variable when the trigger was created.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
collation_connection
</code>
</p>
<p>
The session value of the
<a class="link" href="server-system-variables.html#sysvar_collation_connection">
<code class="literal">
collation_connection
</code>
</a>
system
variable when the trigger was created.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Database Collation
</code>
</p>
<p>
The collation of the database with which the trigger is
associated.
</p>
</li>
</ul>
</div>
<p>
Trigger information is also available from the
<code class="literal">
INFORMATION_SCHEMA
</code>
<a class="link" href="information-schema-triggers-table.html" title="28.3.44 The INFORMATION_SCHEMA TRIGGERS Table">
<code class="literal">
TRIGGERS
</code>
</a>
table. See
<a class="xref" href="information-schema-triggers-table.html" title="28.3.44 The INFORMATION_SCHEMA TRIGGERS Table">
Section 28.3.44, “The INFORMATION_SCHEMA TRIGGERS Table”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/create-view.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="create-view">
</a>
15.1.23 CREATE VIEW Statement
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045183705824">
</a>
<a class="indexterm" name="idm46045183704752">
</a>
<a class="indexterm" name="idm46045183703264">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa94735373"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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 punctuation">[</span><span class="token operator">OR</span> <span class="token keyword">REPLACE</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token keyword">ALGORITHM</span> <span class="token operator">=</span> {<span class="token keyword">UNDEFINED</span> <span class="token operator">|</span> <span class="token keyword">MERGE</span> <span class="token operator">|</span> <span class="token keyword">TEMPTABLE</span>}<span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token keyword">DEFINER</span> <span class="token operator">=</span> <span class="token keyword"><em class="replaceable">user</em></span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token keyword">SQL</span> <span class="token keyword">SECURITY</span> { <span class="token keyword">DEFINER</span> <span class="token operator">|</span> <span class="token keyword">INVOKER</span> }<span class="token punctuation">]</span>
<span class="token keyword">VIEW</span> <em class="replaceable">view_name</em> <span class="token punctuation">[</span><span class="token punctuation">(</span><em class="replaceable">column_list</em><span class="token punctuation">)</span><span class="token punctuation">]</span>
<span class="token keyword">AS</span> <em class="replaceable">select_statement</em>
<span class="token punctuation">[</span><span class="token keyword">WITH</span> <span class="token punctuation">[</span><span class="token keyword">CASCADED</span> <span class="token operator">|</span> <span class="token keyword">LOCAL</span><span class="token punctuation">]</span> <span class="token keyword">CHECK</span> <span class="token keyword">OPTION</span><span class="token punctuation">]</span></code></pre>
</div>
<p>
The
<a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
<code class="literal">
CREATE VIEW
</code>
</a>
statement creates a
new view, or replaces an existing view if the
<code class="literal">
OR
REPLACE
</code>
clause is given. If the view does not exist,
<a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
<code class="literal">
CREATE OR REPLACE
VIEW
</code>
</a>
is the same as
<a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
<code class="literal">
CREATE
VIEW
</code>
</a>
. If the view does exist,
<a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
<code class="literal">
CREATE OR REPLACE
VIEW
</code>
</a>
replaces it.
</p>
<p>
For information about restrictions on view use, see
<a class="xref" href="view-restrictions.html" title="27.9 Restrictions on Views">
Section 27.9, “Restrictions on Views”
</a>
.
</p>
<p>
The
<em class="replaceable">
<code>
select_statement
</code>
</em>
is a
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement that provides the
definition of the view. (Selecting from the view selects, in
effect, using the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement.) The
<em class="replaceable">
<code>
select_statement
</code>
</em>
can
select from base tables or from other views. The
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement can use a
<a class="link" href="values.html" title="15.2.19 VALUES Statement">
<code class="literal">
VALUES
</code>
</a>
statement as its source, or
can be replaced with a
<a class="link" href="table.html" title="15.2.16 TABLE Statement">
<code class="literal">
TABLE
</code>
</a>
statement, as with
<a class="link" href="create-table-select.html" title="15.1.20.4 CREATE TABLE ... SELECT Statement">
<code class="literal">
CREATE TABLE
... SELECT
</code>
</a>
.
</p>
<p>
The view definition is
<span class="quote">
“
<span class="quote">
frozen
</span>
”
</span>
at creation time and
is not affected by subsequent changes to the definitions of the
underlying tables. For example, if a view is defined as
<code class="literal">
SELECT *
</code>
on a table, new columns added to the
table later do not become part of the view, and columns dropped
from the table result in an error when selecting from the view.
</p>
<p>
The
<code class="literal">
ALGORITHM
</code>
clause affects how MySQL
processes the view. The
<code class="literal">
DEFINER
</code>
and
<code class="literal">
SQL SECURITY
</code>
clauses specify the security
context to be used when checking access privileges at view
invocation time. The
<code class="literal">
WITH CHECK OPTION
</code>
clause
can be given to constrain inserts or updates to rows in tables
referenced by the view. These clauses are described later in this
section.
</p>
<p>
The
<a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
<code class="literal">
CREATE VIEW
</code>
</a>
statement requires
the
<a class="link" href="privileges-provided.html#priv_create-view">
<code class="literal">
CREATE VIEW
</code>
</a>
privilege for the
view, and some privilege for each column selected by the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement. For columns used
elsewhere in the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement,
you must have the
<a class="link" href="privileges-provided.html#priv_select">
<code class="literal">
SELECT
</code>
</a>
privilege.
If the
<code class="literal">
OR REPLACE
</code>
clause is present, you must
also have the
<a class="link" href="privileges-provided.html#priv_drop">
<code class="literal">
DROP
</code>
</a>
privilege for
the view. If the
<code class="literal">
DEFINER
</code>
clause is present, the
privileges required depend on the
<em class="replaceable">
<code>
user
</code>
</em>
value, as discussed in
<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>
When a view is referenced, privilege checking occurs as described
later in this section.
</p>
<p>
A view belongs to a database. By default, a new view is created in
the default database. To create the view explicitly in a given
database, use
<em class="replaceable">
<code>
db_name.view_name
</code>
</em>
syntax
to qualify the view name with the database name:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa55437178"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">VIEW</span> test<span class="token punctuation">.</span>v <span class="token keyword">AS</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t<span class="token punctuation">;</span></code></pre>
</div>
<p>
Unqualified table or view names in the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement are also
interpreted with respect to the default database. A view can refer
to tables or views in other databases by qualifying the table or
view name with the appropriate database name.
</p>
<p>
Within a database, base tables and views share the same namespace,
so a base table and a view cannot have the same name.
</p>
<p>
Columns retrieved by the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement can be simple references to table columns, or
expressions that use functions, constant values, operators, and so
forth.
</p>
<p>
A view must have unique column names with no duplicates, just like
a base table. By default, the names of the columns retrieved by
the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement are used for
the view column names. To define explicit names for the view
columns, specify the optional
<em class="replaceable">
<code>
column_list
</code>
</em>
clause as a list of
comma-separated identifiers. The number of names in
<em class="replaceable">
<code>
column_list
</code>
</em>
must be the same as the
number of columns retrieved by the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement.
</p>
<p>
A view can be created from many kinds of
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statements. It can refer to
base tables or other views. It can use joins,
<a class="link" href="union.html" title="15.2.18 UNION Clause">
<code class="literal">
UNION
</code>
</a>
, and subqueries. The
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
need not even refer to any
tables:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa99372095"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">VIEW</span> v_today <span class="token punctuation">(</span>today<span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">SELECT</span> <span class="token keyword">CURRENT_DATE</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The following example defines a view that selects two columns from
another table as well as an expression calculated from those
columns:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58054756"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t <span class="token punctuation">(</span>qty <span class="token datatype">INT</span><span class="token punctuation">,</span> price <span class="token datatype">INT</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <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">3</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">VIEW</span> v <span class="token keyword">AS</span> <span class="token keyword">SELECT</span> qty<span class="token punctuation">,</span> price<span class="token punctuation">,</span> qty<span class="token operator">*</span>price <span class="token keyword">AS</span> <span class="token keyword">value</span> <span class="token keyword">FROM</span> t<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> v<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>
<span class="token output"><span class="token punctuation">|</span> qty <span class="token punctuation">|</span> price <span class="token punctuation">|</span> value <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> 3 <span class="token punctuation">|</span> 50 <span class="token punctuation">|</span> 150 <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>
<p>
A view definition is subject to the following restrictions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement cannot
refer to system variables or user-defined variables.
</p>
</li>
<li class="listitem">
<p>
Within a stored program, the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement cannot refer
to program parameters or local variables.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement cannot
refer to prepared statement parameters.
</p>
</li>
<li class="listitem">
<p>
Any table or view referred to in the definition must exist.
If, after the view has been created, a table or view that the
definition refers to is dropped, use of the view results in an
error. To check a view definition for problems of this kind,
use the
<a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
<code class="literal">
CHECK TABLE
</code>
</a>
statement.
</p>
</li>
<li class="listitem">
<p>
The definition cannot refer to a
<code class="literal">
TEMPORARY
</code>
table, and you cannot create a
<code class="literal">
TEMPORARY
</code>
view.
</p>
</li>
<li class="listitem">
<p>
You cannot associate a trigger with a view.
</p>
</li>
<li class="listitem">
<p>
Aliases for column names in the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement are checked
against the maximum column length of 64 characters (not the
maximum alias length of 256 characters).
</p>
</li>
</ul>
</div>
<p>
<code class="literal">
ORDER BY
</code>
is permitted in a view definition, but
it is ignored if you select from a view using a statement that has
its own
<code class="literal">
ORDER BY
</code>
.
</p>
<p>
For other options or clauses in the definition, they are added to
the options or clauses of the statement that references the view,
but the effect is undefined. For example, if a view definition
includes a
<code class="literal">
LIMIT
</code>
clause, and you select from
the view using a statement that has its own
<code class="literal">
LIMIT
</code>
clause, it is undefined which limit
applies. This same principle applies to options such as
<code class="literal">
ALL
</code>
,
<code class="literal">
DISTINCT
</code>
, or
<code class="literal">
SQL_SMALL_RESULT
</code>
that follow the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
keyword, and to clauses such
as
<code class="literal">
INTO
</code>
,
<code class="literal">
FOR UPDATE
</code>
,
<code class="literal">
FOR SHARE
</code>
,
<code class="literal">
LOCK IN SHARE
MODE
</code>
, and
<code class="literal">
PROCEDURE
</code>
.
</p>
<p>
The results obtained from a view may be affected if you change the
query processing environment by changing system variables:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa76377055"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">VIEW</span> v <span class="token punctuation">(</span>mycol<span class="token punctuation">)</span> <span class="token keyword">AS</span> <span class="token keyword">SELECT</span> <span class="token string">'abc'</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.01 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SET</span> sql_mode <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token string">"mycol"</span> <span class="token keyword">FROM</span> v<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>
<span class="token output"><span class="token punctuation">|</span> mycol <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>
<span class="token output"><span class="token punctuation">|</span> mycol <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>
<span class="token output">1 row in set (0.01 sec)</span>
<span class="token prompt">mysql></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 output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token string">"mycol"</span> <span class="token keyword">FROM</span> v<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>
<span class="token output"><span class="token punctuation">|</span> mycol <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>
<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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
The
<code class="literal">
DEFINER
</code>
and
<code class="literal">
SQL SECURITY
</code>
clauses determine which MySQL account to use when checking access
privileges for the view when a statement is executed that
references the view. The valid
<code class="literal">
SQL SECURITY
</code>
characteristic values are
<code class="literal">
DEFINER
</code>
(the default)
and
<code class="literal">
INVOKER
</code>
. These indicate that the required
privileges must be held by the user who defined or invoked the
view, respectively.
</p>
<p>
If the
<code class="literal">
DEFINER
</code>
clause is present, the
<em class="replaceable">
<code>
user
</code>
</em>
value should be a MySQL account
specified as
<code class="literal">
'
<em class="replaceable">
<code>
user_name
</code>
</em>
'@'
<em class="replaceable">
<code>
host_name
</code>
</em>
'
</code>
,
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER
</code>
</a>
, or
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER()
</code>
</a>
. The permitted
<em class="replaceable">
<code>
user
</code>
</em>
values depend on the privileges
you hold, as discussed in
<a class="xref" href="stored-objects-security.html" title="27.6 Stored Object Access Control">
Section 27.6, “Stored Object Access Control”
</a>
. Also see that section
for additional information about view security.
</p>
<p>
If the
<code class="literal">
DEFINER
</code>
clause is omitted, the default
definer is the user who executes the
<a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
<code class="literal">
CREATE
VIEW
</code>
</a>
statement. This is the same as specifying
<code class="literal">
DEFINER = CURRENT_USER
</code>
explicitly.
</p>
<p>
Within a view definition, the
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER
</code>
</a>
function returns the
view's
<code class="literal">
DEFINER
</code>
value by default. For views
defined with the
<code class="literal">
SQL SECURITY INVOKER
</code>
characteristic,
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER
</code>
</a>
returns the account for the view's invoker. For information about
user auditing within views, see
<a class="xref" href="account-activity-auditing.html" title="8.2.23 SQL-Based Account Activity Auditing">
Section 8.2.23, “SQL-Based Account Activity Auditing”
</a>
.
</p>
<p>
Within a stored routine that is defined with the
<code class="literal">
SQL
SECURITY DEFINER
</code>
characteristic,
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER
</code>
</a>
returns the routine's
<code class="literal">
DEFINER
</code>
value. This also affects a view defined
within such a routine, if the view definition contains a
<code class="literal">
DEFINER
</code>
value of
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER
</code>
</a>
.
</p>
<p>
MySQL checks view privileges like this:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
At view definition time, the view creator must have the
privileges needed to use the top-level objects accessed by the
view. For example, if the view definition refers to table
columns, the creator must have some privilege for each column
in the select list of the definition, and the
<a class="link" href="privileges-provided.html#priv_select">
<code class="literal">
SELECT
</code>
</a>
privilege for each
column used elsewhere in the definition. If the definition
refers to a stored function, only the privileges needed to
invoke the function can be checked. The privileges required at
function invocation time can be checked only as it executes:
For different invocations, different execution paths within
the function might be taken.
</p>
</li>
<li class="listitem">
<p>
The user who references a view must have appropriate
privileges to access it (
<a class="link" href="privileges-provided.html#priv_select">
<code class="literal">
SELECT
</code>
</a>
to select from it,
<a class="link" href="privileges-provided.html#priv_insert">
<code class="literal">
INSERT
</code>
</a>
to
insert into it, and so forth.)
</p>
</li>
<li class="listitem">
<p>
When a view has been referenced, privileges for objects
accessed by the view are checked against the privileges held
by the view
<code class="literal">
DEFINER
</code>
account or invoker,
depending on whether the
<code class="literal">
SQL SECURITY
</code>
characteristic is
<code class="literal">
DEFINER
</code>
or
<code class="literal">
INVOKER
</code>
, respectively.
</p>
</li>
<li class="listitem">
<p>
If reference to a view causes execution of a stored function,
privilege checking for statements executed within the function
depend on whether the function
<code class="literal">
SQL SECURITY
</code>
characteristic is
<code class="literal">
DEFINER
</code>
or
<code class="literal">
INVOKER
</code>
. If the security characteristic is
<code class="literal">
DEFINER
</code>
, the function runs with the
privileges of the
<code class="literal">
DEFINER
</code>
account. If the
characteristic is
<code class="literal">
INVOKER
</code>
, the function
runs with the privileges determined by the view's
<code class="literal">
SQL
SECURITY
</code>
characteristic.
</p>
</li>
</ul>
</div>
<p>
Example: A view might depend on a stored function, and that
function might invoke other stored routines. For example, the
following view invokes a stored function
<code class="literal">
f()
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa23377496"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">VIEW</span> v <span class="token keyword">AS</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t <span class="token keyword">WHERE</span> t<span class="token punctuation">.</span>id <span class="token operator">=</span> f<span class="token punctuation">(</span>t<span class="token punctuation">.</span><span class="token keyword">name</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Suppose that
<code class="literal">
f()
</code>
contains a statement such as
this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14270531"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">IF</span> <span class="token keyword">name</span> <span class="token operator">IS</span> <span class="token boolean">NULL</span> <span class="token keyword">then</span>
<span class="token keyword">CALL</span> p1<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">ELSE</span>
<span class="token keyword">CALL</span> p2<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The privileges required for executing statements within
<code class="literal">
f()
</code>
need to be checked when
<code class="literal">
f()
</code>
executes. This might mean that privileges
are needed for
<code class="literal">
p1()
</code>
or
<code class="literal">
p2()
</code>
,
depending on the execution path within
<code class="literal">
f()
</code>
.
Those privileges must be checked at runtime, and the user who must
possess the privileges is determined by the
<code class="literal">
SQL
SECURITY
</code>
values of the view
<code class="literal">
v
</code>
and the
function
<code class="literal">
f()
</code>
.
</p>
<p>
The
<code class="literal">
DEFINER
</code>
and
<code class="literal">
SQL SECURITY
</code>
clauses for views are extensions to standard SQL. In standard SQL,
views are handled using the rules for
<code class="literal">
SQL SECURITY
DEFINER
</code>
. The standard says that the definer of the view,
which is the same as the owner of the view's schema, gets
applicable privileges on the view (for example,
<a class="link" href="privileges-provided.html#priv_select">
<code class="literal">
SELECT
</code>
</a>
) and may grant them. MySQL
has no concept of a schema
<span class="quote">
“
<span class="quote">
owner
</span>
”
</span>
, so MySQL adds a
clause to identify the definer. The
<code class="literal">
DEFINER
</code>
clause is an extension where the intent is to have what the
standard has; that is, a permanent record of who defined the view.
This is why the default
<code class="literal">
DEFINER
</code>
value is the
account of the view creator.
</p>
<p>
The optional
<code class="literal">
ALGORITHM
</code>
clause is a MySQL
extension to standard SQL. It affects how MySQL processes the
view.
<code class="literal">
ALGORITHM
</code>
takes three values:
<code class="literal">
MERGE
</code>
,
<code class="literal">
TEMPTABLE
</code>
, or
<code class="literal">
UNDEFINED
</code>
. For more information, see
<a class="xref" href="view-algorithms.html" title="27.5.2 View Processing Algorithms">
Section 27.5.2, “View Processing Algorithms”
</a>
, as well as
<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>
Some views are updatable. That is, you can use them in statements
such as
<a class="link" href="update.html" title="15.2.17 UPDATE Statement">
<code class="literal">
UPDATE
</code>
</a>
,
<a class="link" href="delete.html" title="15.2.2 DELETE Statement">
<code class="literal">
DELETE
</code>
</a>
, or
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
to update the contents of
the underlying table. For a view to be updatable, there must be a
one-to-one relationship between the rows in the view and the rows
in the underlying table. There are also certain other constructs
that make a view nonupdatable.
</p>
<a class="indexterm" name="idm46045183543232">
</a>
<p>
A generated column in a view is considered updatable because it is
possible to assign to it. However, if such a column is updated
explicitly, the only permitted value is
<code class="literal">
DEFAULT
</code>
. For information about generated
columns, see
<a class="xref" href="create-table-generated-columns.html" title="15.1.20.8 CREATE TABLE and Generated Columns">
Section 15.1.20.8, “CREATE TABLE and Generated Columns”
</a>
.
</p>
<p>
The
<code class="literal">
WITH CHECK OPTION
</code>
clause can be given for
an updatable view to prevent inserts or updates to rows except
those for which the
<code class="literal">
WHERE
</code>
clause in the
<em class="replaceable">
<code>
select_statement
</code>
</em>
is true.
</p>
<p>
In a
<code class="literal">
WITH CHECK OPTION
</code>
clause for an updatable
view, the
<code class="literal">
LOCAL
</code>
and
<code class="literal">
CASCADED
</code>
keywords determine the scope of check testing when the view is
defined in terms of another view. The
<code class="literal">
LOCAL
</code>
keyword restricts the
<code class="literal">
CHECK OPTION
</code>
only to the
view being defined.
<code class="literal">
CASCADED
</code>
causes the checks
for underlying views to be evaluated as well. When neither keyword
is given, the default is
<code class="literal">
CASCADED
</code>
.
</p>
<p>
For more information about updatable views and the
<code class="literal">
WITH
CHECK OPTION
</code>
clause, see
<a class="xref" href="view-updatability.html" title="27.5.3 Updatable and Insertable Views">
Section 27.5.3, “Updatable and Insertable Views”
</a>
, and
<a class="xref" href="view-check-option.html" title="27.5.4 The View WITH CHECK OPTION Clause">
Section 27.5.4, “The View WITH CHECK OPTION Clause”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-ndbinfo-diskstats-1sec.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="mysql-cluster-ndbinfo-diskstats-1sec">
</a>
25.6.17.33 The ndbinfo diskstats_1sec Table
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045089368336">
</a>
<p>
The
<code class="literal">
diskstats_1sec
</code>
table provides information
about writes to Disk Data tablespaces over the past 20 seconds.
</p>
<p>
The
<code class="literal">
diskstat
</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 of this node
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
block_instance
</code>
</p>
<p>
ID of reporting instance of
<a class="ulink" href="/doc/ndb-internals/en/ndb-internals-kernel-blocks-pgman.html" target="_top">
<code class="literal">
PGMAN
</code>
</a>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
pages_made_dirty
</code>
</p>
<p>
Pages made dirty during the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
reads_issued
</code>
</p>
<p>
Reads issued during the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
reads_completed
</code>
</p>
<p>
Reads completed during the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
writes_issued
</code>
</p>
<p>
Writes issued during the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
writes_completed
</code>
</p>
<p>
Writes completed during the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
log_writes_issued
</code>
</p>
<p>
Number of times a page write has required a log write during
the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
log_writes_completed
</code>
</p>
<p>
Number of log writes completed during the designated
1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
get_page_calls_issued
</code>
</p>
<p>
Number of
<code class="literal">
get_page()
</code>
calls issued during
the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
get_page_reqs_issued
</code>
</p>
<p>
Number of times that a
<code class="literal">
get_page()
</code>
call
has resulted in a wait for I/O or completion of I/O already
begun during the designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
get_page_reqs_completed
</code>
</p>
<p>
Number of
<code class="literal">
get_page()
</code>
calls waiting for
I/O or I/O completion that have completed during the
designated 1-second interval
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
seconds_ago
</code>
</p>
<p>
Number of 1-second intervals in the past of the interval to
which this row applies
</p>
</li>
</ul>
</div>
<h5>
<a name="idm46045089335408">
</a>
Notes
</h5>
<p>
Each row in this table corresponds to an instance of
<a class="ulink" href="/doc/ndb-internals/en/ndb-internals-kernel-blocks-pgman.html" target="_top">
<code class="literal">
PGMAN
</code>
</a>
during a 1-second
interval occurring from 0 to 19 seconds ago; there is one such
instance per LDM thread plus an additional instance for each
data node.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/information-schema.html | <div id="docs-body">
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title">
<a name="information-schema">
</a>
Chapter 28 INFORMATION_SCHEMA Tables
</h1>
</div>
</div>
</div>
<div class="toc">
<p>
<b>
Table of Contents
</b>
</p>
<dl class="toc">
<dt>
<span class="section">
<a href="information-schema-introduction.html">
28.1 Introduction
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-table-reference.html">
28.2 INFORMATION_SCHEMA Table Reference
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="general-information-schema-tables.html">
28.3 INFORMATION_SCHEMA General Tables
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="information-schema-general-table-reference.html">
28.3.1 INFORMATION_SCHEMA General Table Reference
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-administrable-role-authorizations-table.html">
28.3.2 The INFORMATION_SCHEMA ADMINISTRABLE_ROLE_AUTHORIZATIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-applicable-roles-table.html">
28.3.3 The INFORMATION_SCHEMA APPLICABLE_ROLES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-character-sets-table.html">
28.3.4 The INFORMATION_SCHEMA CHARACTER_SETS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-check-constraints-table.html">
28.3.5 The INFORMATION_SCHEMA CHECK_CONSTRAINTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-collations-table.html">
28.3.6 The INFORMATION_SCHEMA COLLATIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-collation-character-set-applicability-table.html">
28.3.7 The INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-columns-table.html">
28.3.8 The INFORMATION_SCHEMA COLUMNS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-columns-extensions-table.html">
28.3.9 The INFORMATION_SCHEMA COLUMNS_EXTENSIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-column-privileges-table.html">
28.3.10 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-column-statistics-table.html">
28.3.11 The INFORMATION_SCHEMA COLUMN_STATISTICS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-enabled-roles-table.html">
28.3.12 The INFORMATION_SCHEMA ENABLED_ROLES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-engines-table.html">
28.3.13 The INFORMATION_SCHEMA ENGINES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-events-table.html">
28.3.14 The INFORMATION_SCHEMA EVENTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-files-table.html">
28.3.15 The INFORMATION_SCHEMA FILES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-key-column-usage-table.html">
28.3.16 The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-keywords-table.html">
28.3.17 The INFORMATION_SCHEMA KEYWORDS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-ndb-transid-mysql-connection-map-table.html">
28.3.18 The INFORMATION_SCHEMA ndb_transid_mysql_connection_map Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-optimizer-trace-table.html">
28.3.19 The INFORMATION_SCHEMA OPTIMIZER_TRACE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-parameters-table.html">
28.3.20 The INFORMATION_SCHEMA PARAMETERS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-partitions-table.html">
28.3.21 The INFORMATION_SCHEMA PARTITIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-plugins-table.html">
28.3.22 The INFORMATION_SCHEMA PLUGINS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-processlist-table.html">
28.3.23 The INFORMATION_SCHEMA PROCESSLIST Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-profiling-table.html">
28.3.24 The INFORMATION_SCHEMA PROFILING Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-referential-constraints-table.html">
28.3.25 The INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-resource-groups-table.html">
28.3.26 The INFORMATION_SCHEMA RESOURCE_GROUPS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-role-column-grants-table.html">
28.3.27 The INFORMATION_SCHEMA ROLE_COLUMN_GRANTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-role-routine-grants-table.html">
28.3.28 The INFORMATION_SCHEMA ROLE_ROUTINE_GRANTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-role-table-grants-table.html">
28.3.29 The INFORMATION_SCHEMA ROLE_TABLE_GRANTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-routines-table.html">
28.3.30 The INFORMATION_SCHEMA ROUTINES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-schemata-table.html">
28.3.31 The INFORMATION_SCHEMA SCHEMATA Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-schemata-extensions-table.html">
28.3.32 The INFORMATION_SCHEMA SCHEMATA_EXTENSIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-schema-privileges-table.html">
28.3.33 The INFORMATION_SCHEMA SCHEMA_PRIVILEGES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-statistics-table.html">
28.3.34 The INFORMATION_SCHEMA STATISTICS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-st-geometry-columns-table.html">
28.3.35 The INFORMATION_SCHEMA ST_GEOMETRY_COLUMNS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-st-spatial-reference-systems-table.html">
28.3.36 The INFORMATION_SCHEMA ST_SPATIAL_REFERENCE_SYSTEMS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-st-units-of-measure-table.html">
28.3.37 The INFORMATION_SCHEMA ST_UNITS_OF_MEASURE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-tables-table.html">
28.3.38 The INFORMATION_SCHEMA TABLES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-tables-extensions-table.html">
28.3.39 The INFORMATION_SCHEMA TABLES_EXTENSIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-tablespaces-extensions-table.html">
28.3.40 The INFORMATION_SCHEMA TABLESPACES_EXTENSIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-table-constraints-table.html">
28.3.41 The INFORMATION_SCHEMA TABLE_CONSTRAINTS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-table-constraints-extensions-table.html">
28.3.42 The INFORMATION_SCHEMA TABLE_CONSTRAINTS_EXTENSIONS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-table-privileges-table.html">
28.3.43 The INFORMATION_SCHEMA TABLE_PRIVILEGES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-triggers-table.html">
28.3.44 The INFORMATION_SCHEMA TRIGGERS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-user-attributes-table.html">
28.3.45 The INFORMATION_SCHEMA USER_ATTRIBUTES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-user-privileges-table.html">
28.3.46 The INFORMATION_SCHEMA USER_PRIVILEGES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-views-table.html">
28.3.47 The INFORMATION_SCHEMA VIEWS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-view-routine-usage-table.html">
28.3.48 The INFORMATION_SCHEMA VIEW_ROUTINE_USAGE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-view-table-usage-table.html">
28.3.49 The INFORMATION_SCHEMA VIEW_TABLE_USAGE Table
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="innodb-information-schema-tables.html">
28.4 INFORMATION_SCHEMA InnoDB Tables
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="information-schema-innodb-table-reference.html">
28.4.1 INFORMATION_SCHEMA InnoDB Table Reference
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-buffer-page-table.html">
28.4.2 The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-buffer-page-lru-table.html">
28.4.3 The INFORMATION_SCHEMA INNODB_BUFFER_PAGE_LRU Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-buffer-pool-stats-table.html">
28.4.4 The INFORMATION_SCHEMA INNODB_BUFFER_POOL_STATS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-cached-indexes-table.html">
28.4.5 The INFORMATION_SCHEMA INNODB_CACHED_INDEXES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-cmp-table.html">
28.4.6 The INFORMATION_SCHEMA INNODB_CMP and INNODB_CMP_RESET Tables
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-cmpmem-table.html">
28.4.7 The INFORMATION_SCHEMA INNODB_CMPMEM and INNODB_CMPMEM_RESET Tables
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-cmp-per-index-table.html">
28.4.8 The INFORMATION_SCHEMA INNODB_CMP_PER_INDEX and
INNODB_CMP_PER_INDEX_RESET Tables
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-columns-table.html">
28.4.9 The INFORMATION_SCHEMA INNODB_COLUMNS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-datafiles-table.html">
28.4.10 The INFORMATION_SCHEMA INNODB_DATAFILES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-fields-table.html">
28.4.11 The INFORMATION_SCHEMA INNODB_FIELDS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-foreign-table.html">
28.4.12 The INFORMATION_SCHEMA INNODB_FOREIGN Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-foreign-cols-table.html">
28.4.13 The INFORMATION_SCHEMA INNODB_FOREIGN_COLS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-ft-being-deleted-table.html">
28.4.14 The INFORMATION_SCHEMA INNODB_FT_BEING_DELETED Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-ft-config-table.html">
28.4.15 The INFORMATION_SCHEMA INNODB_FT_CONFIG Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-ft-default-stopword-table.html">
28.4.16 The INFORMATION_SCHEMA INNODB_FT_DEFAULT_STOPWORD Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-ft-deleted-table.html">
28.4.17 The INFORMATION_SCHEMA INNODB_FT_DELETED Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-ft-index-cache-table.html">
28.4.18 The INFORMATION_SCHEMA INNODB_FT_INDEX_CACHE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-ft-index-table-table.html">
28.4.19 The INFORMATION_SCHEMA INNODB_FT_INDEX_TABLE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-indexes-table.html">
28.4.20 The INFORMATION_SCHEMA INNODB_INDEXES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-metrics-table.html">
28.4.21 The INFORMATION_SCHEMA INNODB_METRICS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-session-temp-tablespaces-table.html">
28.4.22 The INFORMATION_SCHEMA INNODB_SESSION_TEMP_TABLESPACES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-tables-table.html">
28.4.23 The INFORMATION_SCHEMA INNODB_TABLES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-tablespaces-table.html">
28.4.24 The INFORMATION_SCHEMA INNODB_TABLESPACES Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-tablespaces-brief-table.html">
28.4.25 The INFORMATION_SCHEMA INNODB_TABLESPACES_BRIEF Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-tablestats-table.html">
28.4.26 The INFORMATION_SCHEMA INNODB_TABLESTATS View
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-temp-table-info-table.html">
28.4.27 The INFORMATION_SCHEMA INNODB_TEMP_TABLE_INFO Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-trx-table.html">
28.4.28 The INFORMATION_SCHEMA INNODB_TRX Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-innodb-virtual-table.html">
28.4.29 The INFORMATION_SCHEMA INNODB_VIRTUAL Table
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="thread-pool-information-schema-tables.html">
28.5 INFORMATION_SCHEMA Thread Pool Tables
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="information-schema-thread-pool-table-reference.html">
28.5.1 INFORMATION_SCHEMA Thread Pool Table Reference
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-tp-thread-group-state-table.html">
28.5.2 The INFORMATION_SCHEMA TP_THREAD_GROUP_STATE Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-tp-thread-group-stats-table.html">
28.5.3 The INFORMATION_SCHEMA TP_THREAD_GROUP_STATS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-tp-thread-state-table.html">
28.5.4 The INFORMATION_SCHEMA TP_THREAD_STATE Table
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="connection-control-information-schema-tables.html">
28.6 INFORMATION_SCHEMA Connection-Control Tables
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="information-schema-connection-control-table-reference.html">
28.6.1 INFORMATION_SCHEMA Connection-Control Table Reference
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-connection-control-failed-login-attempts-table.html">
28.6.2 The INFORMATION_SCHEMA CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS Table
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="firewall-information-schema-tables.html">
28.7 INFORMATION_SCHEMA MySQL Enterprise Firewall Tables
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="information-schema-firewall-table-reference.html">
28.7.1 INFORMATION_SCHEMA Firewall Table Reference
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-mysql-firewall-users-table.html">
28.7.2 The INFORMATION_SCHEMA MYSQL_FIREWALL_USERS Table
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="information-schema-mysql-firewall-whitelist-table.html">
28.7.3 The INFORMATION_SCHEMA MYSQL_FIREWALL_WHITELIST Table
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="extended-show.html">
28.8 Extensions to SHOW Statements
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045081058336">
</a>
<a class="indexterm" name="idm46045081056880">
</a>
<a class="indexterm" name="idm46045081055808">
</a>
<a class="indexterm" name="idm46045081054736">
</a>
<a class="indexterm" name="idm46045081053664">
</a>
<p>
<code class="literal">
INFORMATION_SCHEMA
</code>
provides access to database
<span class="firstterm">
metadata
</span>
, information about
the MySQL server such as the name of a database or table, the data
type of a column, or access privileges. Other terms that are
sometimes used for this information are
<span class="firstterm">
data dictionary
</span>
and
<span class="firstterm">
system catalog
</span>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/myisam-crash-recovery.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="myisam-crash-recovery">
</a>
9.6.1 Using myisamchk for Crash Recovery
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045230673632">
</a>
<a class="indexterm" name="idm46045230672176">
</a>
<a class="indexterm" name="idm46045230670688">
</a>
<a class="indexterm" name="idm46045230669616">
</a>
<p>
This section describes how to check for and deal with data
corruption in MySQL databases. If your tables become corrupted
frequently, you should try to find the reason why. See
<a class="xref" href="crashing.html" title="B.3.3.3 What to Do If MySQL Keeps Crashing">
Section B.3.3.3, “What to Do If MySQL Keeps Crashing”
</a>
.
</p>
<p>
For an explanation of how
<code class="literal">
MyISAM
</code>
tables can
become corrupted, see
<a class="xref" href="myisam-table-problems.html" title="18.2.4 MyISAM Table Problems">
Section 18.2.4, “MyISAM Table Problems”
</a>
.
</p>
<p>
If you run
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with external locking
disabled (which is the default), you cannot reliably use
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
to check a table when
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
is using the same table. If you can be
certain that no one can access the tables using
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
while you run
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
, you only have to execute
<a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
<span class="command">
<strong>
mysqladmin flush-tables
</strong>
</span>
</a>
before you start
checking the tables. If you cannot guarantee this, you must stop
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
while you check the tables. If you run
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
to check tables that
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
is updating at the same time, you may
get a warning that a table is corrupt even when it is not.
</p>
<p>
If the server is run with external locking enabled, you can use
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
to check tables at any time. In
this case, if the server tries to update a table that
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
is using, the server waits for
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
to finish before it continues.
</p>
<p>
If you use
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
to repair or optimize
tables, you
<span class="emphasis">
<em>
must
</em>
</span>
always ensure that 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 not using the table (this
also applies if external locking is disabled). If you do not
stop
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
, you should at least do a
<a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
<span class="command">
<strong>
mysqladmin flush-tables
</strong>
</span>
</a>
before you run
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
. Your tables
<span class="emphasis">
<em>
may become
corrupted
</em>
</span>
if the server and
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
access the tables simultaneously.
</p>
<p>
When performing crash recovery, it is important to understand
that each
<code class="literal">
MyISAM
</code>
table
<em class="replaceable">
<code>
tbl_name
</code>
</em>
in a database corresponds to
the three files in the database directory shown in the following
table.
</p>
<div class="informaltable">
<table summary="The two files in the database directory that correspond to each MyISAM table.">
<colgroup>
<col style="width: 20%"/>
<col style="width: 40%"/>
</colgroup>
<thead>
<tr>
<th>
File
</th>
<th>
Purpose
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="filename">
<em class="replaceable">
<code>
tbl_name
</code>
</em>
.MYD
</code>
</td>
<td>
Data file
</td>
</tr>
<tr>
<td>
<code class="filename">
<em class="replaceable">
<code>
tbl_name
</code>
</em>
.MYI
</code>
</td>
<td>
Index file
</td>
</tr>
</tbody>
</table>
</div>
<p>
Each of these three file types is subject to corruption in
various ways, but problems occur most often in data files and
index files.
</p>
<p>
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
works by creating a copy of the
<code class="filename">
.MYD
</code>
data file row by row. It ends the
repair stage by removing the old
<code class="filename">
.MYD
</code>
file
and renaming the new file to the original file name. If you use
<a class="link" href="myisamchk-repair-options.html#option_myisamchk_quick">
<code class="option">
--quick
</code>
</a>
,
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
does not create a temporary
<code class="filename">
.MYD
</code>
file, but instead assumes that the
<code class="filename">
.MYD
</code>
file is correct and generates only a
new index file without touching the
<code class="filename">
.MYD
</code>
file. This is safe, because
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
automatically detects whether the
<code class="filename">
.MYD
</code>
file
is corrupt and aborts the repair if it is. You can also specify
the
<a class="link" href="myisamchk-repair-options.html#option_myisamchk_quick">
<code class="option">
--quick
</code>
</a>
option twice to
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
. In this case,
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
does not abort on some errors (such
as duplicate-key errors) but instead tries to resolve them by
modifying the
<code class="filename">
.MYD
</code>
file. Normally the use
of two
<a class="link" href="myisamchk-repair-options.html#option_myisamchk_quick">
<code class="option">
--quick
</code>
</a>
options is
useful only if you have too little free disk space to perform a
normal repair. In this case, you should at least make a backup
of the table before running
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk
</strong>
</span>
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/descending-indexes.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="descending-indexes">
</a>
10.3.13 Descending Indexes
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045226971456">
</a>
<a class="indexterm" name="idm46045226970384">
</a>
<p>
MySQL supports descending indexes:
<code class="literal">
DESC
</code>
in an
index definition is no longer ignored but causes storage of key
values in descending order. Previously, indexes could be scanned
in reverse order but at a performance penalty. A descending
index can be scanned in forward order, which is more efficient.
Descending indexes also make it possible for the optimizer to
use multiple-column indexes when the most efficient scan order
mixes ascending order for some columns and descending order for
others.
</p>
<p>
Consider the following table definition, which contains two
columns and four two-column index definitions for the various
combinations of ascending and descending indexes on the columns:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17229852"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">INT</span><span class="token punctuation">,</span> c2 <span class="token datatype">INT</span><span class="token punctuation">,</span>
<span class="token keyword">INDEX</span> idx1 <span class="token punctuation">(</span>c1 <span class="token keyword">ASC</span><span class="token punctuation">,</span> c2 <span class="token keyword">ASC</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">INDEX</span> idx2 <span class="token punctuation">(</span>c1 <span class="token keyword">ASC</span><span class="token punctuation">,</span> c2 <span class="token keyword">DESC</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">INDEX</span> idx3 <span class="token punctuation">(</span>c1 <span class="token keyword">DESC</span><span class="token punctuation">,</span> c2 <span class="token keyword">ASC</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">INDEX</span> idx4 <span class="token punctuation">(</span>c1 <span class="token keyword">DESC</span><span class="token punctuation">,</span> c2 <span class="token keyword">DESC</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The table definition results in four distinct indexes. The
optimizer can perform a forward index scan for each of the
<code class="literal">
ORDER BY
</code>
clauses and need not use a
<code class="literal">
filesort
</code>
operation:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25190182"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">ORDER</span> <span class="token keyword">BY</span> c1 <span class="token keyword">ASC</span><span class="token punctuation">,</span> c2 <span class="token keyword">ASC</span> <span class="token comment" spellcheck="true">-- optimizer can use idx1</span>
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> c1 <span class="token keyword">DESC</span><span class="token punctuation">,</span> c2 <span class="token keyword">DESC</span> <span class="token comment" spellcheck="true">-- optimizer can use idx4</span>
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> c1 <span class="token keyword">ASC</span><span class="token punctuation">,</span> c2 <span class="token keyword">DESC</span> <span class="token comment" spellcheck="true">-- optimizer can use idx2</span>
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> c1 <span class="token keyword">DESC</span><span class="token punctuation">,</span> c2 <span class="token keyword">ASC</span> <span class="token comment" spellcheck="true">-- optimizer can use idx3</span></code></pre>
</div>
<p>
Use of descending indexes is subject to these conditions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Descending indexes are supported only for the
<code class="literal">
InnoDB
</code>
storage engine, with these
limitations:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
Change buffering is not supported for a secondary index
if the index contains a descending index key column or
if the primary key includes a descending index column.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
InnoDB
</code>
SQL parser does not use
descending indexes. For
<code class="literal">
InnoDB
</code>
full-text search, this means that the index required on
the
<code class="literal">
FTS_DOC_ID
</code>
column of the indexed
table cannot be defined as a descending index. For more
information, see
<a class="xref" href="innodb-fulltext-index.html" title="17.6.2.4 InnoDB Full-Text Indexes">
Section 17.6.2.4, “InnoDB Full-Text Indexes”
</a>
.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
Descending indexes are supported for all data types for
which ascending indexes are available.
</p>
</li>
<li class="listitem">
<p>
Descending indexes are supported for ordinary (nongenerated)
and generated columns (both
<code class="literal">
VIRTUAL
</code>
and
<code class="literal">
STORED
</code>
).
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
DISTINCT
</code>
can use any index containing
matching columns, including descending key parts.
</p>
</li>
<li class="listitem">
<p>
Indexes that have descending key parts are not used for
<a class="link" href="aggregate-functions.html#function_min">
<code class="literal">
MIN()
</code>
</a>
/
<a class="link" href="aggregate-functions.html#function_max">
<code class="literal">
MAX()
</code>
</a>
optimization of queries that invoke aggregate functions but
do not have a
<code class="literal">
GROUP BY
</code>
clause.
</p>
</li>
<li class="listitem">
<p>
Descending indexes are supported for
<code class="literal">
BTREE
</code>
but not
<code class="literal">
HASH
</code>
indexes. Descending indexes are not supported for
<code class="literal">
FULLTEXT
</code>
or
<code class="literal">
SPATIAL
</code>
indexes.
</p>
<p>
Explicitly specified
<code class="literal">
ASC
</code>
and
<code class="literal">
DESC
</code>
designators for
<code class="literal">
HASH
</code>
,
<code class="literal">
FULLTEXT
</code>
, and
<code class="literal">
SPATIAL
</code>
indexes results in an error.
</p>
</li>
</ul>
</div>
<p>
You can see in the
<strong class="userinput">
<code>
Extra
</code>
</strong>
column of the
output of
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
that the
optimizer is able to use a descending index, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58505571"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1 <span class="token punctuation">(</span>
<span class="token prompt"> -></span> a <span class="token datatype">INT</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> b <span class="token datatype">INT</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> <span class="token keyword">INDEX</span> a_desc_b_asc <span class="token punctuation">(</span>a <span class="token keyword">DESC</span><span class="token punctuation">,</span> b <span class="token keyword">ASC</span><span class="token punctuation">)</span>
<span class="token prompt"> -></span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></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">ORDER</span> <span class="token keyword">BY</span> a <span class="token keyword">ASC</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> t1
partitions<span class="token punctuation">:</span> NULL
type<span class="token punctuation">:</span> index
possible_keys<span class="token punctuation">:</span> NULL
key<span class="token punctuation">:</span> a_desc_b_asc
key_len<span class="token punctuation">:</span> 10
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> Backward index scan; Using index</span></code></pre>
</div>
<p>
In
<code class="literal">
EXPLAIN FORMAT=TREE
</code>
output, use of a
descending index is indicated by the addition of
<code class="literal">
(reverse)
</code>
following the name of the index,
like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96342315"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">EXPLAIN</span> <span class="token keyword">FORMAT</span><span class="token operator">=</span><span class="token keyword">TREE</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t1 <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> a <span class="token keyword">ASC</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>
EXPLAIN<span class="token punctuation">:</span> -> Index scan on t1 using a_desc_b_asc (reverse) (cost=0.35 rows=1)</span></code></pre>
</div>
<p>
See also
<a class="xref" href="explain-output.html#explain-extra-information" title="EXPLAIN Extra Information">
EXPLAIN Extra Information
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-features-load-data.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="replication-features-load-data">
</a>
19.5.1.19 Replication and LOAD DATA
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045135393328">
</a>
<a class="indexterm" name="idm46045135391840">
</a>
<p>
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
is considered unsafe
for statement-based logging (see
<a class="xref" href="replication-rbr-safe-unsafe.html" title="19.2.1.3 Determination of Safe and Unsafe Statements in Binary Logging">
Section 19.2.1.3, “Determination of Safe and Unsafe Statements in Binary Logging”
</a>
). When
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
<code class="literal">
binlog_format=MIXED
</code>
</a>
is set, 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>
is set,
note that
<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>
<p>
If you use
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
with
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
<code class="literal">
binlog_format=STATEMENT
</code>
</a>
, each
replica on which the changes are to be applied creates a
temporary file containing the data. The replica then uses a
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
statement to apply the
changes. This temporary file is not encrypted, even if binary
log encryption is active on the source, If encryption is
required, use row-based or mixed binary logging format instead,
for which replicas do not create the temporary file.
</p>
<p>
If a
<code class="literal">
PRIVILEGE_CHECKS_USER
</code>
account has been
used to help secure the replication channel (see
<a class="xref" href="replication-privilege-checks.html" title="19.3.3 Replication Privilege Checks">
Section 19.3.3, “Replication Privilege Checks”
</a>
), it is strongly
recommended that you log
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD
DATA
</code>
</a>
operations using row-based binary logging
(
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
<code class="literal">
binlog_format=ROW
</code>
</a>
). If
<code class="literal">
REQUIRE_ROW_FORMAT
</code>
is set for the channel,
row-based binary logging is required. 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.
If you need to recover from a replication error involving a
<code class="literal">
LOAD DATA INFILE
</code>
operation logged in
statement format, and the replicated event is trusted, you could
grant the
<a class="link" href="privileges-provided.html#priv_file">
<code class="literal">
FILE
</code>
</a>
privilege to the
<code class="literal">
PRIVILEGE_CHECKS_USER
</code>
account temporarily,
removing it after the replicated event has been applied.
</p>
<p>
When
<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>
reads log events for
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
statements logged in
statement-based format, a generated local file is created in a
temporary directory. These temporary files are not automatically
removed by
<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>
or any other MySQL
program. If you do use
<a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
statements with statement-based binary logging, you should
delete the temporary files yourself after you no longer need the
statement log. For more information, see
<a class="xref" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
Section 6.6.9, “mysqlbinlog — Utility for Processing Binary Log Files”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/sys-ps-is-instrument-default-enabled.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="sys-ps-is-instrument-default-enabled">
</a>
30.4.5.11 The ps_is_instrument_default_enabled() Function
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045060856960">
</a>
<a class="indexterm" name="idm46045060855440">
</a>
<p>
Returns
<code class="literal">
YES
</code>
or
<code class="literal">
NO
</code>
to
indicate whether a given Performance Schema instrument is
enabled by default.
</p>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="sys-ps-is-instrument-default-enabled-parameters">
</a>
Parameters
</h5>
</div>
</div>
</div>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
in_instrument VARCHAR(128)
</code>
: The name
of the instrument to check.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="sys-ps-is-instrument-default-enabled-return-value">
</a>
Return Value
</h5>
</div>
</div>
</div>
<p>
An
<code class="literal">
ENUM('YES','NO')
</code>
value.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="sys-ps-is-instrument-default-enabled-example">
</a>
Example
</h5>
</div>
</div>
</div>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88078508"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> sys<span class="token punctuation">.</span>ps_is_instrument_default_enabled<span class="token punctuation">(</span><span class="token string">'memory/innodb/row_log_buf'</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 class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> sys.ps_is_instrument_default_enabled('memory/innodb/row_log_buf') <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>
<span class="token output"><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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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></span> <span class="token keyword">SELECT</span> sys<span class="token punctuation">.</span>ps_is_instrument_default_enabled<span class="token punctuation">(</span><span class="token string">'statement/sql/alter_user'</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> sys.ps_is_instrument_default_enabled('statement/sql/alter_user') <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> YES <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>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/connection-management.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="connection-management">
</a>
7.1.12 Connection Management
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="connection-interfaces.html">
7.1.12.1 Connection Interfaces
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="administrative-connection-interface.html">
7.1.12.2 Administrative Connection Management
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="host-cache.html">
7.1.12.3 DNS Lookups and the Host Cache
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045261024528">
</a>
<p>
This section describes how MySQL Server manages connections. This
includes a description of the available connection interfaces, how
the server uses connection handler threads, details about the
administrative connection interface, and management of DNS
lookups.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysqldumpslow.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="mysqldumpslow">
</a>
6.6.10 mysqldumpslow — Summarize Slow Query Log Files
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045303261776">
</a>
<p>
The MySQL slow query log contains information about queries that
take a long time to execute (see
<a class="xref" href="slow-query-log.html" title="7.4.5 The Slow Query Log">
Section 7.4.5, “The Slow Query Log”
</a>
).
<a class="link" href="mysqldumpslow.html" title="6.6.10 mysqldumpslow — Summarize Slow Query Log Files">
<span class="command">
<strong>
mysqldumpslow
</strong>
</span>
</a>
parses MySQL slow query log
files and summarizes their contents.
</p>
<p>
Normally,
<a class="link" href="mysqldumpslow.html" title="6.6.10 mysqldumpslow — Summarize Slow Query Log Files">
<span class="command">
<strong>
mysqldumpslow
</strong>
</span>
</a>
groups queries that
are similar except for the particular values of number and
string data values. It
<span class="quote">
“
<span class="quote">
abstracts
</span>
”
</span>
these values to
<code class="literal">
N
</code>
and
<code class="literal">
'S'
</code>
when displaying
summary output. To modify value abstracting behavior, use the
<code class="option">
-a
</code>
and
<code class="option">
-n
</code>
options.
</p>
<p>
Invoke
<a class="link" href="mysqldumpslow.html" title="6.6.10 mysqldumpslow — Summarize Slow Query Log Files">
<span class="command">
<strong>
mysqldumpslow
</strong>
</span>
</a>
like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa24234909"><div class="copy-help left">Press ⌘+C to 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">mysqldumpslow <span class="token punctuation">[</span><em class="replaceable">options</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">log_file</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>
Example output with no options given:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa28154501"><div class="copy-help left">Press ⌘+C to 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">Reading mysql slow query log from /usr/local/mysql/data/mysqld84-slow<span class="token punctuation">.</span>log
Count<span class="token punctuation">:</span> 1 Time<span class="token attr-value"><span class="token punctuation">=</span>4.32s</span> <span class="token punctuation">(</span>4s<span class="token punctuation">)</span> Lock<span class="token attr-value"><span class="token punctuation">=</span>0.00s</span> <span class="token punctuation">(</span>0s<span class="token punctuation">)</span> Rows<span class="token attr-value"><span class="token punctuation">=</span>0.0</span> <span class="token punctuation">(</span>0<span class="token punctuation">)</span><span class="token punctuation">,</span> root<span class="token punctuation">[</span>root<span class="token punctuation">]</span>@localhost
insert into t2 select * from t1
Count<span class="token punctuation">:</span> 3 Time<span class="token attr-value"><span class="token punctuation">=</span>2.53s</span> <span class="token punctuation">(</span>7s<span class="token punctuation">)</span> Lock<span class="token attr-value"><span class="token punctuation">=</span>0.00s</span> <span class="token punctuation">(</span>0s<span class="token punctuation">)</span> Rows<span class="token attr-value"><span class="token punctuation">=</span>0.0</span> <span class="token punctuation">(</span>0<span class="token punctuation">)</span><span class="token punctuation">,</span> root<span class="token punctuation">[</span>root<span class="token punctuation">]</span>@localhost
insert into t2 select * from t1 limit N
Count<span class="token punctuation">:</span> 3 Time<span class="token attr-value"><span class="token punctuation">=</span>2.13s</span> <span class="token punctuation">(</span>6s<span class="token punctuation">)</span> Lock<span class="token attr-value"><span class="token punctuation">=</span>0.00s</span> <span class="token punctuation">(</span>0s<span class="token punctuation">)</span> Rows<span class="token attr-value"><span class="token punctuation">=</span>0.0</span> <span class="token punctuation">(</span>0<span class="token punctuation">)</span><span class="token punctuation">,</span> root<span class="token punctuation">[</span>root<span class="token punctuation">]</span>@localhost
insert into t1 select * from t1</code></pre>
</div>
<p>
<a class="link" href="mysqldumpslow.html" title="6.6.10 mysqldumpslow — Summarize Slow Query Log Files">
<span class="command">
<strong>
mysqldumpslow
</strong>
</span>
</a>
supports the following options.
</p>
<div class="table">
<a name="idm46045303246784">
</a>
<p class="title">
<b>
Table 6.21 mysqldumpslow Options
</b>
</p>
<div class="table-contents">
<table frame="box" rules="all" summary="Command-line options available for mysqldumpslow.">
<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="mysqldumpslow.html#option_mysqldumpslow_abstract">
-a
</a>
</td>
<td>
Do not abstract all numbers to N and strings to 'S'
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_abstract-numbers">
-n
</a>
</td>
<td>
Abstract numbers with at least the specified digits
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_debug">
--debug
</a>
</td>
<td>
Write debugging information
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_grep">
-g
</a>
</td>
<td>
Only consider statements that match the pattern
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_help">
--help
</a>
</td>
<td>
Display help message and exit
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_host">
-h
</a>
</td>
<td>
Host name of the server in the log file name
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_instance">
-i
</a>
</td>
<td>
Name of the server instance
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_lock">
-l
</a>
</td>
<td>
Do not subtract lock time from total time
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_reverse">
-r
</a>
</td>
<td>
Reverse the sort order
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_sort">
-s
</a>
</td>
<td>
How to sort output
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_top">
-t
</a>
</td>
<td>
Display only first num queries
</td>
</tr>
<tr>
<td>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_verbose">
--verbose
</a>
</td>
<td>
Verbose mode
</td>
</tr>
</tbody>
</table>
</div>
<div class="table-contents">
<table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 502px;">
<thead>
<tr>
<th style="width: 177.094px;">
Option Name
</th>
<th style="width: 323.844px;">
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_mysqldumpslow_help">
</a>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_help">
<code class="option">
--help
</code>
</a>
</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="idm46045303200112">
</a>
<a class="indexterm" name="idm46045303198624">
</a>
<p>
Display a help message and exit.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_abstract">
</a>
<code class="option">
-a
</code>
</p>
<p>
Do not abstract all numbers to
<code class="literal">
N
</code>
and
strings to
<code class="literal">
'S'
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_debug">
</a>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_debug">
<code class="option">
--debug
</code>
</a>
,
<code class="option">
-d
</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
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303185168">
</a>
<a class="indexterm" name="idm46045303183680">
</a>
<p>
Run in debug mode.
</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_mysqldumpslow_grep">
</a>
<code class="option">
-g
<em class="replaceable">
<code>
pattern
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for grep">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303172864">
</a>
<a class="indexterm" name="idm46045303171376">
</a>
<p>
Consider only queries that match the
(
<span class="command">
<strong>
grep
</strong>
</span>
-style) pattern.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_host">
</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>
Type
</th>
<td>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
*
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303159264">
</a>
<a class="indexterm" name="idm46045303157776">
</a>
<p>
Host name of MySQL server for
<code class="filename">
*-slow.log
</code>
file name. The value can
contain a wildcard. The default is
<code class="literal">
*
</code>
(match all).
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_instance">
</a>
<code class="option">
-i
<em class="replaceable">
<code>
name
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for instance">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303147344">
</a>
<a class="indexterm" name="idm46045303145856">
</a>
<p>
Name of server instance (if using
<a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
<span class="command">
<strong>
mysql.server
</strong>
</span>
</a>
startup script).
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_lock">
</a>
<code class="option">
-l
</code>
</p>
<a class="indexterm" name="idm46045303141104">
</a>
<a class="indexterm" name="idm46045303139616">
</a>
<p>
Do not subtract lock time from total time.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_abstract-numbers">
</a>
<code class="option">
-n
<em class="replaceable">
<code>
N
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for abstract-numbers">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Type
</th>
<td>
Numeric
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303130736">
</a>
<a class="indexterm" name="idm46045303129248">
</a>
<p>
Abstract numbers with at least
<em class="replaceable">
<code>
N
</code>
</em>
digits within names.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_reverse">
</a>
<code class="option">
-r
</code>
</p>
<a class="indexterm" name="idm46045303125264">
</a>
<a class="indexterm" name="idm46045303123776">
</a>
<p>
Reverse the sort order.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_sort">
</a>
<code class="option">
-s
<em class="replaceable">
<code>
sort_type
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for sort">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Type
</th>
<td>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
at
</code>
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303112416">
</a>
<a class="indexterm" name="idm46045303110928">
</a>
<p>
How to sort the output. The value of
<em class="replaceable">
<code>
sort_type
</code>
</em>
should be chosen from
the following list:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
t
</code>
,
<code class="literal">
at
</code>
: Sort by
query time or average query time
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
l
</code>
,
<code class="literal">
al
</code>
: Sort by
lock time or average lock time
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
r
</code>
,
<code class="literal">
ar
</code>
: Sort by
rows sent or average rows sent
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
c
</code>
: Sort by count
</p>
</li>
</ul>
</div>
<p>
By default,
<a class="link" href="mysqldumpslow.html" title="6.6.10 mysqldumpslow — Summarize Slow Query Log Files">
<span class="command">
<strong>
mysqldumpslow
</strong>
</span>
</a>
sorts by
average query time (equivalent to
<code class="option">
-s at
</code>
).
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_top">
</a>
<code class="option">
-t
<em class="replaceable">
<code>
N
</code>
</em>
</code>
</p>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for top">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Type
</th>
<td>
Numeric
</td>
</tr>
</tbody>
</table>
</div>
<a class="indexterm" name="idm46045303090912">
</a>
<a class="indexterm" name="idm46045303089424">
</a>
<p>
Display only the first
<em class="replaceable">
<code>
N
</code>
</em>
queries
in the output.
</p>
</li>
<li class="listitem">
<p>
<a name="option_mysqldumpslow_verbose">
</a>
<a class="link" href="mysqldumpslow.html#option_mysqldumpslow_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="idm46045303078944">
</a>
<a class="indexterm" name="idm46045303077456">
</a>
<p>
Verbose mode. Print more information about what the program
does.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/sql-replication-statements.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="sql-replication-statements">
</a>
15.4 Replication Statements
</h2>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<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>
</div>
<p>
Replication can be controlled through the SQL interface using the
statements described in this section. Statements are split into a
group which controls source servers, a group which controls replica
servers, and a group which can be applied to any replication
servers.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/analyze-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="analyze-table">
</a>
15.7.3.1 ANALYZE TABLE Statement
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045172710672">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65445979"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">ANALYZE</span> <span class="token punctuation">[</span><span class="token keyword">NO_WRITE_TO_BINLOG</span> <span class="token operator">|</span> <span class="token keyword">LOCAL</span><span class="token punctuation">]</span>
<span class="token keyword">TABLE</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 keyword">ANALYZE</span> <span class="token punctuation">[</span><span class="token keyword">NO_WRITE_TO_BINLOG</span> <span class="token operator">|</span> <span class="token keyword">LOCAL</span><span class="token punctuation">]</span>
<span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em>
<span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</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 punctuation">[</span><span class="token keyword">WITH</span> <em class="replaceable">N</em> <span class="token keyword">BUCKETS</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span>{MANUAL <span class="token operator">|</span> AUTO} <span class="token keyword">UPDATE</span><span class="token punctuation">]</span>
<span class="token keyword">ANALYZE</span> <span class="token punctuation">[</span><span class="token keyword">NO_WRITE_TO_BINLOG</span> <span class="token operator">|</span> <span class="token keyword">LOCAL</span><span class="token punctuation">]</span>
<span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em>
<span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> <em class="replaceable">col_name</em> <span class="token punctuation">[</span><span class="token keyword">USING</span> <span class="token keyword">DATA</span> <span class="token string">'<em class="replaceable">json_data</em>'</span><span class="token punctuation">]</span>
<span class="token keyword">ANALYZE</span> <span class="token punctuation">[</span><span class="token keyword">NO_WRITE_TO_BINLOG</span> <span class="token operator">|</span> <span class="token keyword">LOCAL</span><span class="token punctuation">]</span>
<span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em>
<span class="token keyword">DROP</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</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></code></pre>
</div>
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
generates table
statistics:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
without any
<code class="literal">
HISTOGRAM
</code>
clause performs a key
distribution analysis and stores the distribution for the
named table or tables. For
<code class="literal">
MyISAM
</code>
tables,
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
for key
distribution analysis is equivalent to using
<a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
<span class="command">
<strong>
myisamchk --analyze
</strong>
</span>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
with the
<code class="literal">
UPDATE HISTOGRAM
</code>
clause generates
histogram statistics for the named table columns and stores
them in the data dictionary. Only one table name is
permitted with this syntax. MySQL also supports setting the
histogram of a single column to a user-defined JSON value.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
with the
<code class="literal">
DROP HISTOGRAM
</code>
clause removes histogram
statistics for the named table columns from the data
dictionary. Only one table name is permitted for this
syntax.
</p>
</li>
</ul>
</div>
<p>
This statement requires
<a class="link" href="privileges-provided.html#priv_select">
<code class="literal">
SELECT
</code>
</a>
and
<a class="link" href="privileges-provided.html#priv_insert">
<code class="literal">
INSERT
</code>
</a>
privileges for the
table.
</p>
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
works with
<code class="literal">
InnoDB
</code>
,
<code class="literal">
NDB
</code>
, and
<code class="literal">
MyISAM
</code>
tables. It does not work with views.
</p>
<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>
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
is supported for
partitioned tables, and you can use
<code class="literal">
ALTER TABLE ...
ANALYZE PARTITION
</code>
to analyze one or more partitions;
for more information, see
<a class="xref" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
Section 15.1.9, “ALTER TABLE Statement”
</a>
, and
<a class="xref" href="partitioning-maintenance.html" title="26.3.4 Maintenance of Partitions">
Section 26.3.4, “Maintenance of Partitions”
</a>
.
</p>
<p>
During the analysis, the table is locked with a read lock for
<code class="literal">
InnoDB
</code>
and
<code class="literal">
MyISAM
</code>
.
</p>
<p>
By default, the server writes
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE
TABLE
</code>
</a>
statements to the binary log so that they
replicate to replicas. To suppress logging, specify the optional
<code class="literal">
NO_WRITE_TO_BINLOG
</code>
keyword or its alias
<code class="literal">
LOCAL
</code>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="analyze-table.html#analyze-table-output" title="ANALYZE TABLE Output">
ANALYZE TABLE Output
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="analyze-table.html#analyze-table-key-distribution-analysis" title="Key Distribution Analysis">
Key Distribution Analysis
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="analyze-table.html#analyze-table-histogram-statistics-analysis" title="Histogram Statistics Analysis">
Histogram Statistics Analysis
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="analyze-table.html#analyze-table-other-considerations" title="Other Considerations">
Other Considerations
</a>
</p>
</li>
</ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="analyze-table-output">
</a>
ANALYZE TABLE Output
</h5>
</div>
</div>
</div>
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
returns a result
set with the columns shown in the following table.
</p>
<div class="informaltable">
<table summary="Columns of the ANALYZE TABLE result set.">
<colgroup>
<col style="width: 15%"/>
<col style="width: 60%"/>
</colgroup>
<thead>
<tr>
<th>
Column
</th>
<th>
Value
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code class="literal">
Table
</code>
</td>
<td>
The table name
</td>
</tr>
<tr>
<td>
<code class="literal">
Op
</code>
</td>
<td>
<code class="literal">
analyze
</code>
or
<code class="literal">
histogram
</code>
</td>
</tr>
<tr>
<td>
<code class="literal">
Msg_type
</code>
</td>
<td>
<code class="literal">
status
</code>
,
<code class="literal">
error
</code>
,
<code class="literal">
info
</code>
,
<code class="literal">
note
</code>
, or
<code class="literal">
warning
</code>
</td>
</tr>
<tr>
<td>
<code class="literal">
Msg_text
</code>
</td>
<td>
An informational message
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="analyze-table-key-distribution-analysis">
</a>
Key Distribution Analysis
</h5>
</div>
</div>
</div>
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
without either
<code class="literal">
HISTOGRAM
</code>
clause performs a key
distribution analysis and stores the distribution for the
table or tables. Any existing histogram statistics remain
unaffected.
</p>
<p>
If the table has not changed since the last key distribution
analysis, the table is not analyzed again.
</p>
<p>
MySQL uses the stored key distribution to decide the order in
which tables should be joined for joins on something other
than a constant. In addition, key distributions can be used
when deciding which indexes to use for a specific table within
a query.
</p>
<p>
To check the stored key distribution cardinality, use the
<a class="link" href="show-index.html" title="15.7.7.23 SHOW INDEX Statement">
<code class="literal">
SHOW INDEX
</code>
</a>
statement or the
<code class="literal">
INFORMATION_SCHEMA
</code>
<a class="link" href="information-schema-statistics-table.html" title="28.3.34 The INFORMATION_SCHEMA STATISTICS Table">
<code class="literal">
STATISTICS
</code>
</a>
table. 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>
, and
<a class="xref" href="information-schema-statistics-table.html" title="28.3.34 The INFORMATION_SCHEMA STATISTICS Table">
Section 28.3.34, “The INFORMATION_SCHEMA STATISTICS Table”
</a>
.
</p>
<p>
For
<code class="literal">
InnoDB
</code>
tables,
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
determines index
cardinality by performing random dives on each of the index
trees and updating index cardinality estimates accordingly.
Because these are only estimates, repeated runs of
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
could produce
different numbers. This makes
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE
TABLE
</code>
</a>
fast on
<code class="literal">
InnoDB
</code>
tables but
not 100% accurate because it does not take all rows into
account.
</p>
<p>
You can make the
<a class="link" href="glossary.html#glos_statistics" title="statistics">
statistics
</a>
collected by
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
more precise and
more stable by enabling
<a class="link" href="innodb-parameters.html#sysvar_innodb_stats_persistent">
<code class="literal">
innodb_stats_persistent
</code>
</a>
, as
explained in
<a class="xref" href="innodb-persistent-stats.html" title="17.8.10.1 Configuring Persistent Optimizer Statistics Parameters">
Section 17.8.10.1, “Configuring Persistent Optimizer Statistics Parameters”
</a>
. When
<a class="link" href="innodb-parameters.html#sysvar_innodb_stats_persistent">
<code class="literal">
innodb_stats_persistent
</code>
</a>
is
enabled, it is important to run
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE
TABLE
</code>
</a>
after major changes to index column data, as
statistics are not recalculated periodically (such as after a
server restart).
</p>
<p>
If
<a class="link" href="innodb-parameters.html#sysvar_innodb_stats_persistent">
<code class="literal">
innodb_stats_persistent
</code>
</a>
is
enabled, you can change the number of random dives by
modifying the
<a class="link" href="innodb-parameters.html#sysvar_innodb_stats_persistent_sample_pages">
<code class="literal">
innodb_stats_persistent_sample_pages
</code>
</a>
system variable. If
<a class="link" href="innodb-parameters.html#sysvar_innodb_stats_persistent">
<code class="literal">
innodb_stats_persistent
</code>
</a>
is
disabled, modify
<a class="link" href="innodb-parameters.html#sysvar_innodb_stats_transient_sample_pages">
<code class="literal">
innodb_stats_transient_sample_pages
</code>
</a>
instead.
</p>
<p>
For more information about key distribution analysis in
<code class="literal">
InnoDB
</code>
, see
<a class="xref" href="innodb-persistent-stats.html" title="17.8.10.1 Configuring Persistent Optimizer Statistics Parameters">
Section 17.8.10.1, “Configuring Persistent Optimizer Statistics Parameters”
</a>
, and
<a class="xref" href="innodb-analyze-table-complexity.html" title="17.8.10.3 Estimating ANALYZE TABLE Complexity for InnoDB Tables">
Section 17.8.10.3, “Estimating ANALYZE TABLE Complexity for InnoDB Tables”
</a>
.
</p>
<p>
MySQL uses index cardinality estimates in join optimization.
If a join is not optimized in the right way, try running
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
. In the few cases
that
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
does not
produce values good enough for your particular tables, you can
use
<code class="literal">
FORCE INDEX
</code>
with your queries to force
the use of a particular index, or set the
<a class="link" href="server-system-variables.html#sysvar_max_seeks_for_key">
<code class="literal">
max_seeks_for_key
</code>
</a>
system
variable to ensure that MySQL prefers index lookups over table
scans. See
<a class="xref" href="optimizer-issues.html" title="B.3.5 Optimizer-Related Issues">
Section B.3.5, “Optimizer-Related Issues”
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="analyze-table-histogram-statistics-analysis">
</a>
Histogram Statistics Analysis
</h5>
</div>
</div>
</div>
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
with the
<code class="literal">
HISTOGRAM
</code>
clause enables management of
histogram statistics for table column values. For information
about histogram statistics, see
<a class="xref" href="optimizer-statistics.html" title="10.9.6 Optimizer Statistics">
Section 10.9.6, “Optimizer Statistics”
</a>
.
</p>
<p>
These histogram operations are available:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
with an
<code class="literal">
UPDATE HISTOGRAM
</code>
clause generates
histogram statistics for the named table columns and
stores them in the data dictionary. Only one table name is
permitted for this syntax.
</p>
<p>
The optional
<code class="literal">
WITH
<em class="replaceable">
<code>
N
</code>
</em>
BUCKETS
</code>
clause specifies the number of buckets
for the histogram. The value of
<em class="replaceable">
<code>
N
</code>
</em>
must be an integer in the
range from 1 to 1024. If this clause is omitted, the
number of buckets is 100.
</p>
<p>
The optional
<code class="literal">
AUTO UPDATE
</code>
clause enables
automatic updates of histograms on the table. When
enabled, an
<code class="literal">
ANALYZE TABLE
</code>
statement on
this table automatically updates the histogram, using the
same number of buckets as last specified by
<code class="literal">
WITH
... BUCKETS
</code>
if this was previously set for this
table. In addition, when recalculating persistent
statistics for the table (see
<a class="xref" href="innodb-persistent-stats.html" title="17.8.10.1 Configuring Persistent Optimizer Statistics Parameters">
Section 17.8.10.1, “Configuring Persistent Optimizer Statistics Parameters”
</a>
), the
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
background statistics
thread also updates the histogram.
<code class="literal">
MANUAL
UPDATE
</code>
disables automatic updates, and is the
default setting if not specified.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE TABLE
</code>
</a>
with a
<code class="literal">
DROP HISTOGRAM
</code>
clause removes histogram
statistics for the named table columns from the data
dictionary. Only one table name is permitted for this
syntax.
</p>
</li>
</ul>
</div>
<p>
Stored histogram management statements affect only the named
columns. Consider these statements:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa1154591"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">ANALYZE</span> <span class="token keyword">TABLE</span> t <span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> c1<span class="token punctuation">,</span> c2<span class="token punctuation">,</span> c3 <span class="token keyword">WITH</span> <span class="token number">10</span> <span class="token keyword">BUCKETS</span><span class="token punctuation">;</span>
<span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> t <span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> c1<span class="token punctuation">,</span> c3 <span class="token keyword">WITH</span> <span class="token number">10</span> <span class="token keyword">BUCKETS</span><span class="token punctuation">;</span>
<span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> t <span class="token keyword">DROP</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> c2<span class="token punctuation">;</span></code></pre>
</div>
<p>
The first statement updates the histograms for columns
<code class="literal">
c1
</code>
,
<code class="literal">
c2
</code>
, and
<code class="literal">
c3
</code>
, replacing any existing histograms for
those columns. The second statement updates the histograms for
<code class="literal">
c1
</code>
and
<code class="literal">
c3
</code>
, leaving the
<code class="literal">
c2
</code>
histogram unaffected. The third
statement removes the histogram for
<code class="literal">
c2
</code>
,
leaving those for
<code class="literal">
c1
</code>
and
<code class="literal">
c3
</code>
unaffected.
</p>
<p>
When sampling user data as part of building a histogram, not
all values are read; this may lead to missing some values
considered important. In such cases, it might be useful to
modify the histogram, or to set your own histogram explicitly
based on your own criteria, such as the complete data set.
<code class="literal">
ANALYZE TABLE
<em class="replaceable">
<code>
tbl_name
</code>
</em>
UPDATE HISTOGRAM ON
<em class="replaceable">
<code>
col_name
</code>
</em>
USING
DATA '
<em class="replaceable">
<code>
json_data
</code>
</em>
'
</code>
updates
a column of the histogram table with data supplied in the same
JSON format used to display
<code class="literal">
HISTOGRAM
</code>
column values from the Information Schema
<a class="link" href="information-schema-column-statistics-table.html" title="28.3.11 The INFORMATION_SCHEMA COLUMN_STATISTICS Table">
<code class="literal">
COLUMN_STATISTICS
</code>
</a>
table. Only one
column can be modified when updating the histogram with JSON
data.
</p>
<p>
We can illustrate the use of
<code class="literal">
USING DATA
</code>
by
first generating a histogram on column
<code class="literal">
c1
</code>
of table
<code class="literal">
t
</code>
, like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74049284"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> t <span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> c1<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 class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Table <span class="token punctuation">|</span> Op <span class="token punctuation">|</span> Msg_type <span class="token punctuation">|</span> Msg_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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> h.t <span class="token punctuation">|</span> histogram <span class="token punctuation">|</span> status <span class="token punctuation">|</span> Histogram statistics created for column '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 class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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>
We can see the histogram generated in the
<code class="literal">
COLUMN_STATISTICS
</code>
table:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa2514908"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">TABLE</span> information_schema<span class="token punctuation">.</span>column_statistics\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>
SCHEMA_NAME<span class="token punctuation">:</span> h
TABLE_NAME<span class="token punctuation">:</span> t
COLUMN_NAME<span class="token punctuation">:</span> c1
HISTOGRAM<span class="token punctuation">:</span> {"buckets"<span class="token punctuation">:</span> [], "data-type"<span class="token punctuation">:</span> "int", "auto-update"<span class="token punctuation">:</span> false,
"null-values"<span class="token punctuation">:</span> 0.0, "collation-id"<span class="token punctuation">:</span> 8, "last-updated"<span class="token punctuation">:</span> "2024-03-26
16<span class="token punctuation">:</span>54<span class="token punctuation">:</span>43.674995", "sampling-rate"<span class="token punctuation">:</span> 1.0, "histogram-type"<span class="token punctuation">:</span> "singleton",
"number-of-buckets-specified"<span class="token punctuation">:</span> 100}
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
Now we drop the histogram, and when we check
<code class="literal">
COLUMN_STATISTICS
</code>
, it is empty:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa62507846"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> t <span class="token keyword">DROP</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> c1<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 class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Table <span class="token punctuation">|</span> Op <span class="token punctuation">|</span> Msg_type <span class="token punctuation">|</span> Msg_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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> h.t <span class="token punctuation">|</span> histogram <span class="token punctuation">|</span> status <span class="token punctuation">|</span> Histogram statistics removed for column '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 class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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.01 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">TABLE</span> information_schema<span class="token punctuation">.</span>column_statistics\G
<span class="token output">Empty set (0.00 sec)</span></code></pre>
</div>
<p>
We can restore the dropped histogram by inserting its JSON
representation obtained previously from the
<code class="literal">
HISTOGRAM
</code>
column of the
<code class="literal">
COLUMN_STATISTICS
</code>
table, and when we query
that table again, we can see that the histogram has been
restored to its previous state:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa6553885"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> t <span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> c1
<span class="token prompt"> -></span> <span class="token keyword">USING</span> <span class="token keyword">DATA</span> <span class="token string">'{"buckets": [], "data-type": "int", "auto-update": false,
-> "null-values": 0.0, "collation-id": 8, "last-updated": "2024-03-26
-> 16:54:43.674995", "sampling-rate": 1.0, "histogram-type": "singleton",
-> "number-of-buckets-specified": 100}'</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 class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Table <span class="token punctuation">|</span> Op <span class="token punctuation">|</span> Msg_type <span class="token punctuation">|</span> Msg_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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> h.t <span class="token punctuation">|</span> histogram <span class="token punctuation">|</span> status <span class="token punctuation">|</span> Histogram statistics created for column '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 class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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></span> <span class="token keyword">TABLE</span> information_schema<span class="token punctuation">.</span>column_statistics\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>
SCHEMA_NAME<span class="token punctuation">:</span> h
TABLE_NAME<span class="token punctuation">:</span> t
COLUMN_NAME<span class="token punctuation">:</span> c1
HISTOGRAM<span class="token punctuation">:</span> {"buckets"<span class="token punctuation">:</span> [], "data-type"<span class="token punctuation">:</span> "int", "auto-update"<span class="token punctuation">:</span> false,
"null-values"<span class="token punctuation">:</span> 0.0, "collation-id"<span class="token punctuation">:</span> 8, "last-updated"<span class="token punctuation">:</span> "2024-03-26
16<span class="token punctuation">:</span>54<span class="token punctuation">:</span>43.674995", "sampling-rate"<span class="token punctuation">:</span> 1.0, "histogram-type"<span class="token punctuation">:</span> "singleton",
"number-of-buckets-specified"<span class="token punctuation">:</span> 100}</span></code></pre>
</div>
<p>
Histogram generation is not supported for encrypted tables (to
avoid exposing data in the statistics) or
<code class="literal">
TEMPORARY
</code>
tables.
</p>
<p>
Histogram generation applies to columns of all data types
except geometry types (spatial data) and
<a class="link" href="json.html" title="13.5 The JSON Data Type">
<code class="literal">
JSON
</code>
</a>
.
</p>
<p>
Histograms can be generated for stored and virtual generated
columns.
</p>
<p>
Histograms cannot be generated for columns that are covered by
single-column unique indexes.
</p>
<p>
Histogram management statements attempt to perform as much of
the requested operation as possible, and report diagnostic
messages for the remainder. For example, if an
<code class="literal">
UPDATE
HISTOGRAM
</code>
statement names multiple columns, but some
of them do not exist or have an unsupported data type,
histograms are generated for the other columns, and messages
are produced for the invalid columns.
</p>
<p>
Histograms are affected by these DDL statements:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
<code class="literal">
DROP TABLE
</code>
</a>
removes
histograms for columns in the dropped table.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="drop-database.html" title="15.1.24 DROP DATABASE Statement">
<code class="literal">
DROP DATABASE
</code>
</a>
removes
histograms for any table in the dropped database because
the statement drops all tables in the database.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="rename-table.html" title="15.1.36 RENAME TABLE Statement">
<code class="literal">
RENAME TABLE
</code>
</a>
does not
remove histograms. Instead, it renames histograms for the
renamed table to be associated with the new table name.
</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
</code>
</a>
statements that
remove or modify a column remove histograms for that
column.
</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
... CONVERT TO CHARACTER SET
</code>
</a>
removes histograms
for character columns because they are affected by the
change of character set. Histograms for noncharacter
columns remain unaffected.
</p>
</li>
</ul>
</div>
<p>
The
<a class="link" href="server-system-variables.html#sysvar_histogram_generation_max_mem_size">
<code class="literal">
histogram_generation_max_mem_size
</code>
</a>
system variable controls the maximum amount of memory
available for histogram generation. The global and session
values may be set at runtime.
</p>
<p>
Changing the global
<a class="link" href="server-system-variables.html#sysvar_histogram_generation_max_mem_size">
<code class="literal">
histogram_generation_max_mem_size
</code>
</a>
value requires privileges sufficient to set global system
variables. Changing the session
<a class="link" href="server-system-variables.html#sysvar_histogram_generation_max_mem_size">
<code class="literal">
histogram_generation_max_mem_size
</code>
</a>
value requires privileges sufficient to set restricted session
system 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>
If the estimated amount of data to be read into memory for
histogram generation exceeds the limit defined by
<a class="link" href="server-system-variables.html#sysvar_histogram_generation_max_mem_size">
<code class="literal">
histogram_generation_max_mem_size
</code>
</a>
,
MySQL samples the data rather than reading all of it into
memory. Sampling is evenly distributed over the entire table.
MySQL uses
<code class="literal">
SYSTEM
</code>
sampling, which is a
page-level sampling method.
</p>
<p>
The
<code class="literal">
sampling-rate
</code>
value in the
<code class="literal">
HISTOGRAM
</code>
column of the Information Schema
<a class="link" href="information-schema-column-statistics-table.html" title="28.3.11 The INFORMATION_SCHEMA COLUMN_STATISTICS Table">
<code class="literal">
COLUMN_STATISTICS
</code>
</a>
table can be
queried to determine the fraction of data that was sampled to
create the histogram. The
<code class="literal">
sampling-rate
</code>
is
a number between 0.0 and 1.0. A value of 1 means that all of
the data was read (no sampling).
</p>
<p>
The following example demonstrates sampling. To ensure that
the amount of data exceeds the
<a class="link" href="server-system-variables.html#sysvar_histogram_generation_max_mem_size">
<code class="literal">
histogram_generation_max_mem_size
</code>
</a>
limit for the purpose of the example, the limit is set to a
low value (2000000 bytes) prior to generating histogram
statistics for the
<code class="literal">
birth_date
</code>
column of the
<code class="literal">
employees
</code>
table.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43880711"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> histogram_generation_max_mem_size <span class="token operator">=</span> <span class="token number">2000000</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">USE</span> employees<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> employees <span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> birth_date <span class="token keyword">WITH</span> <span class="token number">16</span> <span class="token keyword">BUCKETS</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>
Table<span class="token punctuation">:</span> employees.employees
Op<span class="token punctuation">:</span> histogram
Msg_type<span class="token punctuation">:</span> status
Msg_text<span class="token punctuation">:</span> Histogram statistics created for column 'birth_date'.
</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token keyword">HISTOGRAM</span><span class="token operator">-</span><span class="token operator">>></span><span class="token string">'$."sampling-rate"'</span>
<span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>COLUMN_STATISTICS
<span class="token keyword">WHERE</span> <span class="token keyword">TABLE_NAME</span> <span class="token operator">=</span> <span class="token string">"employees"</span>
<span class="token operator">AND</span> <span class="token keyword">COLUMN_NAME</span> <span class="token operator">=</span> <span class="token string">"birth_date"</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>
<span class="token output"><span class="token punctuation">|</span> HISTOGRAM<span class="token punctuation">-</span>>>'$."sampling<span class="token punctuation">-</span>rate"' <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>
<span class="token output"><span class="token punctuation">|</span> 0.0491431208869665 <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></code></pre>
</div>
<p>
A
<code class="literal">
sampling-rate
</code>
value of 0.0491431208869665
means that approximately 4.9% of the data from the
<code class="literal">
birth_date
</code>
column was read into memory for
generating histogram statistics.
</p>
<p>
The
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
storage engine
provides its own sampling implementation for data stored in
<code class="literal">
InnoDB
</code>
tables. The default sampling
implementation used by MySQL when storage engines do not
provide their own requires a full table scan, which is costly
for large tables. The
<code class="literal">
InnoDB
</code>
sampling
implementation improves sampling performance by avoiding full
table scans.
</p>
<p>
The
<code class="literal">
sampled_pages_read
</code>
and
<code class="literal">
sampled_pages_skipped
</code>
<a class="link" href="information-schema-innodb-metrics-table.html" title="28.4.21 The INFORMATION_SCHEMA INNODB_METRICS Table">
<code class="literal">
INNODB_METRICS
</code>
</a>
counters can be
used to monitor sampling of
<code class="literal">
InnoDB
</code>
data
pages. (For general
<a class="link" href="information-schema-innodb-metrics-table.html" title="28.4.21 The INFORMATION_SCHEMA INNODB_METRICS Table">
<code class="literal">
INNODB_METRICS
</code>
</a>
counter usage
information, see
<a class="xref" href="information-schema-innodb-metrics-table.html" title="28.4.21 The INFORMATION_SCHEMA INNODB_METRICS Table">
Section 28.4.21, “The INFORMATION_SCHEMA INNODB_METRICS Table”
</a>
.)
</p>
<p>
The following example demonstrates sampling counter usage,
which requires enabling the counters prior to generating
histogram statistics.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa27536275"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> innodb_monitor_enable <span class="token operator">=</span> <span class="token string">'sampled%'</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">USE</span> employees<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">ANALYZE</span> <span class="token keyword">TABLE</span> employees <span class="token keyword">UPDATE</span> <span class="token keyword">HISTOGRAM</span> <span class="token keyword">ON</span> birth_date <span class="token keyword">WITH</span> <span class="token number">16</span> <span class="token keyword">BUCKETS</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>
Table<span class="token punctuation">:</span> employees.employees
Op<span class="token punctuation">:</span> histogram
Msg_type<span class="token punctuation">:</span> status
Msg_text<span class="token punctuation">:</span> Histogram statistics created for column 'birth_date'.
</span>
<span class="token prompt">mysql></span> <span class="token keyword">USE</span> INFORMATION_SCHEMA<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token keyword">NAME</span><span class="token punctuation">,</span> COUNT <span class="token keyword">FROM</span> INNODB_METRICS <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'sampled%'</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>
NAME<span class="token punctuation">:</span> sampled_pages_read
COUNT<span class="token punctuation">:</span> 43
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span 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>
NAME<span class="token punctuation">:</span> sampled_pages_skipped
COUNT<span class="token punctuation">:</span> 843</span></code></pre>
</div>
<p>
This formula approximates a sampling rate based on the
sampling counter data:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa65336282"><div class="copy-help left">Press ⌘+C to 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">sampling rate = sampled_page_read/(sampled_pages_read + sampled_pages_skipped)</code></pre>
</div>
<p>
A sampling rate based on sampling counter data is roughly the
same as the
<code class="literal">
sampling-rate
</code>
value in the
<code class="literal">
HISTOGRAM
</code>
column of the Information Schema
<a class="link" href="information-schema-column-statistics-table.html" title="28.3.11 The INFORMATION_SCHEMA COLUMN_STATISTICS Table">
<code class="literal">
COLUMN_STATISTICS
</code>
</a>
table.
</p>
<p>
For information about memory allocations performed for
histogram generation, monitor the Performance Schema
<code class="literal">
memory/sql/histograms
</code>
instrument. See
<a class="xref" href="performance-schema-memory-summary-tables.html" title="29.12.20.10 Memory Summary Tables">
Section 29.12.20.10, “Memory Summary Tables”
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="analyze-table-other-considerations">
</a>
Other Considerations
</h5>
</div>
</div>
</div>
<p>
<code class="literal">
ANALYZE TABLE
</code>
clears table statistics from
the Information Schema
<a class="link" href="information-schema-innodb-tablestats-table.html" title="28.4.26 The INFORMATION_SCHEMA INNODB_TABLESTATS View">
<code class="literal">
INNODB_TABLESTATS
</code>
</a>
table and sets
the
<code class="literal">
STATS_INITIALIZED
</code>
column to
<code class="literal">
Uninitialized
</code>
. Statistics are collected
again the next time the table is accessed.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/faqs-cjk.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="faqs-cjk">
</a>
A.11 MySQL 8.4 FAQ: MySQL Chinese, Japanese, and Korean
Character Sets
</h2>
</div>
</div>
</div>
<a class="indexterm" name="idm46045055655296">
</a>
<a class="indexterm" name="idm46045055653904">
</a>
<a class="indexterm" name="idm46045055652368">
</a>
<a class="indexterm" name="idm46045055650832">
</a>
<a class="indexterm" name="idm46045055649312">
</a>
<a class="indexterm" name="idm46045055647776">
</a>
<a class="indexterm" name="idm46045055646272">
</a>
<a class="indexterm" name="idm46045055645200">
</a>
<a class="indexterm" name="idm46045055643680">
</a>
<a class="indexterm" name="idm46045055642144">
</a>
<a class="indexterm" name="idm46045055640640">
</a>
<a class="indexterm" name="idm46045055639568">
</a>
<a class="indexterm" name="idm46045055638032">
</a>
<a class="indexterm" name="idm46045055636528">
</a>
<a class="indexterm" name="idm46045055635040">
</a>
<a class="indexterm" name="idm46045055633520">
</a>
<a class="indexterm" name="idm46045055632016">
</a>
<a class="indexterm" name="idm46045055630944">
</a>
<a class="indexterm" name="idm46045055629408">
</a>
<a class="indexterm" name="idm46045055627904">
</a>
<a class="indexterm" name="idm46045055626832">
</a>
<a class="indexterm" name="idm46045055625312">
</a>
<a class="indexterm" name="idm46045055623808">
</a>
<a class="indexterm" name="idm46045055622720">
</a>
<a class="indexterm" name="idm46045055621200">
</a>
<a class="indexterm" name="idm46045055619696">
</a>
<a class="indexterm" name="idm46045055618192">
</a>
<a class="indexterm" name="idm46045055616672">
</a>
<a class="indexterm" name="idm46045055615168">
</a>
<a class="indexterm" name="idm46045055613648">
</a>
<a class="indexterm" name="idm46045055612128">
</a>
<a class="indexterm" name="idm46045055610624">
</a>
<a class="indexterm" name="idm46045055609120">
</a>
<a class="indexterm" name="idm46045055607616">
</a>
<a class="indexterm" name="idm46045055606112">
</a>
<a class="indexterm" name="idm46045055604608">
</a>
<a class="indexterm" name="idm46045055603104">
</a>
<a class="indexterm" name="idm46045055601600">
</a>
<a class="indexterm" name="idm46045055600096">
</a>
<a class="indexterm" name="idm46045055598592">
</a>
<a class="indexterm" name="idm46045055597088">
</a>
<a class="indexterm" name="idm46045055595584">
</a>
<a class="indexterm" name="idm46045055594080">
</a>
<a class="indexterm" name="idm46045055593008">
</a>
<a class="indexterm" name="idm46045055591488">
</a>
<a class="indexterm" name="idm46045055589968">
</a>
<a class="indexterm" name="idm46045055588448">
</a>
<a class="indexterm" name="idm46045055586944">
</a>
<a class="indexterm" name="idm46045055585456">
</a>
<a class="indexterm" name="idm46045055583968">
</a>
<p>
This set of Frequently Asked Questions derives from the experience
of MySQL's Support and Development groups in handling many
inquiries about CJK (Chinese-Japanese-Korean) issues.
</p>
<div class="qandaset">
<a name="idm46045055581872">
</a>
<dl>
<dt>
A.11.1.
<a href="faqs-cjk.html#faq-cjk-what-cjk-avail">
What CJK character sets are available in MySQL?
</a>
</dt>
<dt>
A.11.2.
<a href="faqs-cjk.html#faq-cjk-why-cjk-question-marks">
I have inserted CJK characters into my table. Why does
SELECT display them as
“?” characters?
</a>
</dt>
<dt>
A.11.3.
<a href="faqs-cjk.html#faq-cjk-what-problems-big5">
What problems should I be aware of when working with the Big5
Chinese character set?
</a>
</dt>
<dt>
A.11.4.
<a href="faqs-cjk.html#faq-cjk-what-japanese-chars-fail">
Why do Japanese character set conversions fail?
</a>
</dt>
<dt>
A.11.5.
<a href="faqs-cjk.html#faq-cjk-how-convert-81ca-cp932">
What should I do if I want to convert SJIS
81CA to cp932?
</a>
</dt>
<dt>
A.11.6.
<a href="faqs-cjk.html#faq-cjk-how-represent-yen">
How does MySQL represent the Yen (¥) sign?
</a>
</dt>
<dt>
A.11.7.
<a href="faqs-cjk.html#faq-cjk-what-problems-korean">
Of what issues should I be aware when working with Korean
character sets in MySQL?
</a>
</dt>
<dt>
A.11.8.
<a href="faqs-cjk.html#faq-cjk-why-incorrect-string-value">
Why do I get Incorrect string value error
messages?
</a>
</dt>
<dt>
A.11.9.
<a href="faqs-cjk.html#faq-cjk-why-gui-not-display-cjk">
Why does my GUI front end or browser display CJK characters
incorrectly in my application using Access, PHP, or another API?
</a>
</dt>
<dt>
A.11.10.
<a href="faqs-cjk.html#faq-cjk-how-use-4-0-charset">
I've upgraded to MySQL 8.4. How can I revert to
behavior like that in MySQL 4.0 with regard to character sets?
</a>
</dt>
<dt>
A.11.11.
<a href="faqs-cjk.html#faq-cjk-why-cjk-fail-searches">
Why do some LIKE and
FULLTEXT searches with CJK characters fail?
</a>
</dt>
<dt>
A.11.12.
<a href="faqs-cjk.html#faq-cjk-how-know-avail-characters">
How do I know whether character X is
available in all character sets?
</a>
</dt>
<dt>
A.11.13.
<a href="faqs-cjk.html#faq-cjk-how-cjk-sort-unicode-1">
Why do CJK strings sort incorrectly in Unicode? (I)
</a>
</dt>
<dt>
A.11.14.
<a href="faqs-cjk.html#faq-cjk-how-cjk-sort-unicode-2">
Why do CJK strings sort incorrectly in Unicode? (II)
</a>
</dt>
<dt>
A.11.15.
<a href="faqs-cjk.html#faq-cjk-why-supplement-char-rejected">
Why are my supplementary characters rejected by MySQL?
</a>
</dt>
<dt>
A.11.16.
<a href="faqs-cjk.html#faq-cjk-why-cjk-not-cjkv">
Should “CJK” be “CJKV”?
</a>
</dt>
<dt>
A.11.17.
<a href="faqs-cjk.html#faq-cjk-how-cjk-db-table-names">
Does MySQL permit CJK characters to be used in database and
table names?
</a>
</dt>
<dt>
A.11.18.
<a href="faqs-cjk.html#faq-cjk-where-doc-translations">
Where can I find translations of the MySQL Manual into Chinese,
Japanese, and Korean?
</a>
</dt>
<dt>
A.11.19.
<a href="faqs-cjk.html#faq-cjk-help-with-cjk">
Where can I get help with CJK and related issues in MySQL?
</a>
</dt>
</dl>
<table border="0" style="width: 100%;">
<colgroup>
<col align="left" width="1%"/>
<col/>
</colgroup>
<tbody>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-what-cjk-avail">
</a>
<a name="idm46045055581104">
</a>
<p>
<b>
A.11.1.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
What CJK character sets are available in MySQL?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
The list of CJK character sets may vary depending on your MySQL
version. For example, the
<code class="literal">
gb18030
</code>
character
set is not supported prior to MySQL 5.7.4. However, since the
name of the applicable language appears in the
<code class="literal">
DESCRIPTION
</code>
column for every entry in the
<a class="link" href="information-schema-character-sets-table.html" title="28.3.4 The INFORMATION_SCHEMA CHARACTER_SETS Table">
<code class="literal">
INFORMATION_SCHEMA.CHARACTER_SETS
</code>
</a>
table, you can obtain a current list of all the non-Unicode CJK
character sets using this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17893801"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> CHARACTER_SET_NAME<span class="token punctuation">,</span> <span class="token keyword">DESCRIPTION</span>
<span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>CHARACTER_SETS
<span class="token keyword">WHERE</span> <span class="token keyword">DESCRIPTION</span> <span class="token operator">LIKE</span> <span class="token string">'%Chin%'</span>
<span class="token operator">OR</span> <span class="token keyword">DESCRIPTION</span> <span class="token operator">LIKE</span> <span class="token string">'%Japanese%'</span>
<span class="token operator">OR</span> <span class="token keyword">DESCRIPTION</span> <span class="token operator">LIKE</span> <span class="token string">'%Korean%'</span>
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> CHARACTER_SET_NAME<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>
<span class="token output"><span class="token punctuation">|</span> CHARACTER_SET_NAME <span class="token punctuation">|</span> DESCRIPTION <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>
<span class="token output"><span class="token punctuation">|</span> big5 <span class="token punctuation">|</span> Big5 Traditional Chinese <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> cp932 <span class="token punctuation">|</span> SJIS for Windows Japanese <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> eucjpms <span class="token punctuation">|</span> UJIS for Windows Japanese <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> euckr <span class="token punctuation">|</span> EUC<span class="token punctuation">-</span>KR Korean <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> gb18030 <span class="token punctuation">|</span> China National Standard GB18030 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> gb2312 <span class="token punctuation">|</span> GB2312 Simplified Chinese <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> gbk <span class="token punctuation">|</span> GBK Simplified Chinese <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> sjis <span class="token punctuation">|</span> Shift<span class="token punctuation">-</span>JIS Japanese <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> ujis <span class="token punctuation">|</span> EUC<span class="token punctuation">-</span>JP Japanese <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></code></pre>
</div>
<p>
(For more information, see
<a class="xref" href="information-schema-character-sets-table.html" title="28.3.4 The INFORMATION_SCHEMA CHARACTER_SETS Table">
Section 28.3.4, “The INFORMATION_SCHEMA CHARACTER_SETS Table”
</a>
.)
</p>
<p>
MySQL supports three variants of the
<span class="firstterm">
GB
</span>
(
<span class="foreignphrase">
<em class="foreignphrase">
Guojia
Biaozhun
</em>
</span>
, or
<span class="emphasis">
<em>
National
Standard
</em>
</span>
, or
<span class="emphasis">
<em>
Simplified Chinese
</em>
</span>
)
character sets which are official in the People's Republic of
China:
<code class="literal">
gb2312
</code>
,
<code class="literal">
gbk
</code>
, and
(as of MySQL 5.7.4)
<code class="literal">
gb18030
</code>
.
</p>
<p>
Sometimes people try to insert
<code class="literal">
gbk
</code>
characters
into
<code class="literal">
gb2312
</code>
, and it works most of the time
because
<code class="literal">
gbk
</code>
is a superset of
<code class="literal">
gb2312
</code>
. But eventually they try to insert a
rarer Chinese character and it does not work. (For an example,
see Bug #16072).
</p>
<p>
Here, we try to clarify exactly what characters are legitimate
in
<code class="literal">
gb2312
</code>
or
<code class="literal">
gbk
</code>
, with
reference to the official documents. Please check these
references before reporting
<code class="literal">
gb2312
</code>
or
<code class="literal">
gbk
</code>
bugs:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The MySQL
<code class="literal">
gbk
</code>
character set is in reality
<span class="quote">
“
<span class="quote">
Microsoft code page 936
</span>
”
</span>
. This differs from
the official
<code class="literal">
gbk
</code>
for characters
<code class="literal">
A1A4
</code>
(middle dot),
<code class="literal">
A1AA
</code>
(em dash),
<code class="literal">
A6E0-A6F5
</code>
, and
<code class="literal">
A8BB-A8C0
</code>
.
</p>
</li>
<li class="listitem">
<p>
For a listing of
<code class="literal">
gbk
</code>
/Unicode mappings,
see
<a class="ulink" href="http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT" target="_blank">
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT
</a>
.
</p>
</li>
</ul>
</div>
<p>
It is also possible to store CJK characters in Unicode character
sets, although the available collations may not sort characters
quite as you expect:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The
<code class="literal">
utf8
</code>
and
<code class="literal">
ucs2
</code>
character sets support the characters from Unicode Basic
Multilingual Plane (BMP). These characters have code point
values between
<code class="literal">
U+0000
</code>
and
<code class="literal">
U+FFFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
utf8mb4
</code>
,
<code class="literal">
utf16
</code>
,
<code class="literal">
utf16le
</code>
, and
<code class="literal">
utf32
</code>
character sets support BMP characters, as well as
supplementary characters that lie outside the BMP.
Supplementary characters have code point values between
<code class="literal">
U+10000
</code>
and
<code class="literal">
U+10FFFF
</code>
.
</p>
</li>
</ul>
</div>
<p>
The collation used for a Unicode character set determines the
ability to sort (that is, distinguish) characters in the set:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Collations based on Unicode Collation Algorithm (UCA) 4.0.0
distinguish only BMP characters.
</p>
</li>
<li class="listitem">
<p>
Collations based on UCA 5.2.0 or 9.0.0 distinguish BMP and
supplementary characters.
</p>
</li>
<li class="listitem">
<p>
Non-UCA collations may not distinguish all Unicode
characters. For example, the
<code class="literal">
utf8mb4
</code>
default collation is
<code class="literal">
utf8mb4_general_ci
</code>
,
which distinguishes only BMP characters.
</p>
</li>
</ul>
</div>
<p>
Moreover, distinguishing characters is not the same as ordering
them per the conventions of a given CJK language. Currently,
MySQL has only one CJK-specific UCA collation,
<code class="literal">
gb18030_unicode_520_ci
</code>
(which requires use of
the non-Unicode
<code class="literal">
gb18030
</code>
character set).
</p>
<p>
For information about Unicode collations and their
differentiating properties, including collation properties for
supplementary characters, see
<a class="xref" href="charset-unicode-sets.html" title="12.10.1 Unicode Character Sets">
Section 12.10.1, “Unicode Character Sets”
</a>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-why-cjk-question-marks">
</a>
<a name="idm46045055530752">
</a>
<p>
<b>
A.11.2.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
I have inserted CJK characters into my table. Why does
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
display them as
<span class="quote">
“
<span class="quote">
?
</span>
”
</span>
characters?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
This problem is usually due to a setting in MySQL that does not
match the settings for the application program or the operating
system. Here are some common steps for correcting these types of
issues:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<span class="emphasis">
<em>
Be certain of what MySQL version you are
using
</em>
</span>
.
</p>
<p>
Use the statement
<code class="literal">
SELECT VERSION();
</code>
to
determine this.
</p>
</li>
<li class="listitem">
<p>
<span class="emphasis">
<em>
Make sure that the database is actually using the
desired character set
</em>
</span>
.
</p>
<p>
People often think that the client character set is always
the same as either the server character set or the character
set used for display purposes. However, both of these are
false assumptions. You can make sure by checking the result
of
<code class="literal">
SHOW CREATE TABLE
<em class="replaceable">
<code>
tablename
</code>
</em>
</code>
or, better
yet, by using this statement:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa15163097"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> character_set_name<span class="token punctuation">,</span> collation_name
<span class="token keyword">FROM</span> information_schema<span class="token punctuation">.</span><span class="token keyword">columns</span>
<span class="token keyword">WHERE</span> table_schema <span class="token operator">=</span> your_database_name
<span class="token operator">AND</span> <span class="token keyword">table_name</span> <span class="token operator">=</span> your_table_name
<span class="token operator">AND</span> <span class="token keyword">column_name</span> <span class="token operator">=</span> your_column_name<span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
<span class="emphasis">
<em>
Determine the hexadecimal value of the character
or characters that are not being displayed
correctly
</em>
</span>
.
</p>
<p>
You can obtain this information for a column
<em class="replaceable">
<code>
column_name
</code>
</em>
in the table
<em class="replaceable">
<code>
table_name
</code>
</em>
using the following
query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22121110"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">HEX</span><span class="token punctuation">(</span><span class="token keyword"><em class="replaceable">column_name</em></span><span class="token punctuation">)</span>
<span class="token keyword">FROM</span> <span class="token keyword"><em class="replaceable">table_name</em></span><span class="token punctuation">;</span></code></pre>
</div>
<p>
<code class="literal">
3F
</code>
is the encoding for the
<code class="literal">
?
</code>
character; this means that
<code class="literal">
?
</code>
is the character actually stored in the
column. This most often happens because of a problem
converting a particular character from your client character
set to the target character set.
</p>
</li>
<li class="listitem">
<p>
<span class="emphasis">
<em>
Make sure that a round trip is possible. When you
select
<em class="replaceable">
<code>
literal
</code>
</em>
(or
<em class="replaceable">
<code>
_introducer hexadecimal-value
</code>
</em>
),
do you obtain
<em class="replaceable">
<code>
literal
</code>
</em>
as a
result
</em>
</span>
?
</p>
<p>
For example, the Japanese Katakana character
<span class="foreignphrase">
<em class="foreignphrase">
Pe
</em>
</span>
(
<code class="literal">
ペ'
</code>
)
exists in all CJK character sets, and has the code point
value (hexadecimal coding)
<code class="literal">
0x30da
</code>
. To
test a round trip for this character, use this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa55980499"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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 string">'ペ'</span> <span class="token keyword">AS</span> <span class="token punctuation">`</span>ペ<span class="token punctuation">`</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">/* or SELECT _ucs2 0x30da; */</span></code></pre>
</div>
<p>
If the result is not also
<code class="literal">
ペ
</code>
, the round
trip failed.
</p>
<p>
For bug reports regarding such failures, we might ask you to
follow up with
<code class="literal">
SELECT HEX('ペ');
</code>
. Then
we can determine whether the client encoding is correct.
</p>
</li>
<li class="listitem">
<p>
<span class="emphasis">
<em>
Make sure that the problem is not with the browser
or other application, rather than with MySQL
</em>
</span>
.
</p>
<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 program to
accomplish this task. If
<a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
<span class="command">
<strong>
mysql
</strong>
</span>
</a>
displays
characters correctly but your application does not, your
problem is probably due to system settings.
</p>
<p>
To determine your settings, use the
<a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
<code class="literal">
SHOW VARIABLES
</code>
</a>
statement,
whose output should resemble what is shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa78869933"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'char%'</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>
<span class="token output"><span class="token punctuation">|</span> Variable_name <span class="token punctuation">|</span> Value <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>
<span class="token output"><span class="token punctuation">|</span> character_set_client <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_connection <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_database <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_filesystem <span class="token punctuation">|</span> binary <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_results <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_server <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_system <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_sets_dir <span class="token punctuation">|</span> /usr/local/mysql/share/mysql/charsets/ <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></code></pre>
</div>
<p>
These are typical character-set settings for an
international-oriented client (notice the use of
<code class="literal">
utf8
</code>
Unicode) connected to a server in
the West (
<code class="literal">
latin1
</code>
is a West Europe
character set).
</p>
<p>
Although Unicode (usually the
<code class="literal">
utf8
</code>
variant on Unix, and the
<code class="literal">
ucs2
</code>
variant on
Windows) is preferable to Latin, it is often not what your
operating system utilities support best. Many Windows users
find that a Microsoft character set, such as
<code class="literal">
cp932
</code>
for Japanese Windows, is suitable.
</p>
<p>
If you cannot control the server settings, and you have no
idea what setting your underlying computer uses, try
changing to a common character set for the country that
you're in (
<code class="literal">
euckr
</code>
= Korea;
<code class="literal">
gb18030
</code>
,
<code class="literal">
gb2312
</code>
or
<code class="literal">
gbk
</code>
= People's Republic of China;
<code class="literal">
big5
</code>
= Taiwan;
<code class="literal">
sjis
</code>
,
<code class="literal">
ujis
</code>
,
<code class="literal">
cp932
</code>
, or
<code class="literal">
eucjpms
</code>
= Japan;
<code class="literal">
ucs2
</code>
or
<code class="literal">
utf8
</code>
= anywhere). Usually it is
necessary to change only the client and connection and
results settings. The
<a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
<code class="literal">
SET
NAMES
</code>
</a>
. statement changes all three at once. For
example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa47293035"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">'big5'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Once the setting is correct, you can make it permanent by
editing
<code class="filename">
my.cnf
</code>
or
<code class="filename">
my.ini
</code>
. For example you might add lines
looking like these:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa79722017"><div class="copy-help left">Press ⌘+C to 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">character-set-server</span><span class="token attr-value"><span class="token punctuation">=</span>big5</span>
<span class="token selector">[client]</span>
<span class="token constant">default-character-set</span><span class="token attr-value"><span class="token punctuation">=</span>big5</span></code></pre>
</div>
<p>
It is also possible that there are issues with the API
configuration setting being used in your application; see
<em class="citetitle">
Why does my GUI front end or browser not display
CJK characters correctly...?
</em>
for more
information.
</p>
</li>
</ul>
</div>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-what-problems-big5">
</a>
<a name="idm46045055475504">
</a>
<p>
<b>
A.11.3.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
What problems should I be aware of when working with the Big5
Chinese character set?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
MySQL supports the Big5 character set which is common in Hong
Kong and Taiwan (Republic of China). The MySQL
<code class="literal">
big5
</code>
character set is in reality Microsoft
code page 950, which is very similar to the original
<code class="literal">
big5
</code>
character set.
</p>
<p>
A feature request for adding
<code class="literal">
HKSCS
</code>
extensions
has been filed. People who need this extension may find the
suggested patch for Bug #13577 to be of interest.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-what-japanese-chars-fail">
</a>
<a name="idm46045055470560">
</a>
<p>
<b>
A.11.4.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why do Japanese character set conversions fail?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
MySQL supports the
<code class="literal">
sjis
</code>
,
<code class="literal">
ujis
</code>
,
<code class="literal">
cp932
</code>
, and
<code class="literal">
eucjpms
</code>
character sets, as well as Unicode. A
common need is to convert between character sets. For example,
there might be a Unix server (typically with
<code class="literal">
sjis
</code>
or
<code class="literal">
ujis
</code>
) and a
Windows client (typically with
<code class="literal">
cp932
</code>
).
</p>
<p>
In the following conversion table, the
<code class="literal">
ucs2
</code>
column represents the source, and the
<code class="literal">
sjis
</code>
,
<code class="literal">
cp932
</code>
,
<code class="literal">
ujis
</code>
, and
<code class="literal">
eucjpms
</code>
columns represent the destinations;
that is, the last 4 columns provide the hexadecimal result when
we use
<a class="link" href="cast-functions.html#function_convert">
<code class="literal">
CONVERT(ucs2)
</code>
</a>
or we assign
a
<code class="literal">
ucs2
</code>
column containing the value to an
<code class="literal">
sjis
</code>
,
<code class="literal">
cp932
</code>
,
<code class="literal">
ujis
</code>
, or
<code class="literal">
eucjpms
</code>
column.
</p>
<div class="informaltable">
<table summary="Result of assigning various ucs2 characters to a column that uses the sjis, cp932, ujis, or eucjpms character set.">
<colgroup>
<col style="width: 40%"/>
<col align="left" style="width: 12%"/>
<col align="right" style="width: 12%"/>
<col align="right" style="width: 12%"/>
<col align="right" style="width: 12%"/>
<col align="right" style="width: 12%"/>
</colgroup>
<thead>
<tr>
<th scope="col">
Character Name
</th>
<th scope="col">
ucs2
</th>
<th scope="col">
sjis
</th>
<th scope="col">
cp932
</th>
<th scope="col">
ujis
</th>
<th scope="col">
eucjpms
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
BROKEN BAR
</th>
<td>
00A6
</td>
<td>
3F
</td>
<td>
3F
</td>
<td>
8FA2C3
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH BROKEN BAR
</th>
<td>
FFE4
</td>
<td>
3F
</td>
<td>
FA55
</td>
<td>
3F
</td>
<td>
8FA2
</td>
</tr>
<tr>
<th scope="row">
YEN SIGN
</th>
<td>
00A5
</td>
<td>
3F
</td>
<td>
3F
</td>
<td>
20
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH YEN SIGN
</th>
<td>
FFE5
</td>
<td>
818F
</td>
<td>
818F
</td>
<td>
A1EF
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
TILDE
</th>
<td>
007E
</td>
<td>
7E
</td>
<td>
7E
</td>
<td>
7E
</td>
<td>
7E
</td>
</tr>
<tr>
<th scope="row">
OVERLINE
</th>
<td>
203E
</td>
<td>
3F
</td>
<td>
3F
</td>
<td>
20
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
HORIZONTAL BAR
</th>
<td>
2015
</td>
<td>
815C
</td>
<td>
815C
</td>
<td>
A1BD
</td>
<td>
A1BD
</td>
</tr>
<tr>
<th scope="row">
EM DASH
</th>
<td>
2014
</td>
<td>
3F
</td>
<td>
3F
</td>
<td>
3F
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
REVERSE SOLIDUS
</th>
<td>
005C
</td>
<td>
815F
</td>
<td>
5C
</td>
<td>
5C
</td>
<td>
5C
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH REVERSE SOLIDUS
</th>
<td>
FF3C
</td>
<td>
3F
</td>
<td>
815F
</td>
<td>
3F
</td>
<td>
A1C0
</td>
</tr>
<tr>
<th scope="row">
WAVE DASH
</th>
<td>
301C
</td>
<td>
8160
</td>
<td>
3F
</td>
<td>
A1C1
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH TILDE
</th>
<td>
FF5E
</td>
<td>
3F
</td>
<td>
8160
</td>
<td>
3F
</td>
<td>
A1C1
</td>
</tr>
<tr>
<th scope="row">
DOUBLE VERTICAL LINE
</th>
<td>
2016
</td>
<td>
8161
</td>
<td>
3F
</td>
<td>
A1C2
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
PARALLEL TO
</th>
<td>
2225
</td>
<td>
3F
</td>
<td>
8161
</td>
<td>
3F
</td>
<td>
A1C2
</td>
</tr>
<tr>
<th scope="row">
MINUS SIGN
</th>
<td>
2212
</td>
<td>
817C
</td>
<td>
3F
</td>
<td>
A1DD
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH HYPHEN-MINUS
</th>
<td>
FF0D
</td>
<td>
3F
</td>
<td>
817C
</td>
<td>
3F
</td>
<td>
A1DD
</td>
</tr>
<tr>
<th scope="row">
CENT SIGN
</th>
<td>
00A2
</td>
<td>
8191
</td>
<td>
3F
</td>
<td>
A1F1
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH CENT SIGN
</th>
<td>
FFE0
</td>
<td>
3F
</td>
<td>
8191
</td>
<td>
3F
</td>
<td>
A1F1
</td>
</tr>
<tr>
<th scope="row">
POUND SIGN
</th>
<td>
00A3
</td>
<td>
8192
</td>
<td>
3F
</td>
<td>
A1F2
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH POUND SIGN
</th>
<td>
FFE1
</td>
<td>
3F
</td>
<td>
8192
</td>
<td>
3F
</td>
<td>
A1F2
</td>
</tr>
<tr>
<th scope="row">
NOT SIGN
</th>
<td>
00AC
</td>
<td>
81CA
</td>
<td>
3F
</td>
<td>
A2CC
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH NOT SIGN
</th>
<td>
FFE2
</td>
<td>
3F
</td>
<td>
81CA
</td>
<td>
3F
</td>
<td>
A2CC
</td>
</tr>
</tbody>
</table>
</div>
<div class="informaltable">
<table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 469.844px; width: 531px;">
<thead>
<tr>
<th scope="col" style="width: 211.984px;">
Character Name
</th>
<th scope="col" style="width: 63.5781px;">
ucs2
</th>
<th scope="col" style="width: 63.5781px;">
sjis
</th>
<th scope="col" style="width: 63.5781px;">
cp932
</th>
<th scope="col" style="width: 63.5781px;">
ujis
</th>
<th scope="col" style="width: 63.6406px;">
eucjpms
</th>
</tr>
</thead>
</table>
</div>
<p>
Now consider the following portion of the table.
</p>
<div class="informaltable">
<table summary="Result of assigning NOT SIGN and FULLWIDTH NOT SIGN ucs2 characters to a column that uses the sjis, cp932, ujis, or eucjpms character set.">
<colgroup>
<col style="width: 55%"/>
<col align="right" style="width: 15%"/>
<col align="right" style="width: 15%"/>
<col align="right" style="width: 15%"/>
</colgroup>
<thead>
<tr>
<th scope="col">
</th>
<th scope="col">
ucs2
</th>
<th scope="col">
sjis
</th>
<th scope="col">
cp932
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
NOT SIGN
</th>
<td>
00AC
</td>
<td>
81CA
</td>
<td>
3F
</td>
</tr>
<tr>
<th scope="row">
FULLWIDTH NOT SIGN
</th>
<td>
FFE2
</td>
<td>
3F
</td>
<td>
81CA
</td>
</tr>
</tbody>
</table>
</div>
<p>
This means that MySQL converts the
<code class="literal">
NOT SIGN
</code>
(Unicode
<code class="literal">
U+00AC
</code>
) to
<code class="literal">
sjis
</code>
code point
<code class="literal">
0x81CA
</code>
and to
<code class="literal">
cp932
</code>
code point
<code class="literal">
3F
</code>
.
(
<code class="literal">
3F
</code>
is the question mark (
<span class="quote">
“
<span class="quote">
?
</span>
”
</span>
.
This is what is always used when the conversion cannot be
performed.)
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-convert-81ca-cp932">
</a>
<a name="idm46045055284352">
</a>
<p>
<b>
A.11.5.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
What should I do if I want to convert SJIS
<code class="literal">
81CA
</code>
to
<code class="literal">
cp932
</code>
?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Our answer is:
<span class="quote">
“
<span class="quote">
?
</span>
”
</span>
. There are disadvantages to
this, and many people would prefer a
<span class="quote">
“
<span class="quote">
loose
</span>
”
</span>
conversion, so that
<code class="literal">
81CA (NOT SIGN)
</code>
in
<code class="literal">
sjis
</code>
becomes
<code class="literal">
81CA (FULLWIDTH NOT
SIGN)
</code>
in
<code class="literal">
cp932
</code>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-represent-yen">
</a>
<a name="idm46045055277024">
</a>
<p>
<b>
A.11.6.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
How does MySQL represent the Yen (
<code class="literal">
¥
</code>
) sign?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
A problem arises because some versions of Japanese character
sets (both
<code class="literal">
sjis
</code>
and
<code class="literal">
euc
</code>
)
treat
<code class="literal">
5C
</code>
as a
<span class="firstterm">
reverse solidus
</span>
(
<code class="literal">
\
</code>
, also known as a backslash), whereas
others treat it as a yen sign (
<code class="literal">
¥
</code>
).
</p>
<p>
MySQL follows only one version of the JIS (Japanese Industrial
Standards) standard description. In MySQL,
<span class="emphasis">
<em>
<code class="literal">
5C
</code>
is always the reverse solidus
(
<code class="literal">
\
</code>
)
</em>
</span>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-what-problems-korean">
</a>
<a name="idm46045055267744">
</a>
<p>
<b>
A.11.7.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Of what issues should I be aware when working with Korean
character sets in MySQL?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
In theory, while there have been several versions of the
<code class="literal">
euckr
</code>
(
<span class="firstterm">
Extended
Unix Code Korea
</span>
) character set, only one problem has
been noted. We use the
<span class="quote">
“
<span class="quote">
ASCII
</span>
”
</span>
variant of EUC-KR,
in which the code point
<code class="literal">
0x5c
</code>
is REVERSE
SOLIDUS, that is
<code class="literal">
\
</code>
, instead of the
<span class="quote">
“
<span class="quote">
KS-Roman
</span>
”
</span>
variant of EUC-KR, in which the code
point
<code class="literal">
0x5c
</code>
is
<code class="literal">
WON SIGN
</code>
(
<code class="literal">
₩
</code>
). This means that you cannot convert
Unicode
<code class="literal">
U+20A9
</code>
to
<code class="literal">
euckr
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa90649276"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span>
<span class="token function">CONVERT</span><span class="token punctuation">(</span><span class="token string">'₩'</span> <span class="token keyword">USING</span> euckr<span class="token punctuation">)</span> <span class="token keyword">AS</span> euckr<span class="token punctuation">,</span>
<span class="token function">HEX</span><span class="token punctuation">(</span><span class="token function">CONVERT</span><span class="token punctuation">(</span><span class="token string">'₩'</span> <span class="token keyword">USING</span> euckr<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> hexeuckr<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>
<span class="token output"><span class="token punctuation">|</span> euckr <span class="token punctuation">|</span> hexeuckr <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>
<span class="token output"><span class="token punctuation">|</span> ? <span class="token punctuation">|</span> 3F <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></code></pre>
</div>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-why-incorrect-string-value">
</a>
<a name="idm46045055254896">
</a>
<p>
<b>
A.11.8.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why do I get
<span class="errortext">
Incorrect string value
</span>
error
messages?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
To see the problem, create a table with one Unicode
(
<code class="literal">
ucs2
</code>
) column and one Chinese
(
<code class="literal">
gb2312
</code>
) column.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44062214"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> ch
<span class="token punctuation">(</span>ucs2 <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> ucs2<span class="token punctuation">,</span>
gb2312 <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> gb2312<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
In nonstrict SQL mode, try to place the rare character
<code class="literal">
汌
</code>
in both columns.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56073488"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> sql_mode <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> ch <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">'A汌B'</span><span class="token punctuation">,</span><span class="token string">'A汌B'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 1 row affected, 1 warning (0.00 sec)</span></code></pre>
</div>
<p>
The
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
produces a warning.
Use the following statement to see what it is:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa50035722"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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> Warning
Code<span class="token punctuation">:</span> 1366
Message<span class="token punctuation">:</span> Incorrect string value<span class="token punctuation">:</span> '\xE6\xB1\x8CB' for column 'gb2312' at row 1</span></code></pre>
</div>
<p>
So it is a warning about the
<code class="literal">
gb2312
</code>
column
only.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46371347"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> ucs2<span class="token punctuation">,</span><span class="token function">HEX</span><span class="token punctuation">(</span>ucs2<span class="token punctuation">)</span><span class="token punctuation">,</span>gb2312<span class="token punctuation">,</span><span class="token function">HEX</span><span class="token punctuation">(</span>gb2312<span class="token punctuation">)</span> <span class="token keyword">FROM</span> ch<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ucs2 <span class="token punctuation">|</span> HEX(ucs2) <span class="token punctuation">|</span> gb2312 <span class="token punctuation">|</span> HEX(gb2312) <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> A汌B <span class="token punctuation">|</span> 00416C4C0042 <span class="token punctuation">|</span> A?B <span class="token punctuation">|</span> 413F42 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
</div>
<p>
Several things need explanation here:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
The
<code class="literal">
汌
</code>
character is not in the
<code class="literal">
gb2312
</code>
character set, as described
earlier.
</p>
</li>
<li class="listitem">
<p>
If you are using an old version of MySQL, you may see a
different message.
</p>
</li>
<li class="listitem">
<p>
A warning occurs rather than an error because MySQL is not
set to use strict SQL mode. In nonstrict mode, MySQL tries
to do what it can, to get the best fit, rather than give up.
With strict SQL mode, the
<span class="errortext">
Incorrect string
value
</span>
message occurs as an error rather than a
warning, and the
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
fails.
</p>
</li>
</ol>
</div>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-why-gui-not-display-cjk">
</a>
<a name="idm46045055230912">
</a>
<p>
<b>
A.11.9.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why does my GUI front end or browser display CJK characters
incorrectly in my application using Access, PHP, or another API?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Obtain a direct connection to the server using 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, and try the same query there.
If
<a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
<span class="command">
<strong>
mysql
</strong>
</span>
</a>
responds correctly, the trouble may
be that your application interface requires initialization. Use
<a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
<span class="command">
<strong>
mysql
</strong>
</span>
</a>
to tell you what character set or sets
it uses with the statement
<code class="literal">
SHOW VARIABLES LIKE
'char%';
</code>
. If you are using Access, you are most likely
connecting with Connector/ODBC. In this case, you should check
<a class="ulink" href="/doc/connector-odbc/en/connector-odbc-configuration.html" target="_top">
Configuring Connector/ODBC
</a>
. If, for example,
you use
<code class="literal">
big5
</code>
, you would enter
<code class="literal">
SET
NAMES 'big5'
</code>
. (In this case, no
<code class="literal">
;
</code>
character is required.) If you are using ASP, you might need to
add
<a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
<code class="literal">
SET NAMES
</code>
</a>
in the code. Here
is an example that has worked in the past:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-none"><div class="docs-select-all right" id="sa52889031"><div class="copy-help left">Press ⌘+C to 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"><%
Session.CodePage=0
Dim strConnection
Dim Conn
strConnection="driver={MySQL ODBC 3.51 Driver};server=<em class="replaceable">server</em>;uid=<em class="replaceable">username</em>;" \
& "pwd=<em class="replaceable">password</em>;database=<em class="replaceable">database</em>;stmt=SET NAMES 'big5';"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strConnection
%></code></pre>
</div>
<p>
In much the same way, if you are using any character set other
than
<code class="literal">
latin1
</code>
with Connector/NET, you must specify the
character set in the connection string. See
<a class="ulink" href="/doc/connector-net/en/connector-net-connections.html" target="_top">
Connector/NET Connections
</a>
, for more
information.
</p>
<p>
If you are using PHP, try this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-php"><div class="docs-select-all right" id="sa3283930"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-php"><span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token variable">$link</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">mysqli</span><span class="token punctuation">(</span><span class="token variable">$host</span><span class="token punctuation">,</span> <span class="token variable">$usr</span><span class="token punctuation">,</span> <span class="token variable">$pwd</span><span class="token punctuation">,</span> <span class="token variable">$db</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token function">mysqli_connect_errno</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Connect failed: %s\n"</span><span class="token punctuation">,</span> <span class="token function">mysqli_connect_error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">exit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token variable">$link</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">query</span><span class="token punctuation">(</span><span class="token string">"SET NAMES 'utf8'"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span></code></pre>
</div>
<p>
In this case, we used
<a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
<code class="literal">
SET NAMES
</code>
</a>
to change
<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>
.
</p>
<p>
Another issue often encountered in PHP applications has to do
with assumptions made by the browser. Sometimes adding or
changing a
<code class="literal">
<meta>
</code>
tag suffices to
correct the problem: for example, to insure that the user agent
interprets page content as
<code class="literal">
UTF-8
</code>
, include
<code class="literal">
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
</code>
in the
<code class="literal">
<head>
</code>
section of the HTML page.
</p>
<p>
If you are using Connector/J, see
<a class="ulink" href="/doc/connector-j/en/connector-j-reference-charsets.html" target="_top">
Using Character Sets and Unicode
</a>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-use-4-0-charset">
</a>
<a name="idm46045055202304">
</a>
<p>
<b>
A.11.10.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
I've upgraded to MySQL 8.4. How can I revert to
behavior like that in MySQL 4.0 with regard to character sets?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
In MySQL Version 4.0, there was a single
<span class="quote">
“
<span class="quote">
global
</span>
”
</span>
character set for both server and client, and the decision as to
which character to use was made by the server administrator.
This changed starting with MySQL Version 4.1. What happens now
is a
<span class="quote">
“
<span class="quote">
handshake
</span>
”
</span>
, as described in
<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>
<div class="blockquote">
<blockquote class="blockquote">
<p>
When a client connects, it sends to the server the name of the
character set that it wants to use. The server uses the name
to set the
<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_results">
<code class="literal">
character_set_results
</code>
</a>
, and
<a class="link" href="server-system-variables.html#sysvar_character_set_connection">
<code class="literal">
character_set_connection
</code>
</a>
system variables. In effect, the server performs a
<a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
<code class="literal">
SET NAMES
</code>
</a>
operation using the
character set name.
</p>
</blockquote>
</div>
<p>
The effect of this is that you cannot control the client
character set by starting
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with
<a class="link" href="server-system-variables.html#sysvar_character_set_server">
<code class="option">
--character-set-server=utf8
</code>
</a>
.
However, some Asian customers prefer the MySQL 4.0 behavior. To
make it possible to retain this behavior, we added a
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
switch,
<a class="ulink" href="/doc/refman/8.0/en/server-options.html#option_mysqld_character-set-client-handshake" target="_top">
<code class="option">
--character-set-client-handshake
</code>
</a>
,
which can be turned off with
<a class="ulink" href="/doc/refman/8.0/en/server-options.html#option_mysqld_character-set-client-handshake" target="_top">
<code class="option">
--skip-character-set-client-handshake
</code>
</a>
.
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>
with
<a class="ulink" href="/doc/refman/8.0/en/server-options.html#option_mysqld_character-set-client-handshake" target="_top">
<code class="option">
--skip-character-set-client-handshake
</code>
</a>
,
then, when a client connects, it sends to the server the name of
the character set that it wants to use. However,
<span class="emphasis">
<em>
the
server ignores this request from the client
</em>
</span>
.
</p>
<p>
By way of example, suppose that your favorite server character
set is
<code class="literal">
latin1
</code>
. Suppose further that the
client uses
<code class="literal">
utf8
</code>
because this is what the
client's operating system supports. Start the server with
<code class="literal">
latin1
</code>
as its default character set:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa44294501"><div class="copy-help left">Press ⌘+C to 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">mysqld <span class="token constant">--character-set-server</span><span class="token attr-value"><span class="token punctuation">=</span>latin1</span></code></pre>
</div>
<p>
And then start the client with the default character set
<code class="literal">
utf8
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa86905237"><div class="copy-help left">Press ⌘+C to 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">mysql <span class="token constant">--default-character-set</span><span class="token attr-value"><span class="token punctuation">=</span>utf8</span></code></pre>
</div>
<p>
The resulting settings can be seen by viewing the output of
<a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
<code class="literal">
SHOW VARIABLES
</code>
</a>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34381330"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'char%'</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>
<span class="token output"><span class="token punctuation">|</span> Variable_name <span class="token punctuation">|</span> Value <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>
<span class="token output"><span class="token punctuation">|</span> character_set_client <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_connection <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_database <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_filesystem <span class="token punctuation">|</span> binary <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_results <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_server <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_system <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_sets_dir <span class="token punctuation">|</span> /usr/local/mysql/share/mysql/charsets/ <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></code></pre>
</div>
<p>
Now stop the client, and stop the server 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>
. Then start the server again, but
this time tell it to skip the handshake like so:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa74061767"><div class="copy-help left">Press ⌘+C to 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">mysqld <span class="token constant">--character-set-server</span><span class="token attr-value"><span class="token punctuation">=</span>utf8</span> <span class="token property">--skip-character-set-client-handshake</span></code></pre>
</div>
<p>
Start the client with
<code class="literal">
utf8
</code>
once again as the
default character set, then display the resulting settings:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa20577870"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'char%'</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>
<span class="token output"><span class="token punctuation">|</span> Variable_name <span class="token punctuation">|</span> Value <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>
<span class="token output"><span class="token punctuation">|</span> character_set_client <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_connection <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_database <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_filesystem <span class="token punctuation">|</span> binary <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_results <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_server <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_system <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_sets_dir <span class="token punctuation">|</span> /usr/local/mysql/share/mysql/charsets/ <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></code></pre>
</div>
<p>
As you can see by comparing the differing results from
<a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
<code class="literal">
SHOW VARIABLES
</code>
</a>
, the server
ignores the client's initial settings if the
<a class="ulink" href="/doc/refman/8.0/en/server-options.html#option_mysqld_character-set-client-handshake" target="_top">
<code class="option">
--skip-character-set-client-handshake
</code>
</a>
option is used.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-why-cjk-fail-searches">
</a>
<a name="idm46045055164096">
</a>
<p>
<b>
A.11.11.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why do some
<a class="link" href="string-comparison-functions.html#operator_like">
<code class="literal">
LIKE
</code>
</a>
and
<code class="literal">
FULLTEXT
</code>
searches with CJK characters fail?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
For
<a class="link" href="string-comparison-functions.html#operator_like">
<code class="literal">
LIKE
</code>
</a>
searches, there is a very
simple problem with binary string column types such as
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
BINARY
</code>
</a>
and
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
: we must know where
characters end. With multibyte character sets, different
characters might have different octet lengths. For example, in
<code class="literal">
utf8
</code>
,
<code class="literal">
A
</code>
requires one byte
but
<code class="literal">
ペ
</code>
requires three bytes, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-none"><div class="docs-select-all right" id="sa48412239"><div class="copy-help left">Press ⌘+C to 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">+-------------------------+---------------------------+
| OCTET_LENGTH(_utf8 'A') | OCTET_LENGTH(_utf8 'ペ') |
+-------------------------+---------------------------+
| 1 | 3 |
+-------------------------+---------------------------+</code></pre>
</div>
<p>
If we do not know where the first character in a string ends, we
do not know where the second character begins, in which case
even very simple searches such as
<a class="link" href="string-comparison-functions.html#operator_like">
<code class="literal">
LIKE '_A%'
</code>
</a>
fail.
The solution is to use a nonbinary string column type defined to
have the proper CJK character set. For example:
<code class="literal">
mycol
TEXT CHARACTER SET sjis
</code>
. Alternatively, convert to a
CJK character set before comparing.
</p>
<p>
This is one reason why MySQL cannot permit encodings of
nonexistent characters. If it is not strict about rejecting bad
input, it has no way of knowing where characters end.
</p>
<p>
For
<code class="literal">
FULLTEXT
</code>
searches, we must know where
words begin and end. With Western languages, this is rarely a
problem because most (if not all) of these use an
easy-to-identify word boundary: the space character. However,
this is not usually the case with Asian writing. We could use
arbitrary halfway measures, like assuming that all Han
characters represent words, or (for Japanese) depending on
changes from Katakana to Hiragana due to grammatical endings.
However, the only sure solution requires a comprehensive word
list, which means that we would have to include a dictionary in
the server for each Asian language supported. This is simply not
feasible.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-know-avail-characters">
</a>
<a name="idm46045055147408">
</a>
<p>
<b>
A.11.12.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
How do I know whether character
<em class="replaceable">
<code>
X
</code>
</em>
is
available in all character sets?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
The majority of simplified Chinese and basic nonhalfwidth
Japanese Kana characters appear in all CJK character sets. The
following stored procedure accepts a
<code class="literal">
UCS-2
</code>
Unicode character, converts it to other character sets, and
displays the results in hexadecimal.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61678015"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DELIMITER</span> <span class="token comment" spellcheck="true">//</span>
<span class="token keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> p_convert<span class="token punctuation">(</span>ucs2_char <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 keyword">CHARACTER</span> <span class="token keyword">SET</span> ucs2<span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> tj
<span class="token punctuation">(</span>ucs2 <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 keyword">character</span> <span class="token keyword">set</span> ucs2<span class="token punctuation">,</span>
utf8 <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 keyword">character</span> <span class="token keyword">set</span> utf8<span class="token punctuation">,</span>
big5 <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 keyword">character</span> <span class="token keyword">set</span> big5<span class="token punctuation">,</span>
cp932 <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 keyword">character</span> <span class="token keyword">set</span> cp932<span class="token punctuation">,</span>
eucjpms <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 keyword">character</span> <span class="token keyword">set</span> eucjpms<span class="token punctuation">,</span>
euckr <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 keyword">character</span> <span class="token keyword">set</span> euckr<span class="token punctuation">,</span>
gb2312 <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 keyword">character</span> <span class="token keyword">set</span> gb2312<span class="token punctuation">,</span>
gbk <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 keyword">character</span> <span class="token keyword">set</span> gbk<span class="token punctuation">,</span>
sjis <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 keyword">character</span> <span class="token keyword">set</span> sjis<span class="token punctuation">,</span>
ujis <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 keyword">character</span> <span class="token keyword">set</span> ujis<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> tj <span class="token punctuation">(</span>ucs2<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span>ucs2_char<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">UPDATE</span> tj <span class="token keyword">SET</span> utf8<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
big5<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
cp932<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
eucjpms<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
euckr<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
gb2312<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
gbk<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
sjis<span class="token operator">=</span>ucs2<span class="token punctuation">,</span>
ujis<span class="token operator">=</span>ucs2<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/* If there are conversion problems, UPDATE produces warnings. */</span>
<span class="token keyword">SELECT</span> <span class="token function">hex</span><span class="token punctuation">(</span>ucs2<span class="token punctuation">)</span> <span class="token keyword">AS</span> ucs2<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>utf8<span class="token punctuation">)</span> <span class="token keyword">AS</span> utf8<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>big5<span class="token punctuation">)</span> <span class="token keyword">AS</span> big5<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>cp932<span class="token punctuation">)</span> <span class="token keyword">AS</span> cp932<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>eucjpms<span class="token punctuation">)</span> <span class="token keyword">AS</span> eucjpms<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>euckr<span class="token punctuation">)</span> <span class="token keyword">AS</span> euckr<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>gb2312<span class="token punctuation">)</span> <span class="token keyword">AS</span> gb2312<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>gbk<span class="token punctuation">)</span> <span class="token keyword">AS</span> gbk<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>sjis<span class="token punctuation">)</span> <span class="token keyword">AS</span> sjis<span class="token punctuation">,</span>
<span class="token function">hex</span><span class="token punctuation">(</span>ujis<span class="token punctuation">)</span> <span class="token keyword">AS</span> ujis
<span class="token keyword">FROM</span> tj<span class="token punctuation">;</span>
<span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> tj<span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token comment" spellcheck="true">//</span>
<span class="token keyword">DELIMITER</span> <span class="token punctuation">;</span></code></pre>
</div>
<p>
The input can be any single
<code class="literal">
ucs2
</code>
character,
or it can be the code value (hexadecimal representation) of that
character. For example, from Unicode's list of
<code class="literal">
ucs2
</code>
encodings and names
(
<a class="ulink" href="http://www.unicode.org/Public/UNIDATA/UnicodeData.txt" target="_blank">
http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
</a>
),
we know that the Katakana character
<span class="foreignphrase">
<em class="foreignphrase">
Pe
</em>
</span>
appears in all CJK character
sets, and that its code value is
<code class="literal">
X'30DA'
</code>
. If
we use this value as the argument to
<code class="literal">
p_convert()
</code>
, the result is as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89462459"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CALL</span> p_convert<span class="token punctuation">(</span>X<span class="token string">'30DA'</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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> ucs2 <span class="token punctuation">|</span> utf8 <span class="token punctuation">|</span> big5 <span class="token punctuation">|</span> cp932 <span class="token punctuation">|</span> eucjpms <span class="token punctuation">|</span> euckr <span class="token punctuation">|</span> gb2312 <span class="token punctuation">|</span> gbk <span class="token punctuation">|</span> sjis <span class="token punctuation">|</span> ujis <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 class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 30DA <span class="token punctuation">|</span> E3839A <span class="token punctuation">|</span> C772 <span class="token punctuation">|</span> 8379 <span class="token punctuation">|</span> A5DA <span class="token punctuation">|</span> ABDA <span class="token punctuation">|</span> A5DA <span class="token punctuation">|</span> A5DA <span class="token punctuation">|</span> 8379 <span class="token punctuation">|</span> A5DA <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 class="token punctuation">+</span></span></code></pre>
</div>
<p>
Since none of the column values is
<code class="literal">
3F
</code>
(that
is, the question mark character,
<code class="literal">
?
</code>
), we know
that every conversion worked.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-cjk-sort-unicode-1">
</a>
<a name="idm46045055132896">
</a>
<p>
<b>
A.11.13.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why do CJK strings sort incorrectly in Unicode? (I)
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
CJK sorting problems that occurred in older MySQL versions can
be solved as of MySQL 8.0 by using the
<code class="literal">
utf8mb4
</code>
character set and the
<code class="literal">
utf8mb4_ja_0900_as_cs
</code>
collation.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-cjk-sort-unicode-2">
</a>
<a name="idm46045055129360">
</a>
<p>
<b>
A.11.14.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why do CJK strings sort incorrectly in Unicode? (II)
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
CJK sorting problems that occurred in older MySQL versions can
be solved as of MySQL 8.0 by using the
<code class="literal">
utf8mb4
</code>
character set and the
<code class="literal">
utf8mb4_ja_0900_as_cs
</code>
collation.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-why-supplement-char-rejected">
</a>
<a name="idm46045055125824">
</a>
<p>
<b>
A.11.15.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Why are my supplementary characters rejected by MySQL?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Supplementary characters lie outside the Unicode
<span class="emphasis">
<em>
Basic
Multilingual Plane / Plane 0
</em>
</span>
. BMP characters have
code point values between
<code class="literal">
U+0000
</code>
and
<code class="literal">
U+FFFF
</code>
. Supplementary characters have code
point values between
<code class="literal">
U+10000
</code>
and
<code class="literal">
U+10FFFF
</code>
.
</p>
<p>
To store supplementary characters, you must use a character set
that permits them:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The
<code class="literal">
utf8
</code>
and
<code class="literal">
ucs2
</code>
character sets support BMP characters only.
</p>
<p>
The
<code class="literal">
utf8
</code>
character set permits only
<code class="literal">
UTF-8
</code>
characters that take up to three
bytes. This has led to reports such as that found in Bug
#12600, which we rejected as
<span class="quote">
“
<span class="quote">
not a bug
</span>
”
</span>
. With
<code class="literal">
utf8
</code>
, MySQL must truncate an input string
when it encounters bytes that it does no understand.
Otherwise, it is unknown how long the bad multibyte
character is.
</p>
<p>
One possible workaround is to use
<code class="literal">
ucs2
</code>
instead of
<code class="literal">
utf8
</code>
, in which case the
<span class="quote">
“
<span class="quote">
bad
</span>
”
</span>
characters are changed to question marks.
However, no truncation takes place. You can also change the
data type to
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
or
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
BINARY
</code>
</a>
, which perform no
validity checking.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
utf8mb4
</code>
,
<code class="literal">
utf16
</code>
,
<code class="literal">
utf16le
</code>
, and
<code class="literal">
utf32
</code>
character sets support BMP characters, as well as
supplementary characters outside the BMP.
</p>
</li>
</ul>
</div>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-why-cjk-not-cjkv">
</a>
<a name="idm46045055105056">
</a>
<p>
<b>
A.11.16.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Should
<span class="quote">
“
<span class="quote">
CJK
</span>
”
</span>
be
<span class="quote">
“
<span class="quote">
CJKV
</span>
”
</span>
?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
No. The term
<span class="quote">
“
<span class="quote">
CJKV
</span>
”
</span>
(
<span class="firstterm">
Chinese Japanese Korean
Vietnamese
</span>
) refers to Vietnamese character sets which
contain Han (originally Chinese) characters. MySQL supports the
modern Vietnamese script with Western characters, but does not
support the old Vietnamese script using Han characters.
</p>
<p>
As of MySQL 5.6, there are Vietnamese collations for Unicode
character sets, as described in
<a class="xref" href="charset-unicode-sets.html" title="12.10.1 Unicode Character Sets">
Section 12.10.1, “Unicode Character Sets”
</a>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-how-cjk-db-table-names">
</a>
<a name="idm46045055099600">
</a>
<p>
<b>
A.11.17.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Does MySQL permit CJK characters to be used in database and
table names?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Yes.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-where-doc-translations">
</a>
<a name="idm46045055097536">
</a>
<p>
<b>
A.11.18.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Where can I find translations of the MySQL Manual into Chinese,
Japanese, and Korean?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
The Japanese translation of the MySQL 5.6 manual can be
downloaded from
<a class="ulink" href="/doc/" target="_top">
https://dev.mysql.com/doc/
</a>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-cjk-help-with-cjk">
</a>
<a name="idm46045055094912">
</a>
<p>
<b>
A.11.19.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Where can I get help with CJK and related issues in MySQL?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
The following resources are available:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
A listing of MySQL user groups can be found at
<a class="ulink" href="https://wikis.oracle.com/display/mysql/List+of+MySQL+User+Groups" target="_blank">
https://wikis.oracle.com/display/mysql/List+of+MySQL+User+Groups
</a>
.
</p>
</li>
<li class="listitem">
<p>
View feature requests relating to character set issues at
<a class="ulink" href="http://tinyurl.com/y6xcuf" target="_blank">
http://tinyurl.com/y6xcuf
</a>
.
</p>
</li>
<li class="listitem">
<p>
Visit the MySQL
<a class="ulink" href="https://forums.mysql.com/list.php?103" target="_blank">
Character Sets,
Collation, Unicode Forum
</a>
.
<a class="ulink" href="http://forums.mysql.com/" target="_blank">
http://forums.mysql.com/
</a>
also provides
foreign-language forums.
</p>
</li>
</ul>
</div>
<p>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-administration-skip.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="replication-administration-skip">
</a>
19.1.7.3 Skipping Transactions
</h4>
</div>
</div>
</div>
<p>
If replication stops due to an issue with an event in a
replicated transaction, you can resume replication by skipping
the failed transaction on the replica. Before skipping a
transaction, ensure that the replication I/O (receiver) thread
is stopped as well as the SQL (applier) thread.
</p>
<p>
First you need to identify the replicated event that caused the
error. Details of the error and the last successfully applied
transaction are recorded in the Performance Schema table
<a class="link" href="performance-schema-replication-applier-status-by-worker-table.html" title="29.12.11.7 The replication_applier_status_by_worker Table">
<code class="literal">
replication_applier_status_by_worker
</code>
</a>
.
You can use
<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>
to retrieve and
display the events that were logged around the time of the
error. For instructions to do this, see
<a class="xref" href="point-in-time-recovery.html" title="9.5 Point-in-Time (Incremental) Recovery">
Section 9.5, “Point-in-Time (Incremental) Recovery”
</a>
. Alternatively, you can
issue
<a class="link" href="show-relaylog-events.html" title="15.7.7.34 SHOW RELAYLOG EVENTS Statement">
<code class="literal">
SHOW RELAYLOG EVENTS
</code>
</a>
on the
replica or
<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>
on
the source.
</p>
<p>
Before skipping the transaction and restarting the replica,
check these points:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Is the transaction that stopped replication from an unknown
or untrusted source? If so, investigate the cause in case
there are any security considerations that indicate the
replica should not be restarted.
</p>
</li>
<li class="listitem">
<p>
Does the transaction that stopped replication need to be
applied on the replica? If so, either make the appropriate
corrections and reapply the transaction, or manually
reconcile the data on the replica.
</p>
</li>
<li class="listitem">
<p>
Did the transaction that stopped replication need to be
applied on the source? If not, undo the transaction manually
on the server where it originally took place.
</p>
</li>
</ul>
</div>
<p>
To skip the transaction, choose one of the following methods as
appropriate:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
When 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>
), see
<a class="xref" href="replication-administration-skip.html#replication-administration-skip-gtid" title="19.1.7.3.1 Skipping Transactions With GTIDs">
Section 19.1.7.3.1, “Skipping Transactions With GTIDs”
</a>
.
</p>
</li>
<li class="listitem">
<p>
When GTIDs are not in use or are being phased in
(
<a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
<code class="literal">
gtid_mode
</code>
</a>
is
<code class="literal">
OFF
</code>
,
<code class="literal">
OFF_PERMISSIVE
</code>
,
or
<code class="literal">
ON_PERMISSIVE
</code>
), see
<a class="xref" href="replication-administration-skip.html#replication-administration-skip-nogtid" title="19.1.7.3.2 Skipping Transactions Without GTIDs">
Section 19.1.7.3.2, “Skipping Transactions Without GTIDs”
</a>
.
</p>
</li>
<li class="listitem">
<p>
If you have enabled GTID assignment on a replication channel
using the
<code class="literal">
ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS
</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, see
<a class="xref" href="replication-administration-skip.html#replication-administration-skip-nogtid" title="19.1.7.3.2 Skipping Transactions Without GTIDs">
Section 19.1.7.3.2, “Skipping Transactions Without GTIDs”
</a>
.
Using
<code class="literal">
ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS
</code>
on
a replication channel is not the same as introducing
GTID-based replication for the channel, and you cannot use
the transaction skipping method for GTID-based replication
with those channels.
</p>
</li>
</ul>
</div>
<p>
To restart replication after skipping the transaction, issue
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START REPLICA
</code>
</a>
, with the
<code class="literal">
FOR CHANNEL
</code>
clause if the replica is a
multi-source replica.
</p>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="replication-administration-skip-gtid">
</a>
19.1.7.3.1 Skipping Transactions With GTIDs
</h5>
</div>
</div>
</div>
<p>
When 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>
), the GTID for a committed transaction
is persisted on the replica even if the content of the
transaction is filtered out. This feature prevents a replica
from retrieving previously filtered transactions when it
reconnects to the source using GTID auto-positioning. It can
also be used to skip a transaction on the replica, by
committing an empty transaction in place of the failing
transaction.
</p>
<p>
This method of skipping transactions is not suitable when you
have enabled GTID assignment on a replication channel using
the
<code class="literal">
ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS
</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.
</p>
<p>
If the failing transaction generated an error in a worker
thread, you can obtain its GTID directly from the
<code class="literal">
APPLYING_TRANSACTION
</code>
field in the
Performance Schema table
<a class="link" href="performance-schema-replication-applier-status-by-worker-table.html" title="29.12.11.7 The replication_applier_status_by_worker Table">
<code class="literal">
replication_applier_status_by_worker
</code>
</a>
.
To see what the transaction is, issue
<a class="link" href="show-relaylog-events.html" title="15.7.7.34 SHOW RELAYLOG EVENTS Statement">
<code class="literal">
SHOW RELAYLOG EVENTS
</code>
</a>
on the
replica or
<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>
on the source, and search the output for a
transaction preceded by that GTID.
</p>
<p>
When you have assessed the failing transaction for any other
appropriate actions as described previously (such as security
considerations), to skip it, commit an empty transaction on
the replica that has the same GTID as the failing transaction.
For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25462689"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> GTID_NEXT<span class="token operator">=</span><span class="token string">'aaa-bbb-ccc-ddd:N'</span><span class="token punctuation">;</span>
<span class="token keyword">BEGIN</span><span class="token punctuation">;</span>
<span class="token keyword">COMMIT</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> GTID_NEXT<span class="token operator">=</span><span class="token string">'AUTOMATIC'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The presence of this empty transaction on the replica means
that when you issue a
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START
REPLICA
</code>
</a>
statement to restart replication, the
replica uses the auto-skip function to ignore the failing
transaction, because it sees a transaction with that GTID has
already been applied. If the replica is a multi-source
replica, you do not need to specify the channel name when you
commit the empty transaction, but you do need to specify the
channel name when you issue
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START
REPLICA
</code>
</a>
.
</p>
<p>
Note that if binary logging is in use on this replica, the
empty transaction enters the replication stream if the replica
becomes a source or primary in the future. If you need to
avoid this possibility, consider flushing and purging the
replica's binary logs, as in this example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42998628"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">FLUSH</span> <span class="token keyword">LOGS</span><span class="token punctuation">;</span>
<span class="token keyword">PURGE</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token keyword">TO</span> <span class="token string">'binlog.000146'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The GTID of the empty transaction is persisted, but the
transaction itself is removed by purging the binary log files.
</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="replication-administration-skip-nogtid">
</a>
19.1.7.3.2 Skipping Transactions Without GTIDs
</h5>
</div>
</div>
</div>
<p>
To skip failing transactions when GTIDs are not in use or are
being phased in (
<a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
<code class="literal">
gtid_mode
</code>
</a>
is
<code class="literal">
OFF
</code>
,
<code class="literal">
OFF_PERMISSIVE
</code>
, or
<code class="literal">
ON_PERMISSIVE
</code>
), you can skip a specified
number of events by issuing
<code class="literal">
SET GLOBAL
sql_replica_skip_counter
</code>
. Alternatively, you can
skip past an event or events by issuing a
<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 to move the source binary log position forward.
</p>
<p>
These methods are also suitable when you have enabled GTID
assignment on a replication channel using the
<code class="literal">
ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS
</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.
</p>
<p>
When you use these methods, it is important to understand that
you are not necessarily skipping a complete transaction, as is
always the case with the GTID-based method described
previously. These non-GTID-based methods are not aware of
transactions as such, but instead operate on events. The
binary log is organized as a sequence of groups known as event
groups, and each event group consists of a sequence of events.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For transactional tables, an event group corresponds to a
transaction.
</p>
</li>
<li class="listitem">
<p>
For nontransactional tables, an event group corresponds to
a single SQL statement.
</p>
</li>
</ul>
</div>
<p>
A single transaction can contain changes to both transactional
and nontransactional tables.
</p>
<p>
When you use a
<code class="literal">
SET GLOBAL
sql_replica_skip_counter
</code>
statement to skip events
and the resulting position is in the middle of an event group,
the replica continues to skip events until it reaches the end
of the group. Execution then starts with the next event group.
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 does not have this function, so you
must be careful to identify the correct location to restart
replication at the beginning of an event group. However, using
<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>
means you do not have to count the events that need to be
skipped, as you do with
<code class="literal">
SET GLOBAL
sql_replica_skip_counter
</code>
, and instead you can just
specify the location to restart.
</p>
<div class="section">
<div class="titlepage">
<div>
<div>
<h6 class="title">
<a name="set-global-replica-sql-skip-counter">
</a>
19.1.7.3.2.1 Skipping Transactions With
<code class="literal">
SET GLOBAL
sql_replica_skip_counter
</code>
</h6>
</div>
</div>
</div>
<a class="indexterm" name="idm46045138609520">
</a>
<a class="indexterm" name="idm46045138608432">
</a>
<a class="indexterm" name="idm46045138607344">
</a>
<a class="indexterm" name="idm46045138606272">
</a>
<p>
When you have assessed the failing transaction for any other
appropriate actions as described previously (such as
security considerations), count the number of events that
you need to skip. One event normally corresponds to one SQL
statement in the binary log, but note that statements that
use
<code class="literal">
AUTO_INCREMENT
</code>
or
<a class="link" href="information-functions.html#function_last-insert-id">
<code class="literal">
LAST_INSERT_ID()
</code>
</a>
count as two
events in the binary log. When binary log transaction
compression is in use, a compressed transaction payload
(
<code class="literal">
Transaction_payload_event
</code>
) is counted as
a single counter value, so all the events inside it are
skipped as a unit.
</p>
<p>
If you want to skip the complete transaction, you can count
the events to the end of the transaction, or you can just
skip the relevant event group. Remember that with
<a class="link" href="set-variable.html#set-variable-system-variables" title="System Variable Assignment">
<code class="literal">
SET
GLOBAL sql_replica_skip_counter
</code>
</a>
, the replica
continues to skip to the end of an event group. Make sure
you do not skip too far forward and go into the next event
group or transaction so that it is not also skipped.
</p>
<p>
Issue the
<code class="literal">
SET
</code>
statement as follows, where
<em class="replaceable">
<code>
N
</code>
</em>
is the number of events from
the source to skip:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa35169989"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> sql_replica_skip_counter <span class="token operator">=</span> <em class="replaceable">N</em></code></pre>
</div>
<p>
This statement cannot be issued if
<a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
<code class="literal">
gtid_mode=ON
</code>
</a>
is set, or if
the replication I/O (receiver) and SQL (applier) threads are
running.
</p>
<p>
The
<code class="literal">
SET GLOBAL sql_replica_skip_counter
</code>
statement has no immediate effect. When you issue the
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START REPLICA
</code>
</a>
statement for
the next time following this
<code class="literal">
SET
</code>
statement, the new value for the system variable
<a class="link" href="replication-options-replica.html#sysvar_sql_replica_skip_counter">
<code class="literal">
sql_replica_skip_counter
</code>
</a>
is
applied, and the events are skipped. That
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START REPLICA
</code>
</a>
statement also
automatically sets the value of the system variable back to
0. If the replica is a multi-source replica, when you issue
that
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START REPLICA
</code>
</a>
statement,
the
<code class="literal">
FOR CHANNEL
</code>
clause is required. Make
sure that you name the correct channel, otherwise events are
skipped on the wrong channel.
</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h6 class="title">
<a name="replication-administration-skip-change-master-to">
</a>
19.1.7.3.2.2 Skipping Transactions With CHANGE REPLICATION SOURCE TO
</h6>
</div>
</div>
</div>
<p>
When you have assessed the failing transaction for any other
appropriate actions as described previously (such as
security considerations), identify the coordinates (file and
position) in the source's binary log that represent a
suitable position to restart replication. This can be the
start of the event group following the event that caused the
issue, or the start of the next transaction. The replication
I/O (receiver) thread begins reading from the source at
these coordinates the next time the thread starts, skipping
the failing event. Make sure that you have identified the
position accurately, because this statement does not take
event groups into account.
</p>
<p>
Issue 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 follows, where
<em class="replaceable">
<code>
source_log_name
</code>
</em>
is the binary log
file that contains the restart position, and
<em class="replaceable">
<code>
source_log_pos
</code>
</em>
is the number
representing the restart position as stated in the binary
log file:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa94724534"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">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_LOG_FILE</span><span class="token operator">=</span><span class="token string">'<em class="replaceable">source_log_name</em>'</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_LOG_POS</span><span class="token operator">=</span><span class="token keyword"><em class="replaceable">source_log_pos</em></span><span class="token punctuation">;</span></code></pre>
</div>
<p>
If the replica is a multi-source replica, you must use the
<code class="literal">
FOR CHANNEL
</code>
clause to name the
appropriate channel on 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.
</p>
<p>
This statement cannot be issued if
<code class="literal">
SOURCE_AUTO_POSITION
</code>
is
<code class="literal">
1
</code>
, or if the replication I/O (receiver)
and SQL (applier) threads are running. If you need to use
this method of skipping a transaction when
<code class="literal">
SOURCE_AUTO_POSITION=1
</code>
, you can change
the setting to
<code class="literal">
SOURCE_AUTO_POSITION=0
</code>
while issuing the statement, then change it back again
afterwards. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa55153551"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">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_AUTO_POSITION</span><span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_LOG_FILE</span><span class="token operator">=</span><span class="token string">'binlog.000145'</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_LOG_POS</span><span class="token operator">=</span><span class="token number">235</span><span class="token punctuation">;</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_AUTO_POSITION</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span></code></pre>
</div>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/gis-class-multisurface.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="gis-class-multisurface">
</a>
13.4.2.12 MultiSurface Class
</h4>
</div>
</div>
</div>
<p>
A
<code class="literal">
MultiSurface
</code>
is a geometry collection
composed of surface elements.
<code class="literal">
MultiSurface
</code>
is a noninstantiable class. Its only instantiable subclass is
<code class="literal">
MultiPolygon
</code>
.
</p>
<p>
<span class="bold">
<strong>
<code class="literal">
MultiSurface
</code>
Assertions
</strong>
</span>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Surfaces within a
<code class="literal">
MultiSurface
</code>
have no
interiors that intersect.
</p>
</li>
<li class="listitem">
<p>
Surfaces within a
<code class="literal">
MultiSurface
</code>
have
boundaries that intersect at most at a finite number of
points.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/components.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="components">
</a>
7.5 MySQL Components
</h2>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<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>
</div>
<a class="indexterm" name="idm46045257357408">
</a>
<p>
MySQL Server includes a component-based infrastructure for extending
server capabilities. A component provides services that are
available to the server and other components. (With respect to
service use, the server is a component, equal to other components.)
Components interact with each other only through the services they
provide.
</p>
<p>
MySQL distributions include several components that implement server
extensions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Components for configuring error logging. See
<a class="xref" href="error-log.html" title="7.4.2 The Error Log">
Section 7.4.2, “The Error Log”
</a>
, and
<a class="xref" href="error-log-components.html" title="7.5.3 Error Log Components">
Section 7.5.3, “Error Log Components”
</a>
.
</p>
</li>
<li class="listitem">
<p>
A component for checking passwords. 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>
.
</p>
</li>
<li class="listitem">
<p>
Keyring components provide secure storage for sensitive
information. See
<a class="xref" href="keyring.html" title="8.4.4 The MySQL Keyring">
Section 8.4.4, “The MySQL Keyring”
</a>
.
</p>
</li>
<li class="listitem">
<p>
A component that enables applications to add their own message
events to the audit log. See
<a class="xref" href="audit-api-message-emit.html" title="8.4.6 The Audit Message Component">
Section 8.4.6, “The Audit Message Component”
</a>
.
</p>
</li>
<li class="listitem">
<p>
A component that implements a loadable function for accessing
query attributes. See
<a class="xref" href="query-attributes.html" title="11.6 Query Attributes">
Section 11.6, “Query Attributes”
</a>
.
</p>
</li>
<li class="listitem">
<p>
A component for scheduling actively executing tasks. See
<a class="xref" href="scheduler-component.html" title="7.5.5 Scheduler Component">
Section 7.5.5, “Scheduler Component”
</a>
.
</p>
</li>
</ul>
</div>
<p>
System and status variables implemented by a component are exposed
when the component is installed and have names that begin with a
component-specific prefix. For example, the
<code class="literal">
log_filter_dragnet
</code>
error log filter component
implements a system variable named
<code class="literal">
log_error_filter_rules
</code>
, the full name of which is
<a class="link" href="server-system-variables.html#sysvar_dragnet.log_error_filter_rules">
<code class="literal">
dragnet.log_error_filter_rules
</code>
</a>
. To
refer to this variable, use the full name.
</p>
<p>
The following sections describe how to install and uninstall
components, and how to determine at runtime which components are
installed and obtain information about them.
</p>
<p>
For information about the internal implementation of components, see
the MySQL Server Doxygen documentation, available at
<a class="ulink" href="/doc/index-other.html" target="_top">
https://dev.mysql.com/doc/index-other.html
</a>
. For example, if you
intend to write your own components, this information is important
for understanding how components work.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-queries.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="performance-schema-queries">
</a>
29.5 Performance Schema Queries
</h2>
</div>
</div>
</div>
<p>
Pre-filtering limits which event information is collected and is
independent of any particular user. By contrast, post-filtering is
performed by individual users through the use of queries with
appropriate
<code class="literal">
WHERE
</code>
clauses that restrict what
event information to select from the events available after
pre-filtering has been applied.
</p>
<p>
In
<a class="xref" href="performance-schema-pre-filtering.html" title="29.4.3 Event Pre-Filtering">
Section 29.4.3, “Event Pre-Filtering”
</a>
, an example
showed how to pre-filter for file instruments. If the event tables
contain both file and nonfile information, post-filtering is
another way to see information only for file events. Add a
<code class="literal">
WHERE
</code>
clause to queries to restrict event
selection appropriately:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63180855"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> THREAD_ID<span class="token punctuation">,</span> NUMBER_OF_BYTES
<span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>events_waits_history
<span class="token keyword">WHERE</span> EVENT_NAME <span class="token operator">LIKE</span> <span class="token string">'wait/io/file/%'</span>
<span class="token operator">AND</span> NUMBER_OF_BYTES <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> THREAD_ID <span class="token punctuation">|</span> NUMBER_OF_BYTES <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> 11 <span class="token punctuation">|</span> 66 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 11 <span class="token punctuation">|</span> 47 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 11 <span class="token punctuation">|</span> 139 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 5 <span class="token punctuation">|</span> 24 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 5 <span class="token punctuation">|</span> 834 <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>
<p>
Most Performance Schema tables have indexes, which gives the
optimizer access to execution plans other than full table scans.
These indexes also improve performance for related objects, such
as
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema views that use those
tables. For more information, see
<a class="xref" href="performance-schema-optimization.html" title="10.2.4 Optimizing Performance Schema Queries">
Section 10.2.4, “Optimizing Performance Schema Queries”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/information-schema-profiling-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="information-schema-profiling-table">
</a>
28.3.24 The INFORMATION_SCHEMA PROFILING Table
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045079091376">
</a>
<p>
The
<a class="link" href="information-schema-profiling-table.html" title="28.3.24 The INFORMATION_SCHEMA PROFILING Table">
<code class="literal">
PROFILING
</code>
</a>
table provides
statement profiling information. Its contents correspond to the
information produced by the
<a class="link" href="show-profile.html" title="15.7.7.32 SHOW PROFILE Statement">
<code class="literal">
SHOW
PROFILE
</code>
</a>
and
<a class="link" href="show-profiles.html" title="15.7.7.33 SHOW PROFILES Statement">
<code class="literal">
SHOW PROFILES
</code>
</a>
statements (see
<a class="xref" href="show-profile.html" title="15.7.7.32 SHOW PROFILE Statement">
Section 15.7.7.32, “SHOW PROFILE Statement”
</a>
). The table is
empty unless the
<a class="link" href="server-system-variables.html#sysvar_profiling">
<code class="literal">
profiling
</code>
</a>
session variable is set to 1.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
This table is deprecated; expect it to be removed in a future
MySQL release. Use the
<a class="link" href="performance-schema.html" title="Chapter 29 MySQL Performance Schema">
Performance Schema
</a>
instead; see
<a class="xref" href="performance-schema-query-profiling.html" title="29.19.1 Query Profiling Using Performance Schema">
Section 29.19.1, “Query Profiling Using Performance Schema”
</a>
.
</p>
</div>
<p>
The
<a class="link" href="information-schema-profiling-table.html" title="28.3.24 The INFORMATION_SCHEMA PROFILING Table">
<code class="literal">
PROFILING
</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">
QUERY_ID
</code>
</p>
<p>
A numeric statement identifier.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SEQ
</code>
</p>
<p>
A sequence number indicating the display order for rows with
the same
<code class="literal">
QUERY_ID
</code>
value.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
STATE
</code>
</p>
<p>
The profiling state to which the row measurements apply.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
DURATION
</code>
</p>
<p>
How long statement execution remained in the given state, in
seconds.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
CPU_USER
</code>
,
<code class="literal">
CPU_SYSTEM
</code>
</p>
<p>
User and system CPU use, in seconds.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
CONTEXT_VOLUNTARY
</code>
,
<code class="literal">
CONTEXT_INVOLUNTARY
</code>
</p>
<p>
How many voluntary and involuntary context switches occurred.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
BLOCK_OPS_IN
</code>
,
<code class="literal">
BLOCK_OPS_OUT
</code>
</p>
<p>
The number of block input and output operations.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MESSAGES_SENT
</code>
,
<code class="literal">
MESSAGES_RECEIVED
</code>
</p>
<p>
The number of communication messages sent and received.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
PAGE_FAULTS_MAJOR
</code>
,
<code class="literal">
PAGE_FAULTS_MINOR
</code>
</p>
<p>
The number of major and minor page faults.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SWAPS
</code>
</p>
<p>
How many swaps occurred.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SOURCE_FUNCTION
</code>
,
<code class="literal">
SOURCE_FILE
</code>
, and
<code class="literal">
SOURCE_LINE
</code>
</p>
<p>
Information indicating where in the source code the profiled
state executes.
</p>
</li>
</ul>
</div>
<h4>
<a name="idm46045079052144">
</a>
Notes
</h4>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="information-schema-profiling-table.html" title="28.3.24 The INFORMATION_SCHEMA PROFILING Table">
<code class="literal">
PROFILING
</code>
</a>
is a nonstandard
<code class="literal">
INFORMATION_SCHEMA
</code>
table.
</p>
</li>
</ul>
</div>
<p>
Profiling information is also available from the
<a class="link" href="show-profile.html" title="15.7.7.32 SHOW PROFILE Statement">
<code class="literal">
SHOW PROFILE
</code>
</a>
and
<a class="link" href="show-profiles.html" title="15.7.7.33 SHOW PROFILES Statement">
<code class="literal">
SHOW PROFILES
</code>
</a>
statements. See
<a class="xref" href="show-profile.html" title="15.7.7.32 SHOW PROFILE Statement">
Section 15.7.7.32, “SHOW PROFILE Statement”
</a>
. For example, the following queries
are equivalent:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa81750058"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">PROFILE</span> <span class="token keyword">FOR</span> <span class="token keyword">QUERY</span> <span class="token number">2</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> STATE<span class="token punctuation">,</span> <span class="token function">FORMAT</span><span class="token punctuation">(</span>DURATION<span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> DURATION
<span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>PROFILING
<span class="token keyword">WHERE</span> QUERY_ID <span class="token operator">=</span> <span class="token number">2</span> <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> SEQ<span class="token punctuation">;</span></code></pre>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/correlated-subqueries.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="correlated-subqueries">
</a>
15.2.15.7 Correlated Subqueries
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045179843952">
</a>
<a class="indexterm" name="idm46045179842880">
</a>
<p>
A
<span class="emphasis">
<em>
correlated subquery
</em>
</span>
is a subquery that
contains a reference to a table that also appears in the outer
query. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa87575520"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">WHERE</span> column1 <span class="token operator">=</span> <span class="token keyword">ANY</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> column1 <span class="token keyword">FROM</span> t2
<span class="token keyword">WHERE</span> t2<span class="token punctuation">.</span>column2 <span class="token operator">=</span> t1<span class="token punctuation">.</span>column2<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Notice that the subquery contains a reference to a column of
<code class="literal">
t1
</code>
, even though the subquery's
<code class="literal">
FROM
</code>
clause does not mention a table
<code class="literal">
t1
</code>
. So, MySQL looks outside the subquery, and
finds
<code class="literal">
t1
</code>
in the outer query.
</p>
<p>
Suppose that table
<code class="literal">
t1
</code>
contains a row where
<code class="literal">
column1 = 5
</code>
and
<code class="literal">
column2 =
6
</code>
; meanwhile, table
<code class="literal">
t2
</code>
contains a
row where
<code class="literal">
column1 = 5
</code>
and
<code class="literal">
column2 =
7
</code>
. The simple expression
<code class="literal">
... WHERE column1 =
ANY (SELECT column1 FROM t2)
</code>
would be
<code class="literal">
TRUE
</code>
, but in this example, the
<code class="literal">
WHERE
</code>
clause within the subquery is
<code class="literal">
FALSE
</code>
(because
<code class="literal">
(5,6)
</code>
is
not equal to
<code class="literal">
(5,7)
</code>
), so the expression as a
whole is
<code class="literal">
FALSE
</code>
.
</p>
<p>
<span class="bold">
<strong>
Scoping rule:
</strong>
</span>
MySQL evaluates
from inside to outside. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84418658"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> column1 <span class="token keyword">FROM</span> t1 <span class="token keyword">AS</span> x
<span class="token keyword">WHERE</span> x<span class="token punctuation">.</span>column1 <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> column1 <span class="token keyword">FROM</span> t2 <span class="token keyword">AS</span> x
<span class="token keyword">WHERE</span> x<span class="token punctuation">.</span>column1 <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> column1 <span class="token keyword">FROM</span> t3
<span class="token keyword">WHERE</span> x<span class="token punctuation">.</span>column2 <span class="token operator">=</span> t3<span class="token punctuation">.</span>column1<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
In this statement,
<code class="literal">
x.column2
</code>
must be a column
in table
<code class="literal">
t2
</code>
because
<code class="literal">
SELECT column1
FROM t2 AS x ...
</code>
renames
<code class="literal">
t2
</code>
. It is
not a column in table
<code class="literal">
t1
</code>
because
<code class="literal">
SELECT column1 FROM t1 ...
</code>
is an outer query
that is
<span class="emphasis">
<em>
farther out
</em>
</span>
.
</p>
<p>
The optimizer can transform a correlated scalar subquery to a
derived table when the
<a class="link" href="switchable-optimizations.html#optflag_subquery-to-derived">
<code class="literal">
subquery_to_derived
</code>
</a>
flag of
the
<a class="link" href="server-system-variables.html#sysvar_optimizer_switch">
<code class="literal">
optimizer_switch
</code>
</a>
variable
is enabled. Consider the query shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa8871677"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">WHERE</span> <span class="token punctuation">(</span> <span class="token keyword">SELECT</span> a <span class="token keyword">FROM</span> t2
<span class="token keyword">WHERE</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 operator">></span> <span class="token number">0</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
To avoid materializing several times for a given derived table,
we can instead materialize—once—a derived table
which adds a grouping on the join column from the table
referenced in the inner query (
<code class="literal">
t2.a
</code>
) and then
an outer join on the lifted predicate (
<code class="literal">
t1.a =
derived.a
</code>
) in order to select the correct group to
match up with the outer row. (If the subquery already has an
explicit grouping, the extra grouping is added to the end of the
grouping list.) The query previously shown can thus be rewritten
like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61085932"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> t1<span class="token punctuation">.</span><span class="token operator">*</span> <span class="token keyword">FROM</span> t1
<span class="token keyword">LEFT</span> <span class="token keyword">OUTER</span> <span class="token keyword">JOIN</span>
<span class="token punctuation">(</span><span class="token keyword">SELECT</span> a<span class="token punctuation">,</span> <span class="token function">COUNT</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> ct <span class="token keyword">FROM</span> t2 <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> a<span class="token punctuation">)</span> <span class="token keyword">AS</span> derived
<span class="token keyword">ON</span> t1<span class="token punctuation">.</span>a <span class="token operator">=</span> derived<span class="token punctuation">.</span>a
<span class="token operator">AND</span>
REJECT_IF<span class="token punctuation">(</span>
<span class="token punctuation">(</span>ct <span class="token operator">></span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string">"ERROR 1242 (21000): Subquery returns more than 1 row"</span>
<span class="token punctuation">)</span>
<span class="token keyword">WHERE</span> derived<span class="token punctuation">.</span>a <span class="token operator">></span> <span class="token number">0</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
In the rewritten query,
<code class="literal">
REJECT_IF()
</code>
represents an internal function which tests a given condition
(here, the comparison
<code class="literal">
ct > 1
</code>
) and raises a
given error (in this case,
<a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_subquery_no_1_row" target="_top">
<code class="literal">
ER_SUBQUERY_NO_1_ROW
</code>
</a>
) if the
condition is true. This reflects the cardinality check that the
optimizer performs as part of evaluating the
<code class="literal">
JOIN
</code>
or
<code class="literal">
WHERE
</code>
clause,
prior to evaluating any lifted predicate, which is done only if
the subquery does not return more than one row.
</p>
<p>
This type of transformation can be performed, provided the
following conditions are met:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The subquery can be part of a
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
list,
<code class="literal">
WHERE
</code>
condition, or
<code class="literal">
HAVING
</code>
condition, but cannot be part of a
<a class="link" href="join.html" title="15.2.13.2 JOIN Clause">
<code class="literal">
JOIN
</code>
</a>
condition, and cannot
contain a
<code class="literal">
LIMIT
</code>
or
<code class="literal">
OFFSET
</code>
clause. In addition, the subquery
cannot contain any set operations such as
<a class="link" href="union.html" title="15.2.18 UNION Clause">
<code class="literal">
UNION
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
WHERE
</code>
clause may contain one or more
predicates, combined with
<code class="literal">
AND
</code>
. If the
<code class="literal">
WHERE
</code>
clause contains an
<code class="literal">
OR
</code>
clause, it cannot be transformed. At
least one of the
<code class="literal">
WHERE
</code>
clause predicates
must be eligible for transformation, and none of them may
reject transformation.
</p>
</li>
<li class="listitem">
<p>
To be eligible for transformation, a
<code class="literal">
WHERE
</code>
clause predicate must be an
equality predicate in which each operand should be a simple
column reference. No other predicates—including other
comparison predicates—are eligible for transformation.
The predicate must employ the equality operator
<a class="link" href="comparison-operators.html#operator_equal">
<code class="literal">
=
</code>
</a>
for making
the comparison; the null-safe
<a class="link" href="comparison-operators.html#operator_equal-to">
<code class="literal">
<=>
</code>
</a>
operator is not supported in this context.
</p>
</li>
<li class="listitem">
<p>
A
<code class="literal">
WHERE
</code>
clause predicate that contains
only inner references is not eligible for transformation,
since it can be evaluated before the grouping. A
<code class="literal">
WHERE
</code>
clause predicate that contains only
outer references is eligible for transformation, even though
it can be lifted up to the outer query block. This is made
possible by adding a cardinality check without grouping in
the derived table.
</p>
</li>
<li class="listitem">
<p>
To be eligible, a
<code class="literal">
WHERE
</code>
clause predicate
must have one operand that contains only inner references
and one operand that contains only outer references. If the
predicate is not eligible due to this rule, transformation
of the query is rejected.
</p>
</li>
<li class="listitem">
<p>
A correlated column can be present only in the
subquery's
<code class="literal">
WHERE
</code>
clause (and not in
the
<code class="literal">
SELECT
</code>
list, a
<code class="literal">
JOIN
</code>
or
<code class="literal">
ORDER BY
</code>
clause, a
<code class="literal">
GROUP BY
</code>
list, or a
<code class="literal">
HAVING
</code>
clause). Nor can there be any
correlated column inside a derived table in the
subquery's
<code class="literal">
FROM
</code>
list.
</p>
</li>
<li class="listitem">
<p>
A correlated column can not be contained in an aggregate
function's list of arguments.
</p>
</li>
<li class="listitem">
<p>
A correlated column must be resolved in the query block
directly containing the subquery being considered for
transformation.
</p>
</li>
<li class="listitem">
<p>
A correlated column cannot be present in a nested scalar
subquery in the
<code class="literal">
WHERE
</code>
clause.
</p>
</li>
<li class="listitem">
<p>
The subquery cannot contain any window functions, and must
not contain any aggregate function which aggregates in a
query block outer to the subquery. A
<a class="link" href="aggregate-functions.html#function_count">
<code class="literal">
COUNT()
</code>
</a>
aggregate function,
if contained in the
<code class="literal">
SELECT
</code>
list element
of the subquery, must be at the topmost level, and cannot be
part of an expression.
</p>
</li>
</ul>
</div>
<p>
See also
<a class="xref" href="derived-tables.html" title="15.2.15.8 Derived Tables">
Section 15.2.15.8, “Derived Tables”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-users-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="performance-schema-users-table">
</a>
29.12.8.3 The users Table
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045072042864">
</a>
<a class="indexterm" name="idm46045072041376">
</a>
<p>
The
<a class="link" href="performance-schema-users-table.html" title="29.12.8.3 The users Table">
<code class="literal">
users
</code>
</a>
table contains a row
for each user who has connected to the MySQL server. For each
user name, the table counts the current and total number of
connections. The table size is autosized at server startup. To
set the table size explicitly, set the
<a class="link" href="performance-schema-system-variables.html#sysvar_performance_schema_users_size">
<code class="literal">
performance_schema_users_size
</code>
</a>
system variable at server startup. To disable user statistics,
set this variable to 0.
</p>
<p>
The
<a class="link" href="performance-schema-users-table.html" title="29.12.8.3 The users Table">
<code class="literal">
users
</code>
</a>
table has the following
columns. For a description of how the Performance Schema
maintains rows in this table, including the effect of
<a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
<code class="literal">
TRUNCATE TABLE
</code>
</a>
, see
<a class="xref" href="performance-schema-connection-tables.html" title="29.12.8 Performance Schema Connection Tables">
Section 29.12.8, “Performance Schema Connection Tables”
</a>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
USER
</code>
</p>
<p>
The client user name for the connection. This is
<code class="literal">
NULL
</code>
for an internal thread, or for a
user session that failed to authenticate.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
CURRENT_CONNECTIONS
</code>
</p>
<p>
The current number of connections for the user.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
TOTAL_CONNECTIONS
</code>
</p>
<p>
The total number of connections for the user.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MAX_SESSION_CONTROLLED_MEMORY
</code>
</p>
<p>
Reports the maximum amount of controlled memory used by a
session belonging to the user.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MAX_SESSION_TOTAL_MEMORY
</code>
</p>
<p>
Reports the maximum amount of memory used by a session
belonging to the user.
</p>
</li>
</ul>
</div>
<p>
The
<a class="link" href="performance-schema-users-table.html" title="29.12.8.3 The users Table">
<code class="literal">
users
</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">
USER
</code>
)
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/information-schema-column-privileges-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="information-schema-column-privileges-table">
</a>
28.3.10 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045080105888">
</a>
<p>
The
<a class="link" href="information-schema-column-privileges-table.html" title="28.3.10 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table">
<code class="literal">
COLUMN_PRIVILEGES
</code>
</a>
table provides
information about column privileges. It takes its values from the
<code class="literal">
mysql.columns_priv
</code>
system table.
</p>
<p>
The
<a class="link" href="information-schema-column-privileges-table.html" title="28.3.10 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table">
<code class="literal">
COLUMN_PRIVILEGES
</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">
GRANTEE
</code>
</p>
<p>
The name of the account to which the privilege is granted, in
<code class="literal">
'
<em class="replaceable">
<code>
user_name
</code>
</em>
'@'
<em class="replaceable">
<code>
host_name
</code>
</em>
'
</code>
format.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
TABLE_CATALOG
</code>
</p>
<p>
The name of the catalog to which the table containing the
column belongs. This value is always
<code class="literal">
def
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
TABLE_SCHEMA
</code>
</p>
<p>
The name of the schema (database) to which the table
containing the column belongs.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
TABLE_NAME
</code>
</p>
<p>
The name of the table containing the column.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
COLUMN_NAME
</code>
</p>
<p>
The name of the column.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
PRIVILEGE_TYPE
</code>
</p>
<p>
The privilege granted. The value can be any privilege that can
be granted at the column level; see
<a class="xref" href="grant.html" title="15.7.1.6 GRANT Statement">
Section 15.7.1.6, “GRANT Statement”
</a>
.
Each row lists a single privilege, so there is one row per
column privilege held by the grantee.
</p>
<p>
In the output from
<a class="link" href="show-columns.html" title="15.7.7.6 SHOW COLUMNS Statement">
<code class="literal">
SHOW FULL
COLUMNS
</code>
</a>
, the privileges are all in one column and in
lowercase, for example,
<code class="literal">
select,insert,update,references
</code>
. In
<a class="link" href="information-schema-column-privileges-table.html" title="28.3.10 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table">
<code class="literal">
COLUMN_PRIVILEGES
</code>
</a>
, there is one
privilege per row, in uppercase.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
IS_GRANTABLE
</code>
</p>
<p>
<code class="literal">
YES
</code>
if the user has the
<a class="link" href="privileges-provided.html#priv_grant-option">
<code class="literal">
GRANT OPTION
</code>
</a>
privilege,
<code class="literal">
NO
</code>
otherwise. The output does not list
<a class="link" href="privileges-provided.html#priv_grant-option">
<code class="literal">
GRANT OPTION
</code>
</a>
as a separate row
with
<code class="literal">
PRIVILEGE_TYPE='GRANT OPTION'
</code>
.
</p>
</li>
</ul>
</div>
<h4>
<a name="idm46045080074736">
</a>
Notes
</h4>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="information-schema-column-privileges-table.html" title="28.3.10 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table">
<code class="literal">
COLUMN_PRIVILEGES
</code>
</a>
is a
nonstandard
<code class="literal">
INFORMATION_SCHEMA
</code>
table.
</p>
</li>
</ul>
</div>
<p>
The following statements are
<span class="emphasis">
<em>
not
</em>
</span>
equivalent:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49429862"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> INFORMATION_SCHEMA<span class="token punctuation">.</span>COLUMN_PRIVILEGES
<span class="token keyword">SHOW</span> <span class="token keyword">GRANTS</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/clone-plugin-options-variables.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="clone-plugin-options-variables">
</a>
7.6.7.13 Clone System Variables
</h4>
</div>
</div>
</div>
<p>
This section describes the system variables that control
operation of the clone plugin. If values specified at startup
are incorrect, the clone plugin may fail to initialize properly
and the server does not load it. In this case, the server may
also produce error messages for other clone settings because it
does not recognize them.
</p>
<p>
Each system variable has a default value. System variables can
be set at server startup using options on the command line or in
an option file. They can be changed dynamically at runtime using
the
<a class="link" href="set.html" title="13.3.6 The SET Type">
<code class="literal">
SET
</code>
</a>
statement, which enables
you to modify operation of the server without having to stop and
restart it.
</p>
<p>
Setting a global system variable runtime value normally requires
the
<a class="link" href="privileges-provided.html#priv_system-variables-admin">
<code class="literal">
SYSTEM_VARIABLES_ADMIN
</code>
</a>
privilege (or the deprecated
<a class="link" href="privileges-provided.html#priv_super">
<code class="literal">
SUPER
</code>
</a>
privilege). For more
information, 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>
Clone variables are configured on the recipient MySQL server
instance where the cloning operation is executed.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="sysvar_clone_autotune_concurrency">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_autotune_concurrency">
<code class="literal">
clone_autotune_concurrency
</code>
</a>
</p>
<a class="indexterm" name="idm46045255000784">
</a>
<a class="indexterm" name="idm46045254999680">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_autotune_concurrency">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-autotune-concurrency
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_autotune_concurrency">
clone_autotune_concurrency
</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
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_autotune_concurrency">
<code class="literal">
clone_autotune_concurrency
</code>
</a>
is enabled (the default), additional threads for remote
cloning operations are spawned dynamically to optimize data
transfer speed. The setting is applicable to recipient MySQL
server instance only.
</p>
<p>
During a cloning operation, the number of threads increases
incrementally toward a target of double the current thread
count. The effect on the data transfer speed is evaluated at
each increment. The process either continues or stops
according to the following rules:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
If the data transfer speed degrades more than 5% with an
incremental increase, the process stops.
</p>
</li>
<li class="listitem">
<p>
If there is at least a 5% improvement after reaching 25%
of the target, the process continues. Otherwise, the
process stops.
</p>
</li>
<li class="listitem">
<p>
If there is at least a 10% improvement after reaching
50% of the target, the process continues. Otherwise, the
process stops.
</p>
</li>
<li class="listitem">
<p>
If there is at least a 25% improvement after reaching
the target, the process continues toward a new target of
double the current thread count. Otherwise, the process
stops.
</p>
</li>
</ul>
</div>
<p>
The autotuning process does not support decreasing the
number of threads.
</p>
<p>
The
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
<code class="literal">
clone_max_concurrency
</code>
</a>
variable defines the maximum number of threads that can be
spawned.
</p>
<p>
If
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_autotune_concurrency">
<code class="literal">
clone_autotune_concurrency
</code>
</a>
is disabled,
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
<code class="literal">
clone_max_concurrency
</code>
</a>
defines the number of threads spawned for a remote cloning
operation.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_buffer_size">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_buffer_size">
<code class="literal">
clone_buffer_size
</code>
</a>
</p>
<a class="indexterm" name="idm46045254963200">
</a>
<a class="indexterm" name="idm46045254962160">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_buffer_size">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-buffer-size
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_buffer_size">
clone_buffer_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">
4194304
</code>
</td>
</tr>
<tr>
<th>
Minimum Value
</th>
<td>
<code class="literal">
1048576
</code>
</td>
</tr>
<tr>
<th>
Maximum Value
</th>
<td>
<code class="literal">
268435456
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
bytes
</td>
</tr>
</tbody>
</table>
</div>
<p>
Defines the size of the intermediate buffer used when
transferring data during a local cloning operation. The
default value is 4 mebibytes (MiB). A larger buffer size may
permit I/O device drivers to fetch data in parallel, which
can improve cloning performance.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_block_ddl">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_block_ddl">
<code class="literal">
clone_block_ddl
</code>
</a>
</p>
<a class="indexterm" name="idm46045254930432">
</a>
<a class="indexterm" name="idm46045254929344">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_block_ddl">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-block-ddl
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_block_ddl">
clone_block_ddl
</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 an exclusive backup lock on the donor MySQL Server
instance during a cloning operation, which blocks concurrent
DDL operations on the donor. 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>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_delay_after_data_drop">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_delay_after_data_drop">
<code class="literal">
clone_delay_after_data_drop
</code>
</a>
</p>
<a class="indexterm" name="idm46045254904032">
</a>
<a class="indexterm" name="idm46045254902928">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_delay_after_data_drop">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-delay-after-data-drop
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_delay_after_data_drop">
clone_delay_after_data_drop
</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">
3600
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
bytes
</td>
</tr>
</tbody>
</table>
</div>
<p>
Specifies a delay period immediately after removing existing
data on the recipient MySQL Server instance at the start of
a remote cloning operation. The delay is intended to provide
enough time for the file system on the recipient host to
free space before data is cloned from the donor MySQL Server
instance. Certain file systems such as VxFS free space
asynchronously in a background process. On these file
systems, cloning data too soon after dropping existing data
can result in clone operation failures due to insufficient
space. The maximum delay period is 3600 seconds (1 hour).
The default setting is 0 (no delay).
</p>
<p>
This variable is applicable to remote cloning operation only
and is configured on the recipient MySQL Server instance.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_ddl_timeout">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ddl_timeout">
<code class="literal">
clone_ddl_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045254870944">
</a>
<a class="indexterm" name="idm46045254869904">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_ddl_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-ddl-timeout
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ddl_timeout">
clone_ddl_timeout
</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">
300
</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">
2592000
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The time in seconds that a cloning operation waits for a
backup lock. The backup lock blocks concurrent DDL when
executing a cloning operation. This setting is applied on
both the donor and recipient MySQL server instances.
</p>
<p>
A setting of 0 means that the cloning operation does not
wait for a backup lock. In this case, executing a concurrent
DDL operation can cause the cloning operation to fail.
</p>
<p>
Concurrent DDL is permitted on the donor during a cloning
operation if
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_block_ddl">
<code class="literal">
clone_block_ddl
</code>
</a>
is set to
<code class="literal">
OFF
</code>
(the default). In this case, the
cloning operation does not have to wait for a backup lock on
the donor. 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>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_donor_timeout_after_network_failure">
</a>
<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>
</p>
<a class="indexterm" name="idm46045254834240">
</a>
<a class="indexterm" name="idm46045254833136">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_donor_timeout_after_network_failure">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-donor-timeout-after-network-failure
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_donor_timeout_after_network_failure">
clone_donor_timeout_after_network_failure
</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">
5
</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">
30
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
minutes
</td>
</tr>
</tbody>
</table>
</div>
<p>
Defines the amount of time in minutes the donor allows for
the recipient to reconnect and restart a cloning operation
after a network failure. For more information, see
<a class="xref" href="clone-plugin-failure-handling.html" title="7.6.7.9 Remote Cloning Operation Failure Handling">
Section 7.6.7.9, “Remote Cloning Operation Failure Handling”
</a>
.
</p>
<p>
This variable is set on the donor MySQL server instance.
Setting it on the recipient MySQL server instance has no
effect.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_enable_compression">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_enable_compression">
<code class="literal">
clone_enable_compression
</code>
</a>
</p>
<a class="indexterm" name="idm46045254800032">
</a>
<a class="indexterm" name="idm46045254798928">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_enable_compression">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-enable-compression
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_enable_compression">
clone_enable_compression
</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 compression of data at the network layer during a
remote cloning operation. Compression saves network
bandwidth at the cost of CPU. Enabling compression may
improve the data transfer rate. This setting is only applied
on the recipient MySQL server instance.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_max_concurrency">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
<code class="literal">
clone_max_concurrency
</code>
</a>
</p>
<a class="indexterm" name="idm46045254774016">
</a>
<a class="indexterm" name="idm46045254772976">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_max_concurrency">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-max-concurrency
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
clone_max_concurrency
</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">
16
</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">
128
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
threads
</td>
</tr>
</tbody>
</table>
</div>
<p>
Defines the maximum number of concurrent threads for a
remote cloning operation. The default value is 16. A greater
number of threads can improve cloning performance but also
reduces the number of permitted simultaneous client
connections, which can affect the performance of existing
client connections. This setting is only applied on the
recipient MySQL server instance.
</p>
<p>
If
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_autotune_concurrency">
<code class="literal">
clone_autotune_concurrency
</code>
</a>
is enabled (the default),
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
<code class="literal">
clone_max_concurrency
</code>
</a>
is
the maximum number of threads that can be dynamically
spawned for a remote cloning operation. If
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_autotune_concurrency">
<code class="literal">
clone_autotune_concurrency
</code>
</a>
is disabled,
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
<code class="literal">
clone_max_concurrency
</code>
</a>
defines the number of threads spawned for a remote cloning
operation.
</p>
<p>
A minimum data transfer rate of 1 mebibyte (MiB) per thread
is recommended for remote cloning operations. The data
transfer rate for a remote cloning operation is controlled
by the
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_data_bandwidth">
<code class="literal">
clone_max_data_bandwidth
</code>
</a>
variable.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_max_data_bandwidth">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_data_bandwidth">
<code class="literal">
clone_max_data_bandwidth
</code>
</a>
</p>
<a class="indexterm" name="idm46045254733472">
</a>
<a class="indexterm" name="idm46045254732368">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_max_data_bandwidth">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-max-data-bandwidth
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_data_bandwidth">
clone_max_data_bandwidth
</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">
1048576
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
miB/second
</td>
</tr>
</tbody>
</table>
</div>
<p>
Defines the maximum data transfer rate in mebibytes (MiB)
per second for a remote cloning operation. This variable
helps manage the performance impact of a cloning operation.
A limit should be set only when donor disk I/O bandwidth is
saturated, affecting performance. A value of 0 means
<span class="quote">
“
<span class="quote">
unlimited
</span>
”
</span>
, which permits cloning operations
to run at the highest possible data transfer rate. This
setting is only applicable to the recipient MySQL server
instance.
</p>
<p>
The minimum data transfer rate is 1 MiB per second, per
thread. For example, if there are 8 threads, the minimum
transfer rate is 8 MiB per second. The
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_concurrency">
<code class="literal">
clone_max_concurrency
</code>
</a>
variable controls the maximum number threads spawned for a
remote cloning operation.
</p>
<p>
The requested data transfer rate specified by
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_data_bandwidth">
<code class="literal">
clone_max_data_bandwidth
</code>
</a>
may differ from the actual data transfer rate reported by
the
<code class="literal">
DATA_SPEED
</code>
column in the
<code class="literal">
performance_schema.clone_progress
</code>
table.
If your cloning operation is not achieving the desired data
transfer rate and you have available bandwidth, check I/O
usage on the recipient and donor. If there is underutilized
bandwidth, I/O is the next mostly likely bottleneck.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_max_network_bandwidth">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_network_bandwidth">
<code class="literal">
clone_max_network_bandwidth
</code>
</a>
</p>
<a class="indexterm" name="idm46045254694352">
</a>
<a class="indexterm" name="idm46045254693248">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_max_network_bandwidth">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-max-network-bandwidth
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_max_network_bandwidth">
clone_max_network_bandwidth
</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">
1048576
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
miB/second
</td>
</tr>
</tbody>
</table>
</div>
<p>
Specifies the maximum approximate network transfer rate in
mebibytes (MiB) per second for a remote cloning operation.
This variable can be used to manage the performance impact
of a cloning operation on network bandwidth. It should be
set only when network bandwidth is saturated, affecting
performance on the donor instance. A value of 0 means
<span class="quote">
“
<span class="quote">
unlimited
</span>
”
</span>
, which permits cloning at the
highest possible data transfer rate over the network,
providing the best performance. This setting is only
applicable to the recipient MySQL server instance.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_ssl_ca">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ssl_ca">
<code class="literal">
clone_ssl_ca
</code>
</a>
</p>
<a class="indexterm" name="idm46045254660752">
</a>
<a class="indexterm" name="idm46045254659664">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_ssl_ca">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-ssl-ca=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ssl_ca">
clone_ssl_ca
</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>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
empty string
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Specifies the path to the certificate authority (CA) file.
Used to configure an encrypted connection for a remote
cloning operation. This setting configured on the recipient
and used when connecting to the donor.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_ssl_cert">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ssl_cert">
<code class="literal">
clone_ssl_cert
</code>
</a>
</p>
<a class="indexterm" name="idm46045254634960">
</a>
<a class="indexterm" name="idm46045254633872">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_ssl_cert">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-ssl-cert=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ssl_cert">
clone_ssl_cert
</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>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
empty string
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Specifies the path to the public key certificate. Used to
configure an encrypted connection for a remote cloning
operation. This setting configured on the recipient and used
when connecting to the donor.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_ssl_key">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ssl_key">
<code class="literal">
clone_ssl_key
</code>
</a>
</p>
<a class="indexterm" name="idm46045254609184">
</a>
<a class="indexterm" name="idm46045254608096">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_ssl_key">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-ssl-key=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_ssl_key">
clone_ssl_key
</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>
File name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
empty string
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Specifies the path to the private key file. Used to
configure an encrypted connection for a remote cloning
operation. This setting configured on the recipient and used
when connecting to the donor.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_clone_valid_donor_list">
</a>
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_valid_donor_list">
<code class="literal">
clone_valid_donor_list
</code>
</a>
</p>
<a class="indexterm" name="idm46045254583360">
</a>
<a class="indexterm" name="idm46045254582320">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for clone_valid_donor_list">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--clone-valid-donor-list=value
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_valid_donor_list">
clone_valid_donor_list
</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">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Defines valid donor host addresses for remote cloning
operations. This setting is applied on the recipient MySQL
server instance. A comma-separated list of values is
permitted in the following format:
<span class="quote">
“
<span class="quote">
<code class="literal">
HOST1:PORT1,HOST2:PORT2,HOST3:PORT3
</code>
</span>
”
</span>
.
Spaces are not permitted.
</p>
<p>
The
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_valid_donor_list">
<code class="literal">
clone_valid_donor_list
</code>
</a>
variable adds a layer of security by providing control over
the sources of cloned data. The privilege required to
configure
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_valid_donor_list">
<code class="literal">
clone_valid_donor_list
</code>
</a>
is
different from the privilege required to execute remote
cloning operations, which permits assigning those
responsibilities to different roles. Configuring
<a class="link" href="clone-plugin-options-variables.html#sysvar_clone_valid_donor_list">
<code class="literal">
clone_valid_donor_list
</code>
</a>
requires the
<a class="link" href="privileges-provided.html#priv_system-variables-admin">
<code class="literal">
SYSTEM_VARIABLES_ADMIN
</code>
</a>
privilege, whereas executing a remote cloning operation
requires the
<a class="link" href="privileges-provided.html#priv_clone-admin">
<code class="literal">
CLONE_ADMIN
</code>
</a>
privilege.
</p>
<p>
Internet Protocol version 6 (IPv6) address format is not
supported. Internet Protocol version 6 (IPv6) address format
is not supported. An alias to the IPv6 address can be used
instead. An IPv4 address can be used as is.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/sys-schema.html | <div id="docs-body">
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title">
<a name="sys-schema">
</a>
Chapter 30 MySQL sys Schema
</h1>
</div>
</div>
</div>
<div class="toc">
<p>
<b>
Table of Contents
</b>
</p>
<dl class="toc">
<dt>
<span class="section">
<a href="sys-schema-prerequisites.html">
30.1 Prerequisites for Using the sys Schema
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-usage.html">
30.2 Using the sys Schema
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-progress-reporting.html">
30.3 sys Schema Progress Reporting
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-reference.html">
30.4 sys Schema Object Reference
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="sys-schema-object-index.html">
30.4.1 sys Schema Object Index
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-tables.html">
30.4.2 sys Schema Tables and Triggers
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-views.html">
30.4.3 sys Schema Views
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-procedures.html">
30.4.4 sys Schema Stored Procedures
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="sys-schema-functions.html">
30.4.5 sys Schema Stored Functions
</a>
</span>
</dt>
</dl>
</dd>
</dl>
</div>
<p>
MySQL 8.4 includes the
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema, a set of objects that
helps DBAs and developers interpret data collected by the
Performance Schema.
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema objects
can be used for typical tuning and diagnosis use cases. Objects in
this schema include:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Views that summarize Performance Schema data into more easily
understandable form.
</p>
</li>
<li class="listitem">
<p>
Stored procedures that perform operations such as Performance
Schema configuration and generating diagnostic reports.
</p>
</li>
<li class="listitem">
<p>
Stored functions that query Performance Schema configuration and
provide formatting services.
</p>
</li>
</ul>
</div>
<p>
For new installations, the
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema
is installed by default during data directory initialization 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>
with the
<a class="link" href="server-options.html#option_mysqld_initialize">
<code class="option">
--initialize
</code>
</a>
or
<a class="link" href="server-options.html#option_mysqld_initialize-insecure">
<code class="option">
--initialize-insecure
</code>
</a>
option. If this
is not desired, you can drop the
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema manually after initialization if it is unneeded.
</p>
<p>
The MySQL upgrade procedure produces an error if a
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema exists but has no
<a class="link" href="sys-version.html" title="30.4.3.47 The version View">
<code class="literal">
version
</code>
</a>
view, on the assumption that
absence of this view indicates a user-created
<code class="literal">
sys
</code>
schema. To upgrade in this case, remove or rename the existing
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema first.
</p>
<a class="indexterm" name="idm46045064095232">
</a>
<p>
<a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
<code class="literal">
sys
</code>
</a>
schema objects have a
<code class="literal">
DEFINER
</code>
of
<code class="literal">
'mysql.sys'@'localhost'
</code>
. Use of the dedicated
<code class="literal">
mysql.sys
</code>
account avoids problems that occur if a
DBA renames or removes the
<code class="literal">
root
</code>
account.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/innodb-enabling-monitors.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="innodb-enabling-monitors">
</a>
17.17.2 Enabling InnoDB Monitors
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045149420336">
</a>
<a class="indexterm" name="idm46045149418848">
</a>
<p>
When
<code class="literal">
InnoDB
</code>
monitors are enabled for periodic
output,
<code class="literal">
InnoDB
</code>
writes the output to
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
server standard error output
(
<code class="literal">
stderr
</code>
) every 15 seconds, approximately.
</p>
<p>
<code class="literal">
InnoDB
</code>
sends the monitor output to
<code class="literal">
stderr
</code>
rather than to
<code class="literal">
stdout
</code>
or fixed-size memory buffers to avoid potential buffer overflows.
</p>
<p>
On Windows,
<code class="literal">
stderr
</code>
is directed to the default
log file unless configured otherwise. If you want to direct the
output to the console window rather than to the error log, start
the server from a command prompt in a console window with the
<a class="link" href="server-options.html#option_mysqld_console">
<code class="option">
--console
</code>
</a>
option. For more
information, see
<a class="xref" href="error-log-destination-configuration.html#error-log-destination-configuration-windows" title="Default Error Log Destination on Windows">
Default Error Log Destination on Windows
</a>
.
</p>
<p>
On Unix and Unix-like systems,
<code class="literal">
stderr
</code>
is
typically directed to the terminal unless configured otherwise.
For more information, see
<a class="xref" href="error-log-destination-configuration.html#error-log-destination-configuration-unix" title="Default Error Log Destination on Unix and Unix-Like Systems">
Default Error Log Destination on Unix and Unix-Like Systems
</a>
.
</p>
<p>
<code class="literal">
InnoDB
</code>
monitors should only be enabled when you
actually want to see monitor information because output generation
causes some performance decrement. Also, if monitor output is
directed to the error log, the log may become quite large if you
forget to disable the monitor later.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
To assist with troubleshooting,
<code class="literal">
InnoDB
</code>
temporarily enables standard
<code class="literal">
InnoDB
</code>
Monitor
output under certain conditions. For more information, see
<a class="xref" href="innodb-troubleshooting.html" title="17.20 InnoDB Troubleshooting">
Section 17.20, “InnoDB Troubleshooting”
</a>
.
</p>
</div>
<p>
<code class="literal">
InnoDB
</code>
monitor output begins with a header
containing a timestamp and the monitor name. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86452364"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span>
<span class="token number">2014</span><span class="token operator">-</span><span class="token number">10</span><span class="token operator">-</span><span class="token number">16</span> <span class="token number">18</span>:<span class="token number">37</span>:<span class="token number">29</span> <span class="token number">0x7fc2a95c1700</span> INNODB MONITOR OUTPUT
<span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span><span class="token operator">=</span></code></pre>
</div>
<p>
The header for the standard
<code class="literal">
InnoDB
</code>
Monitor
(
<code class="literal">
INNODB MONITOR OUTPUT
</code>
) is also used for the
Lock Monitor because the latter produces the same output with the
addition of extra lock information.
</p>
<p>
The
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output">
<code class="literal">
innodb_status_output
</code>
</a>
and
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output_locks">
<code class="literal">
innodb_status_output_locks
</code>
</a>
system
variables are used to enable the standard
<code class="literal">
InnoDB
</code>
Monitor and
<code class="literal">
InnoDB
</code>
Lock Monitor.
</p>
<p>
The
<a class="link" href="privileges-provided.html#priv_process">
<code class="literal">
PROCESS
</code>
</a>
privilege is required
to enable or disable
<code class="literal">
InnoDB
</code>
Monitors.
</p>
<h4>
<a name="idm46045149390080">
</a>
Enabling the Standard InnoDB Monitor
</h4>
<p>
Enable the standard
<code class="literal">
InnoDB
</code>
Monitor by setting
the
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output">
<code class="literal">
innodb_status_output
</code>
</a>
system
variable to
<code class="literal">
ON
</code>
.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa49827581"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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_status_output<span class="token operator">=</span><span class="token keyword">ON</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
To disable the standard
<code class="literal">
InnoDB
</code>
Monitor, set
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output">
<code class="literal">
innodb_status_output
</code>
</a>
to
<code class="literal">
OFF
</code>
.
</p>
<p>
When you shut down the server, the
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output">
<code class="literal">
innodb_status_output
</code>
</a>
variable is
set to the default
<code class="literal">
OFF
</code>
value.
</p>
<h4>
<a name="idm46045149379760">
</a>
Enabling the InnoDB Lock Monitor
</h4>
<p>
<code class="literal">
InnoDB
</code>
Lock Monitor data is printed with the
<code class="literal">
InnoDB
</code>
Standard Monitor output. Both the
<code class="literal">
InnoDB
</code>
Standard Monitor and
<code class="literal">
InnoDB
</code>
Lock Monitor must be enabled to have
<code class="literal">
InnoDB
</code>
Lock Monitor data printed periodically.
</p>
<p>
To enable the
<code class="literal">
InnoDB
</code>
Lock Monitor, set the
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output_locks">
<code class="literal">
innodb_status_output_locks
</code>
</a>
system
variable to
<code class="literal">
ON
</code>
. Both the
<code class="literal">
InnoDB
</code>
standard Monitor and
<code class="literal">
InnoDB
</code>
Lock Monitor must be enabled to have
<code class="literal">
InnoDB
</code>
Lock Monitor data printed periodically:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa4432794"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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_status_output<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">GLOBAL</span> innodb_status_output_locks<span class="token operator">=</span><span class="token keyword">ON</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
To disable the
<code class="literal">
InnoDB
</code>
Lock Monitor, set
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output_locks">
<code class="literal">
innodb_status_output_locks
</code>
</a>
to
<code class="literal">
OFF
</code>
. Set
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output">
<code class="literal">
innodb_status_output
</code>
</a>
to
<code class="literal">
OFF
</code>
to also disable the
<code class="literal">
InnoDB
</code>
Standard Monitor.
</p>
<p>
When you shut down the server, the
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output">
<code class="literal">
innodb_status_output
</code>
</a>
and
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output_locks">
<code class="literal">
innodb_status_output_locks
</code>
</a>
variables are set to the default
<code class="literal">
OFF
</code>
value.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
To enable the
<code class="literal">
InnoDB
</code>
Lock Monitor for
<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, you are only required to enable
<a class="link" href="innodb-parameters.html#sysvar_innodb_status_output_locks">
<code class="literal">
innodb_status_output_locks
</code>
</a>
.
</p>
</div>
<h4>
<a name="idm46045149354928">
</a>
Obtaining Standard InnoDB Monitor Output On Demand
</h4>
<p>
As an alternative to enabling the standard
<code class="literal">
InnoDB
</code>
Monitor for periodic output, you can
obtain standard
<code class="literal">
InnoDB
</code>
Monitor output on demand
using the
<a class="link" href="show-engine.html" title="15.7.7.16 SHOW ENGINE Statement">
<code class="literal">
SHOW ENGINE
INNODB STATUS
</code>
</a>
SQL statement, which fetches the output to
your client program. If you are using 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>
interactive client, the output is more readable if you replace the
usual semicolon statement terminator with
<code class="literal">
\G
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa11188596"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">ENGINE</span> INNODB <span class="token keyword">STATUS</span>\G</code></pre>
</div>
<p>
<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 also includes
<code class="literal">
InnoDB
</code>
Lock Monitor data if the
<code class="literal">
InnoDB
</code>
Lock Monitor is
enabled.
</p>
<h4>
<a name="idm46045149344096">
</a>
Directing Standard InnoDB Monitor Output to a Status File
</h4>
<p>
Standard
<code class="literal">
InnoDB
</code>
Monitor output can be enabled
and directed to a status file by specifying the
<code class="option">
--innodb-status-file
</code>
option at startup. When this
option is used,
<code class="literal">
InnoDB
</code>
creates a file named
<code class="filename">
innodb_status.
<em class="replaceable">
<code>
pid
</code>
</em>
</code>
in the data directory and writes output to it every 15 seconds,
approximately.
</p>
<p>
<code class="literal">
InnoDB
</code>
removes the status file when the server
is shut down normally. If an abnormal shutdown occurs, the status
file may have to be removed manually.
</p>
<p>
The
<code class="option">
--innodb-status-file
</code>
option is intended for
temporary use, as output generation can affect performance, and
the
<code class="filename">
innodb_status.
<em class="replaceable">
<code>
pid
</code>
</em>
</code>
file can become quite large over time.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/innodb-transaction-model.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="innodb-transaction-model">
</a>
17.7.2 InnoDB Transaction Model
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="innodb-transaction-isolation-levels.html">
17.7.2.1 Transaction Isolation Levels
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="innodb-autocommit-commit-rollback.html">
17.7.2.2 autocommit, Commit, and Rollback
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="innodb-consistent-read.html">
17.7.2.3 Consistent Nonlocking Reads
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="innodb-locking-reads.html">
17.7.2.4 Locking Reads
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045164410880">
</a>
<p>
The
<code class="literal">
InnoDB
</code>
transaction model aims to combine
the best properties of a
<a class="link" href="glossary.html#glos_mvcc" title="MVCC">
multi-versioning
</a>
database with
traditional two-phase locking.
<code class="literal">
InnoDB
</code>
performs
locking at the row level and runs queries as nonlocking
<a class="link" href="glossary.html#glos_consistent_read" title="consistent read">
consistent reads
</a>
by
default, in the style of Oracle. The lock information in
<code class="literal">
InnoDB
</code>
is stored space-efficiently so that lock
escalation is not needed. Typically, several users are permitted
to lock every row in
<code class="literal">
InnoDB
</code>
tables, or any
random subset of the rows, without causing
<code class="literal">
InnoDB
</code>
memory exhaustion.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/window-functions-usage.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="window-functions-usage">
</a>
14.20.2 Window Function Concepts and Syntax
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045192027104">
</a>
<p>
This section describes how to use window functions. Examples use
the same sales information data set as found in the discussion
of the
<a class="link" href="miscellaneous-functions.html#function_grouping">
<code class="literal">
GROUPING()
</code>
</a>
function in
<a class="xref" href="group-by-modifiers.html" title="14.19.2 GROUP BY Modifiers">
Section 14.19.2, “GROUP BY Modifiers”
</a>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72935136"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> sales <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> country<span class="token punctuation">,</span> <span class="token datatype">year</span><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> 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> 2000 <span class="token punctuation">|</span> India <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> India <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> 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> 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> 1500 <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> 1200 <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> 150 <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> 100 <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>
<a class="indexterm" name="idm46045192021408">
</a>
<a class="indexterm" name="idm46045192019920">
</a>
<p>
A window function performs an aggregate-like operation on a set
of query rows. However, whereas an aggregate operation groups
query rows into a single result row, a window function produces
a result for each query row:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The row for which function evaluation occurs is called the
current row.
</p>
</li>
<li class="listitem">
<p>
The query rows related to the current row over which
function evaluation occurs comprise the window for the
current row.
</p>
</li>
</ul>
</div>
<p>
For example, using the sales information table, these two
queries perform aggregate operations that produce a single
global sum for all rows taken as a group, and sums grouped per
country:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa1571482"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">SUM</span><span class="token punctuation">(</span>profit<span class="token punctuation">)</span> <span class="token keyword">AS</span> total_profit
<span class="token keyword">FROM</span> sales<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>
<span class="token output"><span class="token punctuation">|</span> total_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>
<span class="token output"><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>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</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> country_profit
<span class="token keyword">FROM</span> sales
<span class="token keyword">GROUP</span> <span class="token keyword">BY</span> country
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> country<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>
<span class="token output"><span class="token punctuation">|</span> country <span class="token punctuation">|</span> country_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>
<span class="token output"><span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> 1610 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> India <span class="token punctuation">|</span> 1350 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> USA <span class="token punctuation">|</span> 4575 <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></code></pre>
</div>
<p>
By contrast, window operations do not collapse groups of query
rows to a single output row. Instead, they produce a result for
each row. Like the preceding queries, the following query uses
<a class="link" href="aggregate-functions.html#function_sum">
<code class="literal">
SUM()
</code>
</a>
, but this time as a window
function:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa27843023"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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> profit<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">OVER</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> total_profit<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">OVER</span><span class="token punctuation">(</span><span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> country<span class="token punctuation">)</span> <span class="token keyword">AS</span> country_profit
<span class="token keyword">FROM</span> sales
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> country<span class="token punctuation">,</span> <span class="token datatype">year</span><span class="token punctuation">,</span> product<span class="token punctuation">,</span> profit<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>
<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> total_profit <span class="token punctuation">|</span> country_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 class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 7535 <span class="token punctuation">|</span> 1610 <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> 7535 <span class="token punctuation">|</span> 1610 <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> 7535 <span class="token punctuation">|</span> 1610 <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> 75 <span class="token punctuation">|</span> 7535 <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> India <span class="token punctuation">|</span> Calculator <span class="token punctuation">|</span> 75 <span class="token punctuation">|</span> 7535 <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> India <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <span class="token punctuation">|</span> 7535 <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> 7535 <span class="token punctuation">|</span> 4575 <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> 7535 <span class="token punctuation">|</span> 4575 <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> 7535 <span class="token punctuation">|</span> 4575 <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> 1200 <span class="token punctuation">|</span> 7535 <span class="token punctuation">|</span> 4575 <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> 1500 <span class="token punctuation">|</span> 7535 <span class="token punctuation">|</span> 4575 <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> 100 <span class="token punctuation">|</span> 7535 <span class="token punctuation">|</span> 4575 <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> 150 <span class="token punctuation">|</span> 7535 <span class="token punctuation">|</span> 4575 <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></code></pre>
</div>
<a class="indexterm" name="idm46045192001056">
</a>
<p>
Each window operation in the query is signified by inclusion of
an
<code class="literal">
OVER
</code>
clause that specifies how to
partition query rows into groups for processing by the window
function:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The first
<code class="literal">
OVER
</code>
clause is empty, which
treats the entire set of query rows as a single partition.
The window function thus produces a global sum, but does so
for each row.
</p>
</li>
<li class="listitem">
<p>
The second
<code class="literal">
OVER
</code>
clause partitions rows by
country, producing a sum per partition (per country). The
function produces this sum for each partition row.
</p>
</li>
</ul>
</div>
<p>
Window functions are permitted only in the select list and
<code class="literal">
ORDER BY
</code>
clause. Query result rows are
determined from the
<code class="literal">
FROM
</code>
clause, after
<code class="literal">
WHERE
</code>
,
<code class="literal">
GROUP BY
</code>
, and
<code class="literal">
HAVING
</code>
processing, and windowing execution
occurs before
<code class="literal">
ORDER BY
</code>
,
<code class="literal">
LIMIT
</code>
, and
<code class="literal">
SELECT
DISTINCT
</code>
.
</p>
<p>
The
<code class="literal">
OVER
</code>
clause is permitted for many
aggregate functions, which therefore can be used as window or
nonwindow functions, depending on whether the
<code class="literal">
OVER
</code>
clause is present or absent:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99035177"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token function">AVG</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">BIT_AND</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">BIT_OR</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">BIT_XOR</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">COUNT</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">JSON_ARRAYAGG</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">JSON_OBJECTAGG</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">MAX</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">MIN</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">STDDEV_POP</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">STDDEV</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">STD</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">STDDEV_SAMP</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">SUM</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">VAR_POP</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">VARIANCE</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">VAR_SAMP</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></pre>
</div>
<p>
For details about each aggregate function, see
<a class="xref" href="aggregate-functions.html" title="14.19.1 Aggregate Function Descriptions">
Section 14.19.1, “Aggregate Function Descriptions”
</a>
.
</p>
<p>
MySQL also supports nonaggregate functions that are used only as
window functions. For these, the
<code class="literal">
OVER
</code>
clause
is mandatory:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa312564"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token function">CUME_DIST</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">DENSE_RANK</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">FIRST_VALUE</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">LAG</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">LAST_VALUE</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">LEAD</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">NTH_VALUE</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">NTILE</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">PERCENT_RANK</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">RANK</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">ROW_NUMBER</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></pre>
</div>
<p>
For details about each nonaggregate function, see
<a class="xref" href="window-function-descriptions.html" title="14.20.1 Window Function Descriptions">
Section 14.20.1, “Window Function Descriptions”
</a>
.
</p>
<p>
As an example of one of those nonaggregate window functions,
this query uses
<a class="link" href="window-function-descriptions.html#function_row-number">
<code class="literal">
ROW_NUMBER()
</code>
</a>
,
which produces the row number of each row within its partition.
In this case, rows are numbered per country. By default,
partition rows are unordered and row numbering is
nondeterministic. To sort partition rows, include an
<code class="literal">
ORDER BY
</code>
clause within the window definition.
The query uses unordered and ordered partitions (the
<code class="literal">
row_num1
</code>
and
<code class="literal">
row_num2
</code>
columns) to illustrate the difference between omitting and
including
<code class="literal">
ORDER BY
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96227456"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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> profit<span class="token punctuation">,</span>
<span class="token function">ROW_NUMBER</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">OVER</span><span class="token punctuation">(</span><span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> country<span class="token punctuation">)</span> <span class="token keyword">AS</span> row_num1<span class="token punctuation">,</span>
<span class="token function">ROW_NUMBER</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">OVER</span><span class="token punctuation">(</span><span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> country <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> <span class="token datatype">year</span><span class="token punctuation">,</span> product<span class="token punctuation">)</span> <span class="token keyword">AS</span> row_num2
<span class="token keyword">FROM</span> sales<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>
<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> row_num1 <span class="token punctuation">|</span> row_num2 <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>
<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> 2 <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> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 100 <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> 2001 <span class="token punctuation">|</span> Finland <span class="token punctuation">|</span> Phone <span class="token punctuation">|</span> 10 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 3 <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> 75 <span class="token punctuation">|</span> 2 <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> 75 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span> 2 <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> 1 <span class="token punctuation">|</span> 3 <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> 5 <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> Computer <span class="token punctuation">|</span> 1500 <span class="token punctuation">|</span> 4 <span class="token punctuation">|</span> 2 <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> 2 <span class="token punctuation">|</span> 3 <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> 1500 <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> 2001 <span class="token punctuation">|</span> USA <span class="token punctuation">|</span> Computer <span class="token punctuation">|</span> 1200 <span class="token punctuation">|</span> 7 <span class="token punctuation">|</span> 5 <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> 150 <span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 6 <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> 100 <span class="token punctuation">|</span> 6 <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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>
As mentioned previously, to use a window function (or treat an
aggregate function as a window function), include an
<code class="literal">
OVER
</code>
clause following the function call. The
<code class="literal">
OVER
</code>
clause has two forms:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa71486739"><div class="copy-help left">Press ⌘+C to copy</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">over_clause</em>:
{<span class="token keyword">OVER</span> <span class="token punctuation">(</span><em class="replaceable">window_spec</em><span class="token punctuation">)</span> <span class="token operator">|</span> <span class="token keyword">OVER</span> <em class="replaceable">window_name</em>}</code></pre>
</div>
<p>
Both forms define how the window function should process query
rows. They differ in whether the window is defined directly in
the
<code class="literal">
OVER
</code>
clause, or supplied by a reference
to a named window defined elsewhere in the query:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
In the first case, the window specification appears directly
in the
<code class="literal">
OVER
</code>
clause, between the
parentheses.
</p>
</li>
<li class="listitem">
<p>
In the second case,
<em class="replaceable">
<code>
window_name
</code>
</em>
is the name for a window specification defined by a
<code class="literal">
WINDOW
</code>
clause elsewhere in the query. For
details, see
<a class="xref" href="window-functions-named-windows.html" title="14.20.4 Named Windows">
Section 14.20.4, “Named Windows”
</a>
.
</p>
</li>
</ul>
</div>
<p>
For
<code class="literal">
OVER
(
<em class="replaceable">
<code>
window_spec
</code>
</em>
)
</code>
syntax, the
window specification has several parts, all optional:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa92301187"><div class="copy-help left">Press ⌘+C to copy</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">window_spec</em>:
<span class="token punctuation">[</span><em class="replaceable">window_name</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">partition_clause</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">order_clause</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">frame_clause</em><span class="token punctuation">]</span></code></pre>
</div>
<p>
If
<code class="literal">
OVER()
</code>
is empty, the window consists of
all query rows and the window function computes a result using
all rows. Otherwise, the clauses present within the parentheses
determine which query rows are used to compute the function
result and how they are partitioned and ordered:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<em class="replaceable">
<code>
window_name
</code>
</em>
: The name of a window
defined by a
<code class="literal">
WINDOW
</code>
clause elsewhere in
the query. If
<em class="replaceable">
<code>
window_name
</code>
</em>
appears
by itself within the
<code class="literal">
OVER
</code>
clause, it
completely defines the window. If partitioning, ordering, or
framing clauses are also given, they modify interpretation
of the named window. For details, see
<a class="xref" href="window-functions-named-windows.html" title="14.20.4 Named Windows">
Section 14.20.4, “Named Windows”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
partition_clause
</code>
</em>
: A
<code class="literal">
PARTITION BY
</code>
clause indicates how to
divide the query rows into groups. The window function
result for a given row is based on the rows of the partition
that contains the row. If
<code class="literal">
PARTITION BY
</code>
is
omitted, there is a single partition consisting of all query
rows.
</p>
<a class="indexterm" name="idm46045191946096">
</a>
<a class="indexterm" name="idm46045191944608">
</a>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
Partitioning for window functions differs from table
partitioning. For information about table partitioning,
see
<a class="xref" href="partitioning.html" title="Chapter 26 Partitioning">
Chapter 26,
<i>
Partitioning
</i>
</a>
.
</p>
</div>
<p>
<em class="replaceable">
<code>
partition_clause
</code>
</em>
has this syntax:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43955496"><div class="copy-help left">Press ⌘+C to copy</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">partition_clause</em>:
<span class="token keyword">PARTITION</span> <span class="token keyword">BY</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></code></pre>
</div>
<p>
Standard SQL requires
<code class="literal">
PARTITION BY
</code>
to be
followed by column names only. A MySQL extension is to
permit expressions, not just column names. For example, if a
table contains a
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column named
<code class="literal">
ts
</code>
, standard SQL permits
<code class="literal">
PARTITION BY ts
</code>
but not
<code class="literal">
PARTITION BY HOUR(ts)
</code>
, whereas MySQL
permits both.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
order_clause
</code>
</em>
: An
<code class="literal">
ORDER
BY
</code>
clause indicates how to sort rows in each
partition. Partition rows that are equal according to the
<code class="literal">
ORDER BY
</code>
clause are considered peers. If
<code class="literal">
ORDER BY
</code>
is omitted, partition rows are
unordered, with no processing order implied, and all
partition rows are peers.
</p>
<a class="indexterm" name="idm46045191930032">
</a>
<a class="indexterm" name="idm46045191928544">
</a>
<p>
<em class="replaceable">
<code>
order_clause
</code>
</em>
has this syntax:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72213616"><div class="copy-help left">Press ⌘+C to copy</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">order_clause</em>:
<span class="token keyword">ORDER</span> <span class="token keyword">BY</span> <em class="replaceable">expr</em> <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> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">expr</em> <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><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
</div>
<p>
Each
<code class="literal">
ORDER BY
</code>
expression optionally can
be followed by
<code class="literal">
ASC
</code>
or
<code class="literal">
DESC
</code>
to indicate sort direction. The
default is
<code class="literal">
ASC
</code>
if no direction is
specified.
<code class="literal">
NULL
</code>
values sort first for
ascending sorts, last for descending sorts.
</p>
<p>
An
<code class="literal">
ORDER BY
</code>
in a window definition
applies within individual partitions. To sort the result set
as a whole, include an
<code class="literal">
ORDER BY
</code>
at the
query top level.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
frame_clause
</code>
</em>
: A frame is a subset
of the current partition and the frame clause specifies how
to define the subset. The frame clause has many subclauses
of its own. For details, see
<a class="xref" href="window-functions-frames.html" title="14.20.3 Window Function Frame Specification">
Section 14.20.3, “Window Function Frame Specification”
</a>
.
</p>
<a class="indexterm" name="idm46045191915728">
</a>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-connection-strings.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="mysql-cluster-connection-strings">
</a>
25.4.3.3 NDB Cluster Connection Strings
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045120584736">
</a>
<a class="indexterm" name="idm46045120583248">
</a>
<p>
With the exception of the NDB Cluster management server
(
<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>
), each node that is part of an NDB
Cluster requires a
<span class="firstterm">
connection
string
</span>
that points to the management server's
location. This connection string is used in establishing a
connection to the management server as well as in performing
other tasks depending on the node's role in the cluster. The
syntax for a connection string is as follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa52757715"><div class="copy-help left">Press ⌘+C to 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>nodeid<span class="token operator">=</span><em class="replaceable">node_id</em><span class="token punctuation">,</span> <span class="token punctuation">]</span><em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">host<span class="token operator">-</span>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 punctuation">]</span><span class="token punctuation">]</span>
<em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token operator">:</span>
<em class="replaceable">host_name</em><span class="token punctuation">[</span><span class="token operator">:</span><em class="replaceable">port_number</em><span class="token punctuation">]</span></code></pre>
</div>
<p>
<code class="literal">
node_id
</code>
is an integer greater than or equal
to 1 which identifies a node in
<code class="filename">
config.ini
</code>
.
<em class="replaceable">
<code>
host_name
</code>
</em>
is a string representing a
valid Internet host name or IP address.
<em class="replaceable">
<code>
port_number
</code>
</em>
is an integer referring
to a TCP/IP port number.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa3965780"><div class="copy-help left">Press ⌘+C to 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">example 1 <span class="token punctuation">(</span>long<span class="token punctuation">)</span><span class="token operator">:</span> "nodeid<span class="token operator">=</span>2<span class="token punctuation">,</span>myhost1<span class="token operator">:</span>1100<span class="token punctuation">,</span>myhost2<span class="token operator">:</span>1100<span class="token punctuation">,</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>3<span class="token operator">:</span>1200"
example 2 <span class="token punctuation">(</span>short<span class="token punctuation">)</span><span class="token operator">:</span> "myhost1"</code></pre>
</div>
<p>
<code class="literal">
localhost:1186
</code>
is used as the default
connection string value if none is provided. If
<em class="replaceable">
<code>
port_num
</code>
</em>
is omitted from the
connection string, the default port is 1186. This port should
always be available on the network because it has been assigned
by IANA for this purpose (see
<a class="ulink" href="http://www.iana.org/assignments/port-numbers" target="_blank">
http://www.iana.org/assignments/port-numbers
</a>
for
details).
</p>
<p>
By listing multiple host definitions, it is possible to
designate several redundant management servers. An NDB Cluster
data or API node attempts to contact successive management
servers on each host in the order specified, until a successful
connection has been established.
</p>
<p>
It is also possible to specify in a connection string one or
more bind addresses to be used by nodes having multiple network
interfaces for connecting to management servers. A bind address
consists of a hostname or network address and an optional port
number. This enhanced syntax for connection strings is shown
here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa38299799"><div class="copy-help left">Press ⌘+C to 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>nodeid<span class="token operator">=</span><em class="replaceable">node_id</em><span class="token punctuation">,</span> <span class="token punctuation">]</span>
<span class="token punctuation">[</span>bind<span class="token operator">-</span>address<span class="token operator">=</span><em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">,</span> <span class="token punctuation">]</span>
<em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">[</span><span class="token punctuation">;</span> bind<span class="token operator">-</span>address<span class="token operator">=</span><em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">]</span>
<em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">[</span><span class="token punctuation">;</span> bind<span class="token operator">-</span>address<span class="token operator">=</span><em class="replaceable">host<span class="token operator">-</span>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 punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
<em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token operator">:</span>
<em class="replaceable">host_name</em><span class="token punctuation">[</span><span class="token operator">:</span><em class="replaceable">port_number</em><span class="token punctuation">]</span></code></pre>
</div>
<p>
If a single bind address is used in the connection string
<span class="emphasis">
<em>
prior
</em>
</span>
to specifying any management hosts,
then this address is used as the default for connecting to any
of them (unless overridden for a given management server; see
later in this section for an example). For example, the
following connection string causes the node to use
<code class="literal">
198.51.100.242
</code>
regardless of the management
server to which it connects:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa61625075"><div class="copy-help left">Press ⌘+C to 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">bind<span class="token operator">-</span>address<span class="token operator">=</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>242<span class="token punctuation">,</span> poseidon<span class="token operator">:</span>1186<span class="token punctuation">,</span> perch<span class="token operator">:</span>1186</code></pre>
</div>
<p>
If a bind address is specified
<span class="emphasis">
<em>
following
</em>
</span>
a
management host definition, then it is used only for connecting
to that management node. Consider the following connection
string:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa42426391"><div class="copy-help left">Press ⌘+C to 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">poseidon<span class="token operator">:</span>1186<span class="token punctuation">;</span>bind<span class="token operator">-</span>address<span class="token operator">=</span>localhost<span class="token punctuation">,</span> perch<span class="token operator">:</span>1186<span class="token punctuation">;</span>bind<span class="token operator">-</span>address<span class="token operator">=</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>242</code></pre>
</div>
<p>
In this case, the node uses
<code class="literal">
localhost
</code>
to
connect to the management server running on the host named
<code class="literal">
poseidon
</code>
and
<code class="literal">
198.51.100.242
</code>
to connect to the management
server running on the host named
<code class="literal">
perch
</code>
.
</p>
<p>
You can specify a default bind address and then override this
default for one or more specific management hosts. In the
following example,
<code class="literal">
localhost
</code>
is used for
connecting to the management server running on host
<code class="literal">
poseidon
</code>
; since
<code class="literal">
198.51.100.242
</code>
is specified first (before any
management server definitions), it is the default bind address
and so is used for connecting to the management servers on hosts
<code class="literal">
perch
</code>
and
<code class="literal">
orca
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa86273029"><div class="copy-help left">Press ⌘+C to 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">bind<span class="token operator">-</span>address<span class="token operator">=</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>242<span class="token punctuation">,</span>poseidon<span class="token operator">:</span>1186<span class="token punctuation">;</span>bind<span class="token operator">-</span>address<span class="token operator">=</span>localhost<span class="token punctuation">,</span>perch<span class="token operator">:</span>1186<span class="token punctuation">,</span>orca<span class="token operator">:</span>2200</code></pre>
</div>
<p>
There are a number of different ways to specify the connection
string:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Each executable has its own command-line option which
enables specifying the management server at startup. (See
the documentation for the respective executable.)
</p>
</li>
<li class="listitem">
<p>
It is also possible to set the connection string for all
nodes in the cluster at once by placing it in a
<code class="literal">
[mysql_cluster]
</code>
section in the management
server's
<code class="filename">
my.cnf
</code>
file.
</p>
</li>
<li class="listitem">
<p>
For backward compatibility, two other options are available,
using the same syntax:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
Set the
<code class="envar">
NDB_CONNECTSTRING
</code>
environment
variable to contain the connection string.
</p>
<p>
This should be considered deprecated, and not used in
new installations.
</p>
</li>
<li class="listitem">
<p>
Write the connection string for each executable into a
text file named
<code class="filename">
Ndb.cfg
</code>
and place
this file in the executable's startup directory.
</p>
<p>
Use of this file is deprecated in NDB 8.4.3; you should
expect it to be removed in a future release of MySQL
Cluster.
</p>
</li>
</ol>
</div>
</li>
</ul>
</div>
<p>
The recommended method for specifying the connection string is
to set it on the command line or in the
<code class="filename">
my.cnf
</code>
file for each executable.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-multi-source-monitoring.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="replication-multi-source-monitoring">
</a>
19.1.5.8 Monitoring Multi-Source Replication
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045145124352">
</a>
<a class="indexterm" name="idm46045145122848">
</a>
<p>
To monitor the status of replication channels the following
options exist:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Using the replication Performance Schema tables. The first
column of these tables is
<code class="literal">
Channel_Name
</code>
.
This enables you to write complex queries based on
<code class="literal">
Channel_Name
</code>
as a key. See
<a class="xref" href="performance-schema-replication-tables.html" title="29.12.11 Performance Schema Replication Tables">
Section 29.12.11, “Performance Schema Replication Tables”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Using
<code class="literal">
SHOW REPLICA
STATUS FOR CHANNEL
<em class="replaceable">
<code>
channel
</code>
</em>
</code>
. By default, if
the
<code class="literal">
FOR CHANNEL
<em class="replaceable">
<code>
channel
</code>
</em>
</code>
clause is not
used, this statement shows the replica status for all channels
with one row per channel. The identifier
<code class="literal">
Channel_name
</code>
is added as a column in the
result set. If a
<code class="literal">
FOR CHANNEL
<em class="replaceable">
<code>
channel
</code>
</em>
</code>
clause is
provided, the results show the status of only the named
replication channel.
</p>
</li>
</ul>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
The
<a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
<code class="literal">
SHOW VARIABLES
</code>
</a>
statement does
not work with multiple replication channels. The information
that was available through these variables has been migrated to
the replication performance tables. Using a
<a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
<code class="literal">
SHOW VARIABLES
</code>
</a>
statement in a
topology with multiple channels shows the status of only the
default channel.
</p>
</div>
<p>
The error codes and messages that are issued when multi-source
replication is enabled specify the channel that generated the
error.
</p>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="replication-multi-source-monitoring-tutorial">
</a>
19.1.5.8.1 Monitoring Channels Using Performance Schema Tables
</h5>
</div>
</div>
</div>
<a class="indexterm" name="idm46045145106896">
</a>
<p>
This section explains how to use the replication Performance
Schema tables to monitor channels. You can choose to monitor all
channels, or a subset of the existing channels.
</p>
<p>
To monitor the connection status of all channels:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96332465"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> replication_connection_status\G<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> 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>
CHANNEL_NAME<span class="token punctuation">:</span> source_1
GROUP_NAME<span class="token punctuation">:</span>
SOURCE_UUID<span class="token punctuation">:</span> 046e41f8-a223-11e4-a975-0811960cc264
THREAD_ID<span class="token punctuation">:</span> 24
SERVICE_STATE<span class="token punctuation">:</span> ON
COUNT_RECEIVED_HEARTBEATS<span class="token punctuation">:</span> 0
LAST_HEARTBEAT_TIMESTAMP<span class="token punctuation">:</span> 0000-00-00 00<span class="token punctuation">:</span>00<span class="token punctuation">:</span>00
RECEIVED_TRANSACTION_SET<span class="token punctuation">:</span> 046e41f8-a223-11e4-a975-0811960cc264<span class="token punctuation">:</span>4-37
LAST_ERROR_NUMBER<span class="token punctuation">:</span> 0
LAST_ERROR_MESSAGE<span class="token punctuation">:</span>
LAST_ERROR_TIMESTAMP<span class="token punctuation">:</span> 0000-00-00 00<span class="token punctuation">:</span>00<span class="token punctuation">:</span>00
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span 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>
CHANNEL_NAME<span class="token punctuation">:</span> source_2
GROUP_NAME<span class="token punctuation">:</span>
SOURCE_UUID<span class="token punctuation">:</span> 7475e474-a223-11e4-a978-0811960cc264
THREAD_ID<span class="token punctuation">:</span> 26
SERVICE_STATE<span class="token punctuation">:</span> ON
COUNT_RECEIVED_HEARTBEATS<span class="token punctuation">:</span> 0
LAST_HEARTBEAT_TIMESTAMP<span class="token punctuation">:</span> 0000-00-00 00<span class="token punctuation">:</span>00<span class="token punctuation">:</span>00
RECEIVED_TRANSACTION_SET<span class="token punctuation">:</span> 7475e474-a223-11e4-a978-0811960cc264<span class="token punctuation">:</span>4-6
LAST_ERROR_NUMBER<span class="token punctuation">:</span> 0
LAST_ERROR_MESSAGE<span class="token punctuation">:</span>
LAST_ERROR_TIMESTAMP<span class="token punctuation">:</span> 0000-00-00 00<span class="token punctuation">:</span>00<span class="token punctuation">:</span>00
</span><span class="token output">2 rows in set (0.00 sec)</span></code></pre>
</div>
<p>
In the above output there are two channels enabled, and as shown
by the
<code class="literal">
CHANNEL_NAME
</code>
field they are called
<code class="literal">
source_1
</code>
and
<code class="literal">
source_2
</code>
.
</p>
<p>
The addition of the
<code class="literal">
CHANNEL_NAME
</code>
field
enables you to query the Performance Schema tables for a
specific channel. To monitor the connection status of a named
channel, use a
<code class="literal">
WHERE
CHANNEL_NAME=
<em class="replaceable">
<code>
channel
</code>
</em>
</code>
clause:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa97781543"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> replication_connection_status <span class="token keyword">WHERE</span> CHANNEL_NAME<span class="token operator">=</span><span class="token string">'source_1'</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>
CHANNEL_NAME<span class="token punctuation">:</span> source_1
GROUP_NAME<span class="token punctuation">:</span>
SOURCE_UUID<span class="token punctuation">:</span> 046e41f8-a223-11e4-a975-0811960cc264
THREAD_ID<span class="token punctuation">:</span> 24
SERVICE_STATE<span class="token punctuation">:</span> ON
COUNT_RECEIVED_HEARTBEATS<span class="token punctuation">:</span> 0
LAST_HEARTBEAT_TIMESTAMP<span class="token punctuation">:</span> 0000-00-00 00<span class="token punctuation">:</span>00<span class="token punctuation">:</span>00
RECEIVED_TRANSACTION_SET<span class="token punctuation">:</span> 046e41f8-a223-11e4-a975-0811960cc264<span class="token punctuation">:</span>4-37
LAST_ERROR_NUMBER<span class="token punctuation">:</span> 0
LAST_ERROR_MESSAGE<span class="token punctuation">:</span>
LAST_ERROR_TIMESTAMP<span class="token punctuation">:</span> 0000-00-00 00<span class="token punctuation">:</span>00<span class="token punctuation">:</span>00
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
Similarly, the
<code class="literal">
WHERE
CHANNEL_NAME=
<em class="replaceable">
<code>
channel
</code>
</em>
</code>
clause
can be used to monitor the other replication Performance Schema
tables for a specific channel. For more information, see
<a class="xref" href="performance-schema-replication-tables.html" title="29.12.11 Performance Schema Replication Tables">
Section 29.12.11, “Performance Schema Replication Tables”
</a>
.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/merge-table-problems.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="merge-table-problems">
</a>
18.7.2 MERGE Table Problems
</h3>
</div>
</div>
</div>
<p>
The following are known problems with
<code class="literal">
MERGE
</code>
tables:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
MERGE
</code>
child tables are locked through the
parent table. If the parent is a temporary table, it is not
locked, and thus the child tables are also not locked; this
means that parallel use of the underlying
<a class="link" href="myisam-storage-engine.html" title="18.2 The MyISAM Storage Engine">
<code class="literal">
MyISAM
</code>
</a>
tables corrupts them.
</p>
</li>
<li class="listitem">
<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>
to
change a
<code class="literal">
MERGE
</code>
table to another storage
engine, the mapping to the underlying tables is lost. Instead,
the rows from the underlying
<code class="literal">
MyISAM
</code>
tables
are copied into the altered table, which then uses the
specified storage engine.
</p>
</li>
<li class="listitem">
<p>
The
<code class="literal">
INSERT_METHOD
</code>
table option for a
<code class="literal">
MERGE
</code>
table indicates which underlying
<code class="literal">
MyISAM
</code>
table to use for inserts into the
<code class="literal">
MERGE
</code>
table. However, use of the
<code class="literal">
AUTO_INCREMENT
</code>
table option for that
<code class="literal">
MyISAM
</code>
table has no effect for inserts into
the
<code class="literal">
MERGE
</code>
table until at least one row has
been inserted directly into the
<code class="literal">
MyISAM
</code>
table.
</p>
</li>
<li class="listitem">
<p>
A
<code class="literal">
MERGE
</code>
table cannot maintain uniqueness
constraints over the entire table. When you perform an
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
, the data goes into the
first or last
<code class="literal">
MyISAM
</code>
table (as determined
by the
<code class="literal">
INSERT_METHOD
</code>
option). MySQL ensures
that unique key values remain unique within that
<code class="literal">
MyISAM
</code>
table, but not over all the
underlying tables in the collection.
</p>
</li>
<li class="listitem">
<p>
Because the
<code class="literal">
MERGE
</code>
engine cannot enforce
uniqueness over the set of underlying tables,
<a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
<code class="literal">
REPLACE
</code>
</a>
does not work as
expected. The two key facts are:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
<code class="literal">
REPLACE
</code>
</a>
can detect unique
key violations only in the underlying table to which it is
going to write (which is determined by the
<code class="literal">
INSERT_METHOD
</code>
option). This differs
from violations in the
<code class="literal">
MERGE
</code>
table
itself.
</p>
</li>
<li class="listitem">
<p>
If
<a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
<code class="literal">
REPLACE
</code>
</a>
detects a unique
key violation, it changes only the corresponding row in
the underlying table it is writing to; that is, the first
or last table, as determined by the
<code class="literal">
INSERT_METHOD
</code>
option.
</p>
</li>
</ul>
</div>
<p>
Similar considerations apply for
<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>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MERGE
</code>
tables do not support partitioning.
That is, you cannot partition a
<code class="literal">
MERGE
</code>
table, nor can any of a
<code class="literal">
MERGE
</code>
table's
underlying
<code class="literal">
MyISAM
</code>
tables be partitioned.
</p>
</li>
<li class="listitem">
<p>
You should not use
<a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
<code class="literal">
ANALYZE
TABLE
</code>
</a>
,
<a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
<code class="literal">
REPAIR TABLE
</code>
</a>
,
<a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
<code class="literal">
OPTIMIZE TABLE
</code>
</a>
,
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
,
<a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
<code class="literal">
DROP TABLE
</code>
</a>
,
<a class="link" href="delete.html" title="15.2.2 DELETE Statement">
<code class="literal">
DELETE
</code>
</a>
without a
<code class="literal">
WHERE
</code>
clause, or
<a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
<code class="literal">
TRUNCATE TABLE
</code>
</a>
on any of the
tables that are mapped into an open
<code class="literal">
MERGE
</code>
table. If you do so, the
<code class="literal">
MERGE
</code>
table may
still refer to the original table and yield unexpected
results. To work around this problem, ensure that no
<code class="literal">
MERGE
</code>
tables remain open by issuing a
<a class="link" href="flush.html#flush-tables">
<code class="literal">
FLUSH TABLES
</code>
</a>
statement prior to
performing any of the named operations.
</p>
<p>
The unexpected results include the possibility that the
operation on the
<code class="literal">
MERGE
</code>
table reports table
corruption. If this occurs after one of the named operations
on the underlying
<code class="literal">
MyISAM
</code>
tables, the
corruption message is spurious. To deal with this, issue a
<a class="link" href="flush.html#flush-tables">
<code class="literal">
FLUSH TABLES
</code>
</a>
statement after
modifying the
<code class="literal">
MyISAM
</code>
tables.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
<code class="literal">
DROP TABLE
</code>
</a>
on a table that is
in use by a
<code class="literal">
MERGE
</code>
table does not work on
Windows because the
<code class="literal">
MERGE
</code>
storage engine's
table mapping is hidden from the upper layer of MySQL. Windows
does not permit open files to be deleted, so you first must
flush all
<code class="literal">
MERGE
</code>
tables (with
<a class="link" href="flush.html#flush-tables">
<code class="literal">
FLUSH TABLES
</code>
</a>
) or drop the
<code class="literal">
MERGE
</code>
table before dropping the table.
</p>
</li>
<li class="listitem">
<p>
The definition of the
<code class="literal">
MyISAM
</code>
tables and the
<code class="literal">
MERGE
</code>
table are checked when the tables are
accessed (for example, as part of a
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
or
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
statement). The checks
ensure that the definitions of the tables and the parent
<code class="literal">
MERGE
</code>
table definition match by comparing
column order, types, sizes and associated indexes. If there is
a difference between the tables, an error is returned and the
statement fails. Because these checks take place when the
tables are opened, any changes to the definition of a single
table, including column changes, column ordering, and engine
alterations cause the statement to fail.
</p>
</li>
<li class="listitem">
<p>
The order of indexes in the
<code class="literal">
MERGE
</code>
table and
its underlying tables should be the same. If you use
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
to add a
<code class="literal">
UNIQUE
</code>
index to a table used in a
<code class="literal">
MERGE
</code>
table, and then use
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
to add a nonunique
index on the
<code class="literal">
MERGE
</code>
table, the index
ordering is different for the tables if there was already a
nonunique index in the underlying table. (This happens because
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
puts
<code class="literal">
UNIQUE
</code>
indexes before nonunique indexes to
facilitate rapid detection of duplicate keys.) Consequently,
queries on tables with such indexes may return unexpected
results.
</p>
</li>
<li class="listitem">
<p>
If you encounter an error message similar to
<span class="errortext">
ERROR
1017 (HY000): Can't find file:
'
<em class="replaceable">
<code>
tbl_name
</code>
</em>
.MRG' (errno:
2)
</span>
, it generally indicates that some of the
underlying tables do not use the
<code class="literal">
MyISAM
</code>
storage engine. Confirm that all of these tables are
<code class="literal">
MyISAM
</code>
.
</p>
</li>
<li class="listitem">
<p>
The maximum number of rows in a
<code class="literal">
MERGE
</code>
table
is 2
<sup>
64
</sup>
(~1.844E+19; the same as for
a
<code class="literal">
MyISAM
</code>
table). It is not possible to
merge multiple
<code class="literal">
MyISAM
</code>
tables into a single
<code class="literal">
MERGE
</code>
table that would have more than this
number of rows.
</p>
</li>
<li class="listitem">
<p>
Use of underlying
<code class="literal">
MyISAM
</code>
tables of
differing row formats with a parent
<code class="literal">
MERGE
</code>
table is currently known to fail. See Bug #32364.
</p>
</li>
<li class="listitem">
<p>
You cannot change the union list of a nontemporary
<code class="literal">
MERGE
</code>
table when
<a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements">
<code class="literal">
LOCK
TABLES
</code>
</a>
is in effect. The following does
<span class="emphasis">
<em>
not
</em>
</span>
work:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61183059"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> m1 <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>MRG_MYISAM <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</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">WRITE</span><span class="token punctuation">,</span> m1 <span class="token keyword">WRITE</span><span class="token punctuation">;</span>
<span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> m1 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">UNION</span><span class="token operator">=</span><span class="token punctuation">(</span>t1<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>
However, you can do this with a temporary
<code class="literal">
MERGE
</code>
table.
</p>
</li>
<li class="listitem">
<p>
You cannot create a
<code class="literal">
MERGE
</code>
table with
<code class="literal">
CREATE ... SELECT
</code>
, neither as a temporary
<code class="literal">
MERGE
</code>
table, nor as a nontemporary
<code class="literal">
MERGE
</code>
table. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa74827280"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> m1 <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>MRG_MYISAM <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">SELECT</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>
Attempts to do this result in an error:
<em class="replaceable">
<code>
tbl_name
</code>
</em>
is not
<code class="literal">
BASE
TABLE
</code>
.
</p>
</li>
<li class="listitem">
<p>
In some cases, differing
<code class="literal">
PACK_KEYS
</code>
table
option values among the
<code class="literal">
MERGE
</code>
and
underlying tables cause unexpected results if the underlying
tables contain
<code class="literal">
CHAR
</code>
or
<code class="literal">
BINARY
</code>
columns. As a workaround, use
<code class="literal">
ALTER TABLE
</code>
to ensure that all involved
tables have the same
<code class="literal">
PACK_KEYS
</code>
value. (Bug
#50646)
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/optimizing-subqueries.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="optimizing-subqueries">
</a>
15.2.15.11 Optimizing Subqueries
</h4>
</div>
</div>
</div>
<p>
Development is ongoing, so no optimization tip is reliable for
the long term. The following list provides some interesting
tricks that you might want to play with. See also
<a class="xref" href="subquery-optimization.html" title="10.2.2 Optimizing Subqueries, Derived Tables, View References, and Common Table Expressions">
Section 10.2.2, “Optimizing Subqueries, Derived Tables, View References, and Common Table
Expressions”
</a>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Move clauses from outside to inside the subquery. For
example, use this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47112548"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">WHERE</span> s1 <span class="token keyword">IN</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> s1 <span class="token keyword">FROM</span> t1 <span class="token keyword">UNION</span> <span class="token keyword">ALL</span> <span class="token keyword">SELECT</span> s1 <span class="token keyword">FROM</span> t2<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Instead of this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56955145"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">WHERE</span> s1 <span class="token keyword">IN</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> s1 <span class="token keyword">FROM</span> t1<span class="token punctuation">)</span> <span class="token operator">OR</span> s1 <span class="token keyword">IN</span> <span class="token punctuation">(</span><span class="token keyword">SELECT</span> s1 <span class="token keyword">FROM</span> t2<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
For another example, use this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa76248112"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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 keyword">SELECT</span> column1 <span class="token operator">+</span> <span class="token number">5</span> <span class="token keyword">FROM</span> t1<span class="token punctuation">)</span> <span class="token keyword">FROM</span> t2<span class="token punctuation">;</span></code></pre>
</div>
<p>
Instead of this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa90708122"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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 keyword">SELECT</span> column1 <span class="token keyword">FROM</span> t1<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">5</span> <span class="token keyword">FROM</span> t2<span class="token punctuation">;</span></code></pre>
</div>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/generated-column-index-optimizations.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="generated-column-index-optimizations">
</a>
10.3.11 Optimizer Use of Generated Column Indexes
</h3>
</div>
</div>
</div>
<p>
MySQL supports indexes on generated columns. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa80370060"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>f1 <span class="token datatype">INT</span><span class="token punctuation">,</span> gc <span class="token datatype">INT</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span>f1 <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">STORED</span><span class="token punctuation">,</span> <span class="token keyword">INDEX</span> <span class="token punctuation">(</span>gc<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The generated column,
<code class="literal">
gc
</code>
, is defined as the
expression
<code class="literal">
f1 + 1
</code>
. The column is also indexed
and the optimizer can take that index into account during
execution plan construction. In the following query, the
<code class="literal">
WHERE
</code>
clause refers to
<code class="literal">
gc
</code>
and the optimizer considers whether the index on that column
yields a more efficient plan:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa13392312"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">WHERE</span> gc <span class="token operator">></span> <span class="token number">9</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The optimizer can use indexes on generated columns to generate
execution plans, even in the absence of direct references in
queries to those columns by name. This occurs if the
<code class="literal">
WHERE
</code>
,
<code class="literal">
ORDER BY
</code>
, or
<code class="literal">
GROUP BY
</code>
clause refers to an expression that
matches the definition of some indexed generated column. The
following query does not refer directly to
<code class="literal">
gc
</code>
but does use an expression that matches the definition of
<code class="literal">
gc
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa66816965"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">WHERE</span> f1 <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">></span> <span class="token number">9</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The optimizer recognizes that the expression
<code class="literal">
f1 +
1
</code>
matches the definition of
<code class="literal">
gc
</code>
and
that
<code class="literal">
gc
</code>
is indexed, so it considers that
index during execution plan construction. You can see this using
<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="sa13184508"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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">WHERE</span> f1 <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">></span> <span class="token number">9</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> t1
partitions<span class="token punctuation">:</span> NULL
type<span class="token punctuation">:</span> range
possible_keys<span class="token punctuation">:</span> gc
key<span class="token punctuation">:</span> gc
key_len<span class="token punctuation">:</span> 5
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> Using index condition</span></code></pre>
</div>
<p>
In effect, the optimizer has replaced the expression
<code class="literal">
f1
+ 1
</code>
with the name of the generated column that matches
the expression. That is also apparent in the rewritten query
available in the extended
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
information displayed by
<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="sa85204224"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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 `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`gc`
AS `gc` from `test`.`t1` where (`test`.`t1`.`gc` > 9)</span></code></pre>
</div>
<p>
The following restrictions and conditions apply to the
optimizer's use of generated column indexes:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For a query expression to match a generated column
definition, the expression must be identical and it must
have the same result type. For example, if the generated
column expression is
<code class="literal">
f1 + 1
</code>
, the
optimizer does not recognize a match if the query uses
<code class="literal">
1 + f1
</code>
, or if
<code class="literal">
f1 + 1
</code>
(an integer expression) is compared with a string.
</p>
</li>
<li class="listitem">
<p>
The optimization applies to these operators:
<a class="link" href="comparison-operators.html#operator_equal">
<code class="literal">
=
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_less-than">
<code class="literal">
<
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_less-than-or-equal">
<code class="literal">
<=
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_greater-than">
<code class="literal">
>
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_greater-than-or-equal">
<code class="literal">
>=
</code>
</a>
,
<a class="link" href="comparison-operators.html#operator_between">
<code class="literal">
BETWEEN
</code>
</a>
, and
<a class="link" href="comparison-operators.html#operator_in">
<code class="literal">
IN()
</code>
</a>
.
</p>
<p>
For operators other than
<a class="link" href="comparison-operators.html#operator_between">
<code class="literal">
BETWEEN
</code>
</a>
and
<a class="link" href="comparison-operators.html#operator_in">
<code class="literal">
IN()
</code>
</a>
, either operand can be
replaced by a matching generated column. For
<a class="link" href="comparison-operators.html#operator_between">
<code class="literal">
BETWEEN
</code>
</a>
and
<a class="link" href="comparison-operators.html#operator_in">
<code class="literal">
IN()
</code>
</a>
, only the first argument
can be replaced by a matching generated column, and the
other arguments must have the same result type.
<a class="link" href="comparison-operators.html#operator_between">
<code class="literal">
BETWEEN
</code>
</a>
and
<a class="link" href="comparison-operators.html#operator_in">
<code class="literal">
IN()
</code>
</a>
are not yet supported for
comparisons involving JSON values.
</p>
</li>
<li class="listitem">
<p>
The generated column must be defined as an expression that
contains at least a function call or one of the operators
mentioned in the preceding item. The expression cannot
consist of a simple reference to another column. For
example,
<code class="literal">
gc INT AS (f1) STORED
</code>
consists
only of a column reference, so indexes on
<code class="literal">
gc
</code>
are not considered.
</p>
</li>
<li class="listitem">
<p>
For comparisons of strings to indexed generated columns that
compute a value from a JSON function that returns a quoted
string,
<a class="link" href="json-modification-functions.html#function_json-unquote">
<code class="literal">
JSON_UNQUOTE()
</code>
</a>
is
needed in the column definition to remove the extra quotes
from the function value. (For direct comparison of a string
to the function result, the JSON comparator handles quote
removal, but this does not occur for index lookups.) For
example, instead of writing a column definition like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa99496890"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">doc_name <span class="token datatype">TEXT</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span><span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span>jdoc<span class="token punctuation">,</span> <span class="token string">'$.name'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">STORED</span></code></pre>
</div>
<p>
Write it like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa84221709"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">doc_name <span class="token datatype">TEXT</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span><span class="token function">JSON_UNQUOTE</span><span class="token punctuation">(</span><span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span>jdoc<span class="token punctuation">,</span> <span class="token string">'$.name'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">STORED</span></code></pre>
</div>
<p>
With the latter definition, the optimizer can detect a match
for both of these comparisons:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa39569906"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">WHERE</span> <span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span>jdoc<span class="token punctuation">,</span> <span class="token string">'$.name'</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">some_string</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 punctuation">.</span> <span class="token keyword">WHERE</span> <span class="token function">JSON_UNQUOTE</span><span class="token punctuation">(</span><span class="token function">JSON_EXTRACT</span><span class="token punctuation">(</span>jdoc<span class="token punctuation">,</span> <span class="token string">'$.name'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">some_string</em>'</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
</div>
<p>
Without
<a class="link" href="json-modification-functions.html#function_json-unquote">
<code class="literal">
JSON_UNQUOTE()
</code>
</a>
in the
column definition, the optimizer detects a match only for
the first of those comparisons.
</p>
</li>
<li class="listitem">
<p>
If the optimizer picks the wrong index, an index hint can be
used to disable it and force the optimizer to make a
different choice.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/bnl-bka-optimization.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="bnl-bka-optimization">
</a>
10.2.1.12 Block Nested-Loop and Batched Key Access Joins
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045229279376">
</a>
<a class="indexterm" name="idm46045229277920">
</a>
<a class="indexterm" name="idm46045229276432">
</a>
<a class="indexterm" name="idm46045229274944">
</a>
<p>
In MySQL, a Batched Key Access (BKA) Join algorithm is
available that uses both index access to the joined table and
a join buffer. The BKA algorithm supports inner join, outer
join, and semijoin operations, including nested outer joins.
Benefits of BKA include improved join performance due to more
efficient table scanning. Also, the Block Nested-Loop (BNL)
Join algorithm previously used only for inner joins is
extended and can be employed for outer join and semijoin
operations, including nested outer joins.
</p>
<p>
The following sections discuss the join buffer management that
underlies the extension of the original BNL algorithm, the
extended BNL algorithm, and the BKA algorithm. For information
about semijoin strategies, see
<a class="ulink" href="/doc/refman/8.0/en/semijoins.html" target="_top">
Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations
</a>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="bnl-bka-optimization.html#join-buffer-management" title="Join Buffer Management for Block Nested-Loop and Batched Key Access Algorithms">
Join Buffer Management for Block Nested-Loop and Batched Key Access
Algorithms
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="bnl-bka-optimization.html#bnl-optimization" title="Block Nested-Loop Algorithm for Outer Joins and Semijoins">
Block Nested-Loop Algorithm for Outer Joins and Semijoins
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="bnl-bka-optimization.html#bka-optimization" title="Batched Key Access Joins">
Batched Key Access Joins
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="bnl-bka-optimization.html#bnl-bka-optimizer-hints" title="Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms">
Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms
</a>
</p>
</li>
</ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="join-buffer-management">
</a>
Join Buffer Management for Block Nested-Loop and Batched Key Access
Algorithms
</h5>
</div>
</div>
</div>
<p>
MySQL can employ join buffers to execute not only inner
joins without index access to the inner table, but also
outer joins and semijoins that appear after subquery
flattening. Moreover, a join buffer can be effectively used
when there is an index access to the inner table.
</p>
<p>
The join buffer management code slightly more efficiently
utilizes join buffer space when storing the values of the
interesting row columns: No additional bytes are allocated
in buffers for a row column if its value is
<code class="literal">
NULL
</code>
, and the minimum number of bytes is
allocated for any value of the
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
type.
</p>
<p>
The code supports two types of buffers, regular and
incremental. Suppose that join buffer
<code class="literal">
B1
</code>
is employed to join tables
<code class="literal">
t1
</code>
and
<code class="literal">
t2
</code>
and the result of this operation is
joined with table
<code class="literal">
t3
</code>
using join buffer
<code class="literal">
B2
</code>
:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
A regular join buffer contains columns from each join
operand. If
<code class="literal">
B2
</code>
is a regular join
buffer, each row
<em class="replaceable">
<code>
r
</code>
</em>
put into
<code class="literal">
B2
</code>
is composed of the columns of a
row
<em class="replaceable">
<code>
r1
</code>
</em>
from
<code class="literal">
B1
</code>
and the interesting columns of a
matching row
<em class="replaceable">
<code>
r2
</code>
</em>
from table
<code class="literal">
t3
</code>
.
</p>
</li>
<li class="listitem">
<p>
An incremental join buffer contains only columns from
rows of the table produced by the second join operand.
That is, it is incremental to a row from the first
operand buffer. If
<code class="literal">
B2
</code>
is an
incremental join buffer, it contains the interesting
columns of the row
<em class="replaceable">
<code>
r2
</code>
</em>
together with a link to the row
<em class="replaceable">
<code>
r1
</code>
</em>
from
<code class="literal">
B1
</code>
.
</p>
</li>
</ul>
</div>
<p>
Incremental join buffers are always incremental relative to
a join buffer from an earlier join operation, so the buffer
from the first join operation is always a regular buffer. In
the example just given, the buffer
<code class="literal">
B1
</code>
used to join tables
<code class="literal">
t1
</code>
and
<code class="literal">
t2
</code>
must be a regular buffer.
</p>
<p>
Each row of the incremental buffer used for a join operation
contains only the interesting columns of a row from the
table to be joined. These columns are augmented with a
reference to the interesting columns of the matched row from
the table produced by the first join operand. Several rows
in the incremental buffer can refer to the same row
<em class="replaceable">
<code>
r
</code>
</em>
whose columns are stored in the
previous join buffers insofar as all these rows match row
<em class="replaceable">
<code>
r
</code>
</em>
.
</p>
<p>
Incremental buffers enable less frequent copying of columns
from buffers used for previous join operations. This
provides a savings in buffer space because in the general
case a row produced by the first join operand can be matched
by several rows produced by the second join operand. It is
unnecessary to make several copies of a row from the first
operand. Incremental buffers also provide a savings in
processing time due to the reduction in copying time.
</p>
<p>
The
<a class="link" href="switchable-optimizations.html#optflag_block-nested-loop">
<code class="literal">
block_nested_loop
</code>
</a>
flag
of the
<a class="link" href="server-system-variables.html#sysvar_optimizer_switch">
<code class="literal">
optimizer_switch
</code>
</a>
system variable controls hash joins.
</p>
<p>
The
<a class="link" href="switchable-optimizations.html#optflag_batched-key-access">
<code class="literal">
batched_key_access
</code>
</a>
flag controls how the optimizer uses the Batched Key Access
join algorithms.
</p>
<p>
By default,
<a class="link" href="switchable-optimizations.html#optflag_block-nested-loop">
<code class="literal">
block_nested_loop
</code>
</a>
is
<code class="literal">
on
</code>
and
<a class="link" href="switchable-optimizations.html#optflag_batched-key-access">
<code class="literal">
batched_key_access
</code>
</a>
is
<code class="literal">
off
</code>
. See
<a class="xref" href="switchable-optimizations.html" title="10.9.2 Switchable Optimizations">
Section 10.9.2, “Switchable Optimizations”
</a>
. Optimizer hints
may also be applied; see
<a class="xref" href="bnl-bka-optimization.html#bnl-bka-optimizer-hints" title="Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms">
Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms
</a>
.
</p>
<p>
For information about semijoin strategies, see
<a class="ulink" href="/doc/refman/8.0/en/semijoins.html" target="_top">
Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations
</a>
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="bnl-optimization">
</a>
Block Nested-Loop Algorithm for Outer Joins and Semijoins
</h5>
</div>
</div>
</div>
<a class="indexterm" name="idm46045229230288">
</a>
<a class="indexterm" name="idm46045229228832">
</a>
<p>
The original implementation of the MySQL BNL algorithm was
extended to support outer join and semijoin operations (and
was later superseded by the hash join algorithm; see
<a class="xref" href="hash-joins.html" title="10.2.1.4 Hash Join Optimization">
Section 10.2.1.4, “Hash Join Optimization”
</a>
).
</p>
<p>
When these operations are executed with a join buffer, each
row put into the buffer is supplied with a match flag.
</p>
<p>
If an outer join operation is executed using a join buffer,
each row of the table produced by the second operand is
checked for a match against each row in the join buffer.
When a match is found, a new extended row is formed (the
original row plus columns from the second operand) and sent
for further extensions by the remaining join operations. In
addition, the match flag of the matched row in the buffer is
enabled. After all rows of the table to be joined have been
examined, the join buffer is scanned. Each row from the
buffer that does not have its match flag enabled is extended
by
<code class="literal">
NULL
</code>
complements
(
<code class="literal">
NULL
</code>
values for each column in the
second operand) and sent for further extensions by the
remaining join operations.
</p>
<p>
The
<a class="link" href="switchable-optimizations.html#optflag_block-nested-loop">
<code class="literal">
block_nested_loop
</code>
</a>
flag
of the
<a class="link" href="server-system-variables.html#sysvar_optimizer_switch">
<code class="literal">
optimizer_switch
</code>
</a>
system variable controls hash joins.
</p>
<p>
See
<a class="xref" href="switchable-optimizations.html" title="10.9.2 Switchable Optimizations">
Section 10.9.2, “Switchable Optimizations”
</a>
, for more
information. Optimizer hints may also be applied; see
<a class="xref" href="bnl-bka-optimization.html#bnl-bka-optimizer-hints" title="Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms">
Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms
</a>
.
</p>
<p>
In
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
output, use of BNL
for a table is signified when the
<code class="literal">
Extra
</code>
value contains
<code class="literal">
Using join buffer (Block Nested
Loop)
</code>
and the
<code class="literal">
type
</code>
value is
<a class="link" href="explain-output.html#jointype_all">
<code class="literal">
ALL
</code>
</a>
,
<a class="link" href="explain-output.html#jointype_index">
<code class="literal">
index
</code>
</a>
, or
<a class="link" href="explain-output.html#jointype_range">
<code class="literal">
range
</code>
</a>
.
</p>
<p>
For information about semijoin strategies, see
<a class="ulink" href="/doc/refman/8.0/en/semijoins.html" target="_top">
Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations
</a>
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="bka-optimization">
</a>
Batched Key Access Joins
</h5>
</div>
</div>
</div>
<a class="indexterm" name="idm46045229208224">
</a>
<a class="indexterm" name="idm46045229206768">
</a>
<p>
MySQL implements a method of joining tables called the
Batched Key Access (BKA) join algorithm. BKA can be applied
when there is an index access to the table produced by the
second join operand. Like the BNL join algorithm, the BKA
join algorithm employs a join buffer to accumulate the
interesting columns of the rows produced by the first
operand of the join operation. Then the BKA algorithm builds
keys to access the table to be joined for all rows in the
buffer and submits these keys in a batch to the database
engine for index lookups. The keys are submitted to the
engine through the Multi-Range Read (MRR) interface (see
<a class="xref" href="mrr-optimization.html" title="10.2.1.11 Multi-Range Read Optimization">
Section 10.2.1.11, “Multi-Range Read Optimization”
</a>
). After submission of the
keys, the MRR engine functions perform lookups in the index
in an optimal way, fetching the rows of the joined table
found by these keys, and starts feeding the BKA join
algorithm with matching rows. Each matching row is coupled
with a reference to a row in the join buffer.
</p>
<p>
When BKA is used, the value of
<a class="link" href="server-system-variables.html#sysvar_join_buffer_size">
<code class="literal">
join_buffer_size
</code>
</a>
defines
how large the batch of keys is in each request to the
storage engine. The larger the buffer, the more sequential
access is made to the right hand table of a join operation,
which can significantly improve performance.
</p>
<p>
For BKA to be used, the
<a class="link" href="switchable-optimizations.html#optflag_batched-key-access">
<code class="literal">
batched_key_access
</code>
</a>
flag of
the
<a class="link" href="server-system-variables.html#sysvar_optimizer_switch">
<code class="literal">
optimizer_switch
</code>
</a>
system
variable must be set to
<code class="literal">
on
</code>
. BKA uses MRR,
so the
<a class="link" href="switchable-optimizations.html#optflag_mrr">
<code class="literal">
mrr
</code>
</a>
flag must also
be
<code class="literal">
on
</code>
. Currently, the cost estimation for
MRR is too pessimistic. Hence, it is also necessary for
<a class="link" href="switchable-optimizations.html#optflag_mrr-cost-based">
<code class="literal">
mrr_cost_based
</code>
</a>
to be
<code class="literal">
off
</code>
for BKA to be used. The following
setting enables BKA:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa59527405"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> optimizer_switch<span class="token operator">=</span><span class="token string">'mrr=on,mrr_cost_based=off,batched_key_access=on'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
There are two scenarios by which MRR functions execute:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The first scenario is used for conventional disk-based
storage engines such as
<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="myisam-storage-engine.html" title="18.2 The MyISAM Storage Engine">
<code class="literal">
MyISAM
</code>
</a>
. For these engines,
usually the keys for all rows from the join buffer are
submitted to the MRR interface at once. Engine-specific
MRR functions perform index lookups for the submitted
keys, get row IDs (or primary keys) from them, and then
fetch rows for all these selected row IDs one by one by
request from BKA algorithm. Every row is returned with
an association reference that enables access to the
matched row in the join buffer. The rows are fetched by
the MRR functions in an optimal way: They are fetched in
the row ID (primary key) order. This improves
performance because reads are in disk order rather than
random order.
</p>
</li>
<li class="listitem">
<p>
The second scenario is used for remote storage engines
such as
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
. A package of
keys for a portion of rows from the join buffer,
together with their associations, is sent by a MySQL
Server (SQL node) to MySQL Cluster data nodes. In
return, the SQL node receives a package (or several
packages) of matching rows coupled with corresponding
associations. The BKA join algorithm takes these rows
and builds new joined rows. Then a new set of keys is
sent to the data nodes and the rows from the returned
packages are used to build new joined rows. The process
continues until the last keys from the join buffer are
sent to the data nodes, and the SQL node has received
and joined all rows matching these keys. This improves
performance because fewer key-bearing packages sent by
the SQL node to the data nodes means fewer round trips
between it and the data nodes to perform the join
operation.
</p>
</li>
</ul>
</div>
<p>
With the first scenario, a portion of the join buffer is
reserved to store row IDs (primary keys) selected by index
lookups and passed as a parameter to the MRR functions.
</p>
<p>
There is no special buffer to store keys built for rows from
the join buffer. Instead, a function that builds the key for
the next row in the buffer is passed as a parameter to the
MRR functions.
</p>
<p>
In
<a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
<code class="literal">
EXPLAIN
</code>
</a>
output, use of BKA
for a table is signified when the
<code class="literal">
Extra
</code>
value contains
<code class="literal">
Using join buffer (Batched Key
Access)
</code>
and the
<code class="literal">
type
</code>
value is
<a class="link" href="explain-output.html#jointype_ref">
<code class="literal">
ref
</code>
</a>
or
<a class="link" href="explain-output.html#jointype_eq_ref">
<code class="literal">
eq_ref
</code>
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="bnl-bka-optimizer-hints">
</a>
Optimizer Hints for Block Nested-Loop and Batched Key Access Algorithms
</h5>
</div>
</div>
</div>
<p>
In addition to using the
<a class="link" href="server-system-variables.html#sysvar_optimizer_switch">
<code class="literal">
optimizer_switch
</code>
</a>
system
variable to control optimizer use of the BNL and BKA
algorithms session-wide, MySQL supports optimizer hints to
influence the optimizer on a per-statement basis. See
<a class="xref" href="optimizer-hints.html" title="10.9.3 Optimizer Hints">
Section 10.9.3, “Optimizer Hints”
</a>
.
</p>
<p>
To use a BNL or BKA hint to enable join buffering for any
inner table of an outer join, join buffering must be enabled
for all inner tables of the outer join.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/drop-spatial-reference-system.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="drop-spatial-reference-system">
</a>
15.1.31 DROP SPATIAL REFERENCE SYSTEM Statement
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045183366176">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17248593"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">SPATIAL</span> <span class="token keyword">REFERENCE</span> <span class="token keyword">SYSTEM</span>
<span class="token punctuation">[</span><span class="token keyword">IF</span> <span class="token keyword">EXISTS</span><span class="token punctuation">]</span>
<span class="token keyword"><em class="replaceable">srid</em></span>
<span class="token keyword"><em class="replaceable">srid</em></span>: <span class="token number"></span><em class="replaceable"><span class="token number">32</span><span class="token operator">-</span><span class="token datatype">bit</span> <span class="token keyword">unsigned</span> <span class="token datatype">integer</span></em><span class="token datatype"></span></code></pre>
</div>
<p>
This statement removes a
<a class="link" href="spatial-reference-systems.html" title="13.4.5 Spatial Reference System Support">
spatial reference
system
</a>
(SRS) definition from the data dictionary. It
requires the
<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 one-line language-sql"><div class="docs-select-all right" id="sa30194145"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">SPATIAL</span> <span class="token keyword">REFERENCE</span> <span class="token keyword">SYSTEM</span> <span class="token number">4120</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
If no SRS definition with the SRID value exists, an error occurs
unless
<code class="literal">
IF EXISTS
</code>
is specified. In that case, a
warning occurs rather than an error.
</p>
<p>
If the SRID value is used by some column in an existing table, an
error occurs. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa49228885"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">DROP</span> <span class="token keyword">SPATIAL</span> <span class="token keyword">REFERENCE</span> <span class="token keyword">SYSTEM</span> <span class="token number">4326</span><span class="token punctuation">;</span>
<span class="token output">ERROR 3716 (SR005)<span class="token punctuation">:</span> Can't modify SRID 4326. There is at
least one column depending on it.</span></code></pre>
</div>
<p>
To identify which column or columns use the SRID, use this query:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa10169079"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>ST_GEOMETRY_COLUMNS <span class="token keyword">WHERE</span> SRS_ID<span class="token operator">=</span><span class="token number">4326</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
SRID values must be in the range of 32-bit unsigned integers, with
these restrictions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
SRID 0 is a valid SRID but cannot be used with
<a class="link" href="drop-spatial-reference-system.html" title="15.1.31 DROP SPATIAL REFERENCE SYSTEM Statement">
<code class="literal">
DROP SPATIAL REFERENCE SYSTEM
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
If the value is in a reserved SRID range, a warning occurs.
Reserved ranges are [0, 32767] (reserved by EPSG),
[60,000,000, 69,999,999] (reserved by EPSG), and
[2,000,000,000, 2,147,483,647] (reserved by MySQL). EPSG
stands for the
<a class="ulink" href="http://epsg.org" target="_blank">
European Petroleum
Survey Group
</a>
.
</p>
</li>
<li class="listitem">
<p>
Users should not drop SRSs with SRIDs in the reserved ranges.
If system-installed SRSs are dropped, the SRS definitions may
be recreated for MySQL upgrades.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/drop-server.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="drop-server">
</a>
15.1.30 DROP SERVER Statement
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045183381904">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa26374913"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">SERVER</span> <span class="token punctuation">[</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">]</span> <em class="replaceable">server_name</em></code></pre>
</div>
<p>
Drops the server definition for the server named
<code class="literal">
<em class="replaceable">
<code>
server_name
</code>
</em>
</code>
. The
corresponding row in the
<code class="literal">
mysql.servers
</code>
table is
deleted. This statement requires the
<a class="link" href="privileges-provided.html#priv_super">
<code class="literal">
SUPER
</code>
</a>
privilege.
</p>
<p>
Dropping a server for a table does not affect any
<code class="literal">
FEDERATED
</code>
tables that used this connection
information when they were created. See
<a class="xref" href="create-server.html" title="15.1.18 CREATE SERVER Statement">
Section 15.1.18, “CREATE SERVER Statement”
</a>
.
</p>
<p>
<code class="literal">
DROP SERVER
</code>
causes an implicit commit. See
<a class="xref" href="implicit-commit.html" title="15.3.3 Statements That Cause an Implicit Commit">
Section 15.3.3, “Statements That Cause an Implicit Commit”
</a>
.
</p>
<p>
<code class="literal">
DROP SERVER
</code>
is not written to the binary log,
regardless of the logging format that is in use.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/using-stack-trace.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="using-stack-trace">
</a>
7.9.1.5 Using a Stack Trace
</h4>
</div>
</div>
</div>
<p>
On some operating systems, the error log contains a stack trace
if
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
dies unexpectedly. You can use this
to find out where (and maybe why)
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
died. See
<a class="xref" href="error-log.html" title="7.4.2 The Error Log">
Section 7.4.2, “The Error Log”
</a>
. To get a stack trace, you
must not compile
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with the
<code class="option">
-fomit-frame-pointer
</code>
option to gcc. See
<a class="xref" href="compiling-for-debugging.html" title="7.9.1.1 Compiling MySQL for Debugging">
Section 7.9.1.1, “Compiling MySQL for Debugging”
</a>
.
</p>
<p>
A stack trace in the error log looks something like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa13954958"><div class="copy-help left">Press ⌘+C to 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">mysqld got signal 11<span class="token punctuation">;</span>
Attempting backtrace<span class="token punctuation">.</span> You can use the following information
to find out where mysqld died<span class="token punctuation">.</span> If you see no messages after
this<span class="token punctuation">,</span> something went terribly wrong<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
stack_bottom <span class="token operator">=</span> 0x41fd0110 thread_stack 0x40000
mysqld<span class="token punctuation">(</span>my_print_stacktrace<span class="token operator">+</span>0x32<span class="token punctuation">)</span><span class="token punctuation">[</span>0x9da402<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>handle_segfault<span class="token operator">+</span>0x28a<span class="token punctuation">)</span><span class="token punctuation">[</span>0x6648e9<span class="token punctuation">]</span>
<span class="token operator">/</span>lib<span class="token operator">/</span>libpthread<span class="token punctuation">.</span>so<span class="token punctuation">.</span>0<span class="token punctuation">[</span>0x7f1a5af000f0<span class="token punctuation">]</span>
<span class="token operator">/</span>lib<span class="token operator">/</span>libc<span class="token punctuation">.</span>so<span class="token punctuation">.</span>6<span class="token punctuation">(</span>strcmp<span class="token operator">+</span>0x2<span class="token punctuation">)</span><span class="token punctuation">[</span>0x7f1a5a10f0f2<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_Z21check_change_passwordP3THDPKcS2_Pcj<span class="token operator">+</span>0x7c<span class="token punctuation">)</span><span class="token punctuation">[</span>0x7412cb<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_ZN16set_var_password5checkEP3THD<span class="token operator">+</span>0xd0<span class="token punctuation">)</span><span class="token punctuation">[</span>0x688354<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_Z17sql_set_variablesP3THDP4ListI12set_var_baseE<span class="token operator">+</span>0x68<span class="token punctuation">)</span><span class="token punctuation">[</span>0x688494<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_Z21mysql_execute_commandP3THD<span class="token operator">+</span>0x41a0<span class="token punctuation">)</span><span class="token punctuation">[</span>0x67a170<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_Z11mysql_parseP3THDPKcjPS2_<span class="token operator">+</span>0x282<span class="token punctuation">)</span><span class="token punctuation">[</span>0x67f0ad<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_Z16dispatch_command19enum_server_commandP3THDPcj<span class="token operator">+</span>0xbb7<span class="token punctuation">[</span>0x67fdf8<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>_Z10do_commandP3THD<span class="token operator">+</span>0x24d<span class="token punctuation">)</span><span class="token punctuation">[</span>0x6811b6<span class="token punctuation">]</span>
mysqld<span class="token punctuation">(</span>handle_one_connection<span class="token operator">+</span>0x11c<span class="token punctuation">)</span><span class="token punctuation">[</span>0x66e05e<span class="token punctuation">]</span></code></pre>
</div>
<p>
If resolution of function names for the trace fails, the trace
contains less information:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa85368430"><div class="copy-help left">Press ⌘+C to 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">mysqld got signal 11<span class="token punctuation">;</span>
Attempting backtrace<span class="token punctuation">.</span> You can use the following information
to find out where mysqld died<span class="token punctuation">.</span> If you see no messages after
this<span class="token punctuation">,</span> something went terribly wrong<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
stack_bottom <span class="token operator">=</span> 0x41fd0110 thread_stack 0x40000
<span class="token punctuation">[</span>0x9da402<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x6648e9<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x7f1a5af000f0<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x7f1a5a10f0f2<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x7412cb<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x688354<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x688494<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x67a170<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x67f0ad<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x67fdf8<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x6811b6<span class="token punctuation">]</span>
<span class="token punctuation">[</span>0x66e05e<span class="token punctuation">]</span></code></pre>
</div>
<p>
Newer versions of
<code class="literal">
glibc
</code>
stack trace functions
also print the address as relative to the object. On
<code class="literal">
glibc
</code>
-based systems (Linux), the trace for an
unexpected exit within a plugin looks something like:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa55397409"><div class="copy-help left">Press ⌘+C to 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">plugin<span class="token operator">/</span>auth<span class="token operator">/</span>auth_test_plugin<span class="token punctuation">.</span>so<span class="token punctuation">(</span><span class="token operator">+</span>0x9a6<span class="token punctuation">)</span><span class="token punctuation">[</span>0x7ff4d11c29a6<span class="token punctuation">]</span></code></pre>
</div>
<p>
To translate the relative address (
<code class="literal">
+0x9a6
</code>
)
into a file name and line number, use this command:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa6089907"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">addr2line</span> <span class="token property">-fie</span> auth_test_plugin<span class="token punctuation">.</span>so 0x9a6
auth_test_plugin
mysql-trunk/plugin/auth/test_plugin<span class="token punctuation">.</span>c<span class="token punctuation">:</span>65</code></pre>
</div>
<p>
The
<span class="command">
<strong>
addr2line
</strong>
</span>
utility is part of the
<code class="literal">
binutils
</code>
package on Linux.
</p>
<p>
On Solaris, the procedure is similar. The Solaris
<code class="literal">
printstack()
</code>
already prints relative
addresses:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa1765926"><div class="copy-help left">Press ⌘+C to 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">plugin<span class="token operator">/</span>auth<span class="token operator">/</span>auth_test_plugin<span class="token punctuation">.</span>so<span class="token operator">:</span>0x1510</code></pre>
</div>
<p>
To translate, use this command:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa72708234"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">gaddr2line</span> <span class="token property">-fie</span> auth_test_plugin<span class="token punctuation">.</span>so 0x1510
mysql-trunk/plugin/auth/test_plugin<span class="token punctuation">.</span>c<span class="token punctuation">:</span>88</code></pre>
</div>
<p>
Windows already prints the address, function name and line:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa92360990"><div class="copy-help left">Press ⌘+C to 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">000007FEF07E10A4 auth_test_plugin<span class="token punctuation">.</span>dll<span class="token operator">!</span>auth_test_plugin<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">[</span>test_plugin<span class="token punctuation">.</span>c<span class="token operator">:</span>72<span class="token punctuation">]</span></code></pre>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-features-floatvalues.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="replication-features-floatvalues">
</a>
19.5.1.12 Replication and Floating-Point Values
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045135629056">
</a>
<a class="indexterm" name="idm46045135627552">
</a>
<p>
With statement-based replication, values are converted from
decimal to binary. Because conversions between decimal and
binary representations of them may be approximate, comparisons
involving floating-point values are inexact. This is true for
operations that use floating-point values explicitly, or that
use values that are converted to floating-point implicitly.
Comparisons of floating-point values might yield different
results on source and replica servers due to differences in
computer architecture, the compiler used to build MySQL, and so
forth. See
<a class="xref" href="type-conversion.html" title="14.3 Type Conversion in Expression Evaluation">
Section 14.3, “Type Conversion in Expression Evaluation”
</a>
, and
<a class="xref" href="problems-with-float.html" title="B.3.4.8 Problems with Floating-Point Values">
Section B.3.4.8, “Problems with Floating-Point Values”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/optimizing-innodb-configuration-variables.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="optimizing-innodb-configuration-variables">
</a>
10.5.9 Optimizing InnoDB Configuration Variables
</h3>
</div>
</div>
</div>
<p>
Different settings work best for servers with light, predictable
loads, versus servers that are running near full capacity all
the time, or that experience spikes of high activity.
</p>
<p>
Because the
<code class="literal">
InnoDB
</code>
storage engine performs
many of its optimizations automatically, many performance-tuning
tasks involve monitoring to ensure that the database is
performing well, and changing configuration options when
performance drops. See
<a class="xref" href="innodb-performance-schema.html" title="17.16 InnoDB Integration with MySQL Performance Schema">
Section 17.16, “InnoDB Integration with MySQL Performance Schema”
</a>
for information
about detailed
<code class="literal">
InnoDB
</code>
performance monitoring.
</p>
<p>
The main configuration steps you can perform include:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Controlling the types of data change operations for which
<code class="literal">
InnoDB
</code>
buffers the changed data, to avoid
frequent small disk writes. See
<a class="xref" href="innodb-change-buffer.html#innodb-change-buffer-configuration" title="Configuring Change Buffering">
Configuring Change Buffering
</a>
.
Enabling change buffering can give better performance on
IO-bound workloads, but can cause issues during recovery,
bulk load, or during buffer pool resizing. Having it
disabled (default as of MySQL 8.4) helps ensure stability
even if it may lower performance.
</p>
</li>
<li class="listitem">
<p>
Turning the adaptive hash indexing feature on and off using
the
<a class="link" href="innodb-parameters.html#sysvar_innodb_adaptive_hash_index">
<code class="literal">
innodb_adaptive_hash_index
</code>
</a>
option. See
<a class="xref" href="innodb-adaptive-hash.html" title="17.5.3 Adaptive Hash Index">
Section 17.5.3, “Adaptive Hash Index”
</a>
for more
information. You might change this setting during periods of
unusual activity, then restore it to its original setting.
</p>
</li>
<li class="listitem">
<p>
Setting a limit on the number of concurrent threads that
<code class="literal">
InnoDB
</code>
processes, if context switching is
a bottleneck. See
<a class="xref" href="innodb-performance-thread_concurrency.html" title="17.8.4 Configuring Thread Concurrency for InnoDB">
Section 17.8.4, “Configuring Thread Concurrency for InnoDB”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Controlling the amount of prefetching that
<code class="literal">
InnoDB
</code>
does with its read-ahead
operations. When the system has unused I/O capacity, more
read-ahead can improve the performance of queries. Too much
read-ahead can cause periodic drops in performance on a
heavily loaded system. See
<a class="xref" href="innodb-performance-read_ahead.html" title="17.8.3.4 Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)">
Section 17.8.3.4, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Increasing the number of background threads for read or
write operations, if you have a high-end I/O subsystem that
is not fully utilized by the default values. See
<a class="xref" href="innodb-performance-multiple_io_threads.html" title="17.8.5 Configuring the Number of Background InnoDB I/O Threads">
Section 17.8.5, “Configuring the Number of Background InnoDB I/O Threads”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Controlling how much I/O
<code class="literal">
InnoDB
</code>
performs
in the background. See
<a class="xref" href="innodb-configuring-io-capacity.html" title="17.8.7 Configuring InnoDB I/O Capacity">
Section 17.8.7, “Configuring InnoDB I/O Capacity”
</a>
. You might
scale back this setting if you observe periodic drops in
performance.
</p>
</li>
<li class="listitem">
<p>
Controlling the algorithm that determines when
<code class="literal">
InnoDB
</code>
performs certain types of
background writes. See
<a class="xref" href="innodb-buffer-pool-flushing.html" title="17.8.3.5 Configuring Buffer Pool Flushing">
Section 17.8.3.5, “Configuring Buffer Pool Flushing”
</a>
. The algorithm
works for some types of workloads but not others, so you
might disable this feature if you observe periodic drops in
performance.
</p>
</li>
<li class="listitem">
<p>
Taking advantage of multicore processors and their cache
memory configuration, to minimize delays in context
switching. See
<a class="xref" href="innodb-performance-spin_lock_polling.html" title="17.8.8 Configuring Spin Lock Polling">
Section 17.8.8, “Configuring Spin Lock Polling”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Preventing one-time operations such as table scans from
interfering with the frequently accessed data stored in the
<code class="literal">
InnoDB
</code>
buffer cache. See
<a class="xref" href="innodb-performance-midpoint_insertion.html" title="17.8.3.3 Making the Buffer Pool Scan Resistant">
Section 17.8.3.3, “Making the Buffer Pool Scan Resistant”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Adjusting log files to a size that makes sense for
reliability and crash recovery.
<code class="literal">
InnoDB
</code>
log files have often been kept small to avoid long startup
times after a crash. Optimizations introduced in MySQL 5.5
speed up certain steps of the crash
<a class="link" href="glossary.html#glos_crash_recovery" title="crash recovery">
recovery
</a>
process.
In particular, scanning the
<a class="link" href="glossary.html#glos_redo_log" title="redo log">
redo log
</a>
and applying
the redo log are faster due to improved algorithms for
memory management. If you have kept your log files
artificially small to avoid long startup times, you can now
consider increasing log file size to reduce the I/O that
occurs due recycling of redo log records.
</p>
</li>
<li class="listitem">
<p>
Configuring the size and number of instances for the
<code class="literal">
InnoDB
</code>
buffer pool, especially important
for systems with multi-gigabyte buffer pools. See
<a class="xref" href="innodb-multiple-buffer-pools.html" title="17.8.3.2 Configuring Multiple Buffer Pool Instances">
Section 17.8.3.2, “Configuring Multiple Buffer Pool Instances”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Increasing the maximum number of concurrent transactions,
which dramatically improves scalability for the busiest
databases. See
<a class="xref" href="innodb-undo-logs.html" title="17.6.6 Undo Logs">
Section 17.6.6, “Undo Logs”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Moving purge operations (a type of garbage collection) into
a background thread. See
<a class="xref" href="innodb-purge-configuration.html" title="17.8.9 Purge Configuration">
Section 17.8.9, “Purge Configuration”
</a>
. To effectively
measure the results of this setting, tune the other
I/O-related and thread-related configuration settings first.
</p>
</li>
<li class="listitem">
<p>
Reducing the amount of switching that
<code class="literal">
InnoDB
</code>
does between concurrent threads,
so that SQL operations on a busy server do not queue up and
form a
<span class="quote">
“
<span class="quote">
traffic jam
</span>
”
</span>
. Set a value for the
<a class="link" href="innodb-parameters.html#sysvar_innodb_thread_concurrency">
<code class="literal">
innodb_thread_concurrency
</code>
</a>
option, up to approximately 32 for a high-powered modern
system. Increase the value for the
<a class="link" href="innodb-parameters.html#sysvar_innodb_concurrency_tickets">
<code class="literal">
innodb_concurrency_tickets
</code>
</a>
option, typically to 5000 or so. This combination of options
sets a cap on the number of threads that
<code class="literal">
InnoDB
</code>
processes at any one time, and
allows each thread to do substantial work before being
swapped out, so that the number of waiting threads stays low
and operations can complete without excessive context
switching.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/partitioning-hash.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="partitioning-hash">
</a>
26.2.4 HASH Partitioning
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="partitioning-linear-hash.html">
26.2.4.1 LINEAR HASH Partitioning
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045084337344">
</a>
<a class="indexterm" name="idm46045084335856">
</a>
<p>
Partitioning by
<code class="literal">
HASH
</code>
is used primarily to
ensure an even distribution of data among a predetermined number
of partitions. With range or list partitioning, you must specify
explicitly which partition a given column value or set of column
values should be stored in; with hash partitioning, this
decision is taken care of for you, and you need only specify a
column value or expression based on a column value to be hashed
and the number of partitions into which the partitioned table is
to be divided.
</p>
<p>
To partition a table using
<code class="literal">
HASH
</code>
partitioning,
it is necessary to append to the
<a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
<code class="literal">
CREATE
TABLE
</code>
</a>
statement a
<code class="literal">
PARTITION BY HASH
(
<em class="replaceable">
<code>
expr
</code>
</em>
)
</code>
clause, where
<em class="replaceable">
<code>
expr
</code>
</em>
is an expression that returns an
integer. This can simply be the name of a column whose type is
one of MySQL's integer types. In addition, you most likely
want to follow this with
<code class="literal">
PARTITIONS
<em class="replaceable">
<code>
num
</code>
</em>
</code>
, where
<em class="replaceable">
<code>
num
</code>
</em>
is a positive integer
representing the number of partitions into which the table is to
be divided.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
For simplicity, the tables in the examples that follow do not
use any keys. You should be aware that, if a table has any
unique keys, every column used in the partitioning expression
for this table must be part of every unique key, including the
primary key. See
<a class="xref" href="partitioning-limitations-partitioning-keys-unique-keys.html" title="26.6.1 Partitioning Keys, Primary Keys, and Unique Keys">
Section 26.6.1, “Partitioning Keys, Primary Keys, and Unique Keys”
</a>
,
for more information.
</p>
</div>
<p>
The following statement creates a table that uses hashing on the
<code class="literal">
store_id
</code>
column and is divided into 4
partitions:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10036804"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> employees <span class="token punctuation">(</span>
id <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
fname <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
lname <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
hired <span class="token datatype">DATE</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'1970-01-01'</span><span class="token punctuation">,</span>
separated <span class="token datatype">DATE</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'9999-12-31'</span><span class="token punctuation">,</span>
job_code <span class="token datatype">INT</span><span class="token punctuation">,</span>
store_id <span class="token datatype">INT</span>
<span class="token punctuation">)</span>
<span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> <span class="token keyword">HASH</span><span class="token punctuation">(</span>store_id<span class="token punctuation">)</span>
<span class="token keyword">PARTITIONS</span> <span class="token number">4</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
If you do not include a
<code class="literal">
PARTITIONS
</code>
clause,
the number of partitions defaults to
<code class="literal">
1
</code>
; using
the
<code class="literal">
PARTITIONS
</code>
keyword without a number
following it results in a syntax error.
</p>
<a class="indexterm" name="idm46045084320416">
</a>
<p>
You can also use an SQL expression that returns an integer for
<em class="replaceable">
<code>
expr
</code>
</em>
. For instance, you might want to
partition based on the year in which an employee was hired. This
can be done as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa97053718"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> employees <span class="token punctuation">(</span>
id <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
fname <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
lname <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
hired <span class="token datatype">DATE</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'1970-01-01'</span><span class="token punctuation">,</span>
separated <span class="token datatype">DATE</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'9999-12-31'</span><span class="token punctuation">,</span>
job_code <span class="token datatype">INT</span><span class="token punctuation">,</span>
store_id <span class="token datatype">INT</span>
<span class="token punctuation">)</span>
<span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> <span class="token keyword">HASH</span><span class="token punctuation">(</span> <span class="token function">YEAR</span><span class="token punctuation">(</span>hired<span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token keyword">PARTITIONS</span> <span class="token number">4</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
<em class="replaceable">
<code>
expr
</code>
</em>
must return a nonconstant,
nonrandom integer value (in other words, it should be varying
but deterministic), and must not contain any prohibited
constructs as described in
<a class="xref" href="partitioning-limitations.html" title="26.6 Restrictions and Limitations on Partitioning">
Section 26.6, “Restrictions and Limitations on Partitioning”
</a>
. You should also keep
in mind that this expression is evaluated each time a row is
inserted or updated (or possibly deleted); this means that very
complex expressions may give rise to performance issues,
particularly when performing operations (such as batch inserts)
that affect a great many rows at one time.
</p>
<p>
The most efficient hashing function is one which operates upon a
single table column and whose value increases or decreases
consistently with the column value, as this allows for
<span class="quote">
“
<span class="quote">
pruning
</span>
”
</span>
on ranges of partitions. That is, the
more closely that the expression varies with the value of the
column on which it is based, the more efficiently MySQL can use
the expression for hash partitioning.
</p>
<p>
For example, where
<code class="literal">
date_col
</code>
is a column of
type
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATE
</code>
</a>
, then the expression
<a class="link" href="date-and-time-functions.html#function_to-days">
<code class="literal">
TO_DAYS(date_col)
</code>
</a>
is said to vary
directly with the value of
<code class="literal">
date_col
</code>
, because
for every change in the value of
<code class="literal">
date_col
</code>
,
the value of the expression changes in a consistent manner. The
variance of the expression
<a class="link" href="date-and-time-functions.html#function_year">
<code class="literal">
YEAR(date_col)
</code>
</a>
with respect to
<code class="literal">
date_col
</code>
is not quite as direct as that of
<a class="link" href="date-and-time-functions.html#function_to-days">
<code class="literal">
TO_DAYS(date_col)
</code>
</a>
, because not
every possible change in
<code class="literal">
date_col
</code>
produces an
equivalent change in
<a class="link" href="date-and-time-functions.html#function_year">
<code class="literal">
YEAR(date_col)
</code>
</a>
. Even so,
<a class="link" href="date-and-time-functions.html#function_year">
<code class="literal">
YEAR(date_col)
</code>
</a>
is a good
candidate for a hashing function, because it varies directly
with a portion of
<code class="literal">
date_col
</code>
and there is no
possible change in
<code class="literal">
date_col
</code>
that produces a
disproportionate change in
<a class="link" href="date-and-time-functions.html#function_year">
<code class="literal">
YEAR(date_col)
</code>
</a>
.
</p>
<p>
By way of contrast, suppose that you have a column named
<code class="literal">
int_col
</code>
whose type is
<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>
. Now consider the expression
<a class="link" href="mathematical-functions.html#function_pow">
<code class="literal">
POW(5-int_col,3) + 6
</code>
</a>
. This would
be a poor choice for a hashing function because a change in the
value of
<code class="literal">
int_col
</code>
is not guaranteed to produce
a proportional change in the value of the expression. Changing
the value of
<code class="literal">
int_col
</code>
by a given amount can
produce widely differing changes in the value of the expression.
For example, changing
<code class="literal">
int_col
</code>
from
<code class="literal">
5
</code>
to
<code class="literal">
6
</code>
produces a change
of
<code class="literal">
-1
</code>
in the value of the expression, but
changing the value of
<code class="literal">
int_col
</code>
from
<code class="literal">
6
</code>
to
<code class="literal">
7
</code>
produces a change
of
<code class="literal">
-7
</code>
in the expression value.
</p>
<p>
In other words, the more closely the graph of the column value
versus the value of the expression follows a straight line as
traced by the equation
<code class="literal">
y=
<em class="replaceable">
<code>
c
</code>
</em>
x
</code>
where
<em class="replaceable">
<code>
c
</code>
</em>
is some nonzero constant, the
better the expression is suited to hashing. This has to do with
the fact that the more nonlinear an expression is, the more
uneven the distribution of data among the partitions it tends to
produce.
</p>
<p>
In theory, pruning is also possible for expressions involving
more than one column value, but determining which of such
expressions are suitable can be quite difficult and
time-consuming. For this reason, the use of hashing expressions
involving multiple columns is not particularly recommended.
</p>
<p>
When
<code class="literal">
PARTITION BY HASH
</code>
is used, the storage
engine determines which partition of
<em class="replaceable">
<code>
num
</code>
</em>
partitions to use based on the
modulus of the result of the expression. In other words, for a
given expression
<em class="replaceable">
<code>
expr
</code>
</em>
, the partition
in which the record is stored is partition number
<em class="replaceable">
<code>
N
</code>
</em>
, where
<code class="literal">
<em class="replaceable">
<code>
N
</code>
</em>
=
MOD(
<em class="replaceable">
<code>
expr
</code>
</em>
,
<em class="replaceable">
<code>
num
</code>
</em>
)
</code>
. Suppose that table
<code class="literal">
t1
</code>
is defined as follows, so that it has 4
partitions:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa37391553"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>col1 <span class="token datatype">INT</span><span class="token punctuation">,</span> col2 <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> col3 <span class="token datatype">DATE</span><span class="token punctuation">)</span>
<span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> <span class="token keyword">HASH</span><span class="token punctuation">(</span> <span class="token function">YEAR</span><span class="token punctuation">(</span>col3<span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token keyword">PARTITIONS</span> <span class="token number">4</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
If you insert a record into
<code class="literal">
t1
</code>
whose
<code class="literal">
col3
</code>
value is
<code class="literal">
'2005-09-15'
</code>
, then the partition in which it
is stored is determined as follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88807730"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token function">MOD</span><span class="token punctuation">(</span><span class="token function">YEAR</span><span class="token punctuation">(</span><span class="token string">'2005-09-01'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">)</span>
<span class="token operator">=</span> <span class="token function">MOD</span><span class="token punctuation">(</span><span class="token number">2005</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">)</span>
<span class="token operator">=</span> <span class="token number">1</span></code></pre>
</div>
<p>
MySQL 8.4 also supports a variant of
<code class="literal">
HASH
</code>
partitioning known as
<span class="firstterm">
linear hashing
</span>
which
employs a more complex algorithm for determining the placement
of new rows inserted into the partitioned table. See
<a class="xref" href="partitioning-linear-hash.html" title="26.2.4.1 LINEAR HASH Partitioning">
Section 26.2.4.1, “LINEAR HASH Partitioning”
</a>
, for a description of
this algorithm.
</p>
<p>
The user-supplied expression is evaluated each time a record is
inserted or updated. It may also—depending on the
circumstances—be evaluated when records are deleted.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-security.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="replication-security">
</a>
19.3 Replication Security
</h2>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="replication-encrypted-connections.html">
19.3.1 Setting Up Replication to Use Encrypted Connections
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-binlog-encryption.html">
19.3.2 Encrypting Binary Log Files and Relay Log Files
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-privilege-checks.html">
19.3.3 Replication Privilege Checks
</a>
</span>
</dt>
</dl>
</div>
<p>
To protect against unauthorized access to data that is stored on and
transferred between replication source servers and replicas, set up
all the servers involved using the security measures that you would
choose for any MySQL instance in your installation, as described in
<a class="xref" href="security.html" title="Chapter 8 Security">
Chapter 8,
<i>
Security
</i>
</a>
. In addition, for servers in a
replication topology, consider implementing the following security
measures:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Set up sources and replicas to use encrypted connections to
transfer the binary log, which protects this data in motion.
Encryption for these connections must be activated using a
<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, in addition to setting up the servers to support
encrypted network connections. See
<a class="xref" href="replication-encrypted-connections.html" title="19.3.1 Setting Up Replication to Use Encrypted Connections">
Section 19.3.1, “Setting Up Replication to Use Encrypted Connections”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Encrypt the binary log files and relay log files on sources and
replicas, which protects this data at rest, and also any data in
use in the binary log cache. Binary log encryption is activated
using the
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_encryption">
<code class="literal">
binlog_encryption
</code>
</a>
system variable. 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>
Apply privilege checks to replication appliers, which help to
secure replication channels against the unauthorized or
accidental use of privileged or unwanted operations. Privilege
checks are implemented by setting up a
<code class="literal">
PRIVILEGE_CHECKS_USER
</code>
account, which MySQL
uses to verify that you have authorized each specific
transaction for that channel. See
<a class="xref" href="replication-privilege-checks.html" title="19.3.3 Replication Privilege Checks">
Section 19.3.3, “Replication Privilege Checks”
</a>
.
</p>
</li>
</ul>
</div>
<p>
For Group Replication, binary log encryption and privilege checks
can be used as a security measure on replication group members. You
should also consider encrypting the connections between group
members, comprising group communication connections and distributed
recovery connections, and applying IP address allowlisting to
exclude untrusted hosts. For information on these security measures
specific to Group Replication, see
<a class="xref" href="group-replication-security.html" title="20.6 Group Replication Security">
Section 20.6, “Group Replication Security”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/selinux-mode.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="selinux-mode">
</a>
8.7.2 Changing the SELinux Mode
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045231636704">
</a>
<p>
SELinux supports enforcing, permissive, and disabled modes.
Enforcing mode is the default. Permissive mode allows operations
that are not permitted in enforcing mode and logs those operations
to the SELinux audit log. Permissive mode is typically used when
developing policies or troubleshooting. In disabled mode, polices
are not enforced, and contexts are not applied to system objects,
which makes it difficult to enable SELinux later.
</p>
<p>
To view the current SELinux mode, use the
<span class="command">
<strong>
sestatus
</strong>
</span>
command mentioned previously or the
<span class="command">
<strong>
getenforce
</strong>
</span>
utility.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa96750137"><div class="copy-help left">Press ⌘+C to 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 operator">></span> getenforce
Enforcing</code></pre>
</div>
<p>
To change the SELinux mode, use the
<code class="literal">
setenforce
</code>
utility:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa25181167"><div class="copy-help left">Press ⌘+C to 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 operator">></span> setenforce 0
$<span class="token operator">></span> getenforce
Permissive</code></pre>
</div>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa20009524"><div class="copy-help left">Press ⌘+C to 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 operator">></span> setenforce 1
$<span class="token operator">></span> getenforce
Enforcing</code></pre>
</div>
<p>
Changes made with
<span class="command">
<strong>
setenforce
</strong>
</span>
are lost when you
restart the system. To permanently change the SELinux mode, edit
the
<code class="filename">
/etc/selinux/config
</code>
file and restart the
system.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/faqs-innodb-change-buffer.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="faqs-innodb-change-buffer">
</a>
A.16 MySQL 8.4 FAQ: InnoDB Change Buffer
</h2>
</div>
</div>
</div>
<div class="qandaset">
<a name="idm46045054908128">
</a>
<dl>
<dt>
A.16.1.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-operations">
What types of operations modify secondary indexes and result in
change buffering?
</a>
</dt>
<dt>
A.16.2.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-benefits">
What is the benefit of the InnoDB change
buffer?
</a>
</dt>
<dt>
A.16.3.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-index-types">
Does the change buffer support other types of indexes?
</a>
</dt>
<dt>
A.16.4.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-space-max-size">
How much space does InnoDB use for the change
buffer?
</a>
</dt>
<dt>
A.16.5.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-current-size">
How do I determine the current size of the change buffer?
</a>
</dt>
<dt>
A.16.6.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-merging">
When does change buffer merging occur?
</a>
</dt>
<dt>
A.16.7.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-flush-time">
When is the change buffer flushed?
</a>
</dt>
<dt>
A.16.8.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-when-to-enable">
When should the change buffer be used?
</a>
</dt>
<dt>
A.16.9.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-when-to-disable">
When should the change buffer not be used?
</a>
</dt>
<dt>
A.16.10.
<a href="faqs-innodb-change-buffer.html#faq-innodb-change-buffer-info">
Where can I find additional information about the change buffer?
</a>
</dt>
</dl>
<table border="0" style="width: 100%;">
<colgroup>
<col align="left" width="1%"/>
<col/>
</colgroup>
<tbody>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-operations">
</a>
<a name="idm46045054907376">
</a>
<p>
<b>
A.16.1.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
What types of operations modify secondary indexes and result in
change buffering?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
<code class="literal">
INSERT
</code>
,
<code class="literal">
UPDATE
</code>
, and
<code class="literal">
DELETE
</code>
operations can modify secondary
indexes. If an affected index page is not in the buffer pool,
the changes can be buffered in the change buffer.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-benefits">
</a>
<a name="idm46045054903056">
</a>
<p>
<b>
A.16.2.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
What is the benefit of the
<code class="literal">
InnoDB
</code>
change
buffer?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Buffering secondary index changes when secondary index pages are
not in the buffer pool avoids expensive random access I/O
operations that would be required to immediately read in
affected index pages from disk. Buffered changes can be applied
later, in batches, as pages are read into the buffer pool by
other read operations.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-index-types">
</a>
<a name="idm46045054899952">
</a>
<p>
<b>
A.16.3.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Does the change buffer support other types of indexes?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
No. The change buffer only supports secondary indexes. Clustered
indexes, full-text indexes, and spatial indexes are not
supported. Full-text indexes have their own caching mechanism.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-space-max-size">
</a>
<a name="idm46045054897728">
</a>
<p>
<b>
A.16.4.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
How much space does
<code class="literal">
InnoDB
</code>
use for the change
buffer?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Prior to the introduction of the
<a class="link" href="innodb-parameters.html#sysvar_innodb_change_buffer_max_size">
<code class="literal">
innodb_change_buffer_max_size
</code>
</a>
configuration option in MySQL 5.6, the maximum size of the
on-disk change buffer in the system tablespace was 1/3 of the
<code class="literal">
InnoDB
</code>
buffer pool size.
</p>
<p>
In MySQL 5.6 and later, the
<a class="link" href="innodb-parameters.html#sysvar_innodb_change_buffer_max_size">
<code class="literal">
innodb_change_buffer_max_size
</code>
</a>
configuration option defines the maximum size of the change
buffer as a percentage of the total buffer pool size. By
default,
<a class="link" href="innodb-parameters.html#sysvar_innodb_change_buffer_max_size">
<code class="literal">
innodb_change_buffer_max_size
</code>
</a>
is set to 25. The maximum setting is 50.
</p>
<p>
<code class="literal">
InnoDB
</code>
does not buffer an operation if it
would cause the on-disk change buffer to exceed the defined
limit.
</p>
<p>
Change buffer pages are not required to persist in the buffer
pool and may be evicted by LRU operations.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-current-size">
</a>
<a name="idm46045054887920">
</a>
<p>
<b>
A.16.5.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
How do I determine the current size of the change buffer?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
The current size of the change buffer is reported by
<code class="literal">
SHOW ENGINE INNODB STATUS \G
</code>
, under the
<code class="literal">
INSERT BUFFER AND ADAPTIVE HASH INDEX
</code>
heading. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-none"><div class="docs-select-all right" id="sa3305531"><div class="copy-help left">Press ⌘+C to 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">-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges</code></pre>
</div>
<p>
Relevant data points include:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
size
</code>
: The number of pages used within the
change buffer. Change buffer size is equal to
<code class="literal">
seg
size - (1 + free list len)
</code>
. The
<code class="literal">
1
+
</code>
value represents the change buffer header page.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
seg size
</code>
: The size of the change buffer,
in pages.
</p>
</li>
</ul>
</div>
<p>
For information about monitoring change buffer status, see
<a class="xref" href="innodb-change-buffer.html" title="17.5.2 Change Buffer">
Section 17.5.2, “Change Buffer”
</a>
.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-merging">
</a>
<a name="idm46045054876624">
</a>
<p>
<b>
A.16.6.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
When does change buffer merging occur?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
When a page is read into the buffer pool, buffered changes
are merged upon completion of the read, before the page is
made available.
</p>
</li>
<li class="listitem">
<p>
Change buffer merging is performed as a background task. The
<a class="link" href="innodb-parameters.html#sysvar_innodb_io_capacity">
<code class="literal">
innodb_io_capacity
</code>
</a>
parameter sets an upper limit on the I/O activity performed
by
<code class="literal">
InnoDB
</code>
background tasks such as
merging data from the change buffer.
</p>
</li>
<li class="listitem">
<p>
A change buffer merge is performed during crash recovery.
Changes are applied from the change buffer (in the system
tablespace) to leaf pages of secondary indexes as index
pages are read into the buffer pool.
</p>
</li>
<li class="listitem">
<p>
The change buffer is fully durable and can survive a system
crash. Upon restart, change buffer merge operations resume
as part of normal operations.
</p>
</li>
<li class="listitem">
<p>
A full merge of the change buffer can be forced as part of a
slow server shutdown using
<a class="link" href="innodb-parameters.html#sysvar_innodb_fast_shutdown">
<code class="literal">
--innodb-fast-shutdown=0
</code>
</a>
.
</p>
</li>
</ul>
</div>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-flush-time">
</a>
<a name="idm46045054866464">
</a>
<p>
<b>
A.16.7.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
When is the change buffer flushed?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
Updated pages are flushed by the same flushing mechanism that
flushes the other pages that occupy the buffer pool.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-when-to-enable">
</a>
<a name="idm46045054864384">
</a>
<p>
<b>
A.16.8.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
When should the change buffer be used?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
The change buffer is a feature designed to reduce random I/O to
secondary indexes as indexes grow larger and no longer fit in
the
<code class="literal">
InnoDB
</code>
buffer pool. Generally, the change
buffer should be used when the entire data set does not fit into
the buffer pool, when there is substantial DML activity that
modifies secondary index pages, or when there are lots of
secondary indexes that are regularly changed by DML activity.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-when-to-disable">
</a>
<a name="idm46045054861152">
</a>
<p>
<b>
A.16.9.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
When should the change buffer not be used?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
You might consider disabling the change buffer if the entire
data set fits within the
<code class="literal">
InnoDB
</code>
buffer pool,
if you have relatively few secondary indexes, or if you are
using solid-state storage, where random reads are about as fast
as sequential reads. Before making configuration changes, it is
recommended that you run tests using a representative workload
to determine if disabling the change buffer provides any
benefit.
</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="faq-innodb-change-buffer-info">
</a>
<a name="idm46045054857968">
</a>
<p>
<b>
A.16.10.
</b>
</p>
</td>
<td align="left" valign="top">
<p>
Where can I find additional information about the change buffer?
</p>
</td>
</tr>
<tr class="answer">
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<p>
See
<a class="xref" href="innodb-change-buffer.html" title="17.5.2 Change Buffer">
Section 17.5.2, “Change Buffer”
</a>
.
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/x-plugin-options-system-variables.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="x-plugin-options-system-variables">
</a>
22.5.6.2 X Plugin Options and System Variables
</h4>
</div>
</div>
</div>
<p>
To control activation of X Plugin, use this option:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_mysqld_mysqlx">
</a>
<a class="link" href="x-plugin-options-system-variables.html#option_mysqld_mysqlx">
<code class="option">
--mysqlx[=value]
</code>
</a>
</p>
<a class="indexterm" name="idm46045125788784">
</a>
<a class="indexterm" name="idm46045125787712">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx[=value]
</code>
</td>
</tr>
<tr>
<th>
Type
</th>
<td>
Enumeration
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
ON
</code>
</td>
</tr>
<tr>
<th>
Valid Values
</th>
<td>
<p class="valid-value">
<code class="literal">
ON
</code>
</p>
<p class="valid-value">
<code class="literal">
OFF
</code>
</p>
<p class="valid-value">
<code class="literal">
FORCE
</code>
</p>
<p class="valid-value">
<code class="literal">
FORCE_PLUS_PERMANENT
</code>
</p>
</td>
</tr>
</tbody>
</table>
</div>
<p>
This option controls how the server loads X Plugin at
startup. In MySQL 8.4, X Plugin is enabled by
default, but this option may be used to control its
activation state.
</p>
<p>
The option value should be one of those available for
plugin-loading options, as described in
<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>
</li>
</ul>
</div>
<p>
If X Plugin is enabled, it exposes several system variables
that permit control over its operation:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="sysvar_mysqlx_bind_address">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address">
<code class="literal">
mysqlx_bind_address
</code>
</a>
</p>
<a class="indexterm" name="idm46045125765344">
</a>
<a class="indexterm" name="idm46045125764304">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_bind_address">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-bind-address=addr
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address">
mysqlx_bind_address
</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>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
*
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The network address on which X Plugin listens for TCP/IP
connections. This variable is not dynamic and can be
configured only at startup. This is the X Plugin equivalent
of the
<a class="link" href="server-system-variables.html#sysvar_bind_address">
<code class="literal">
bind_address
</code>
</a>
system
variable; see that variable description for more
information.
</p>
<p>
By default, X Plugin accepts TCP/IP connections on all
server host IPv4 interfaces, and, if the server host
supports IPv6, on all IPv6 interfaces. If
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address">
<code class="literal">
mysqlx_bind_address
</code>
</a>
is
specified, its value must satisfy these requirements:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
A single address value, which may specify a single
non-wildcard IP address (either IPv4 or IPv6), or a host
name, or one of the wildcard address formats that permit
listening on multiple network interfaces
(
<code class="literal">
*
</code>
,
<code class="literal">
0.0.0.0
</code>
, or
<code class="literal">
::
</code>
).
</p>
</li>
<li class="listitem">
<p>
A list of comma-separated values. When the variable
names a list of multiple values, each value must specify
a single non-wildcard IP address (either IPv4 or IPv6)
or a host name. Wildcard address formats
(
<code class="literal">
*
</code>
,
<code class="literal">
0.0.0.0
</code>
, or
<code class="literal">
::
</code>
) are not allowed in a list of
values.
</p>
</li>
<li class="listitem">
<p>
The value may also include a network namespace
specifier.
</p>
</li>
</ul>
</div>
<p>
IP addresses can be specified as IPv4 or IPv6 addresses. For
any value that is a host name, X Plugin resolves the name
to an IP address and binds to that address. If a host name
resolves to multiple IP addresses, X Plugin uses the first
IPv4 address if there are any, or the first IPv6 address
otherwise.
</p>
<p>
X Plugin treats different types of addresses as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
If the address is
<code class="literal">
*
</code>
, X Plugin
accepts TCP/IP connections on all server host IPv4
interfaces, and, if the server host supports IPv6, on
all IPv6 interfaces. Use this address to permit both
IPv4 and IPv6 connections for X Plugin. This value is
the default. If the variable specifies a list of
multiple values, this value is not permitted.
</p>
</li>
<li class="listitem">
<p>
If the address is
<code class="literal">
0.0.0.0
</code>
, X Plugin
accepts TCP/IP connections on all server host IPv4
interfaces. If the variable specifies a list of multiple
values, this value is not permitted.
</p>
</li>
<li class="listitem">
<p>
If the address is
<code class="literal">
::
</code>
, X Plugin
accepts TCP/IP connections on all server host IPv4 and
IPv6 interfaces. If the variable specifies a list of
multiple values, this value is not permitted.
</p>
</li>
<li class="listitem">
<p>
If the address is an IPv4-mapped address, X Plugin
accepts TCP/IP connections for that address, in either
IPv4 or IPv6 format. For example, if X Plugin is bound
to
<code class="literal">
::ffff:127.0.0.1
</code>
, a client such as
MySQL Shell can connect using
<code class="option">
--host=127.0.0.1
</code>
or
<code class="option">
--host=::ffff:127.0.0.1
</code>
.
</p>
</li>
<li class="listitem">
<p>
If the address is a
<span class="quote">
“
<span class="quote">
regular
</span>
”
</span>
IPv4 or IPv6
address (such as
<code class="literal">
127.0.0.1
</code>
or
<code class="literal">
::1
</code>
), X Plugin accepts TCP/IP
connections only for that IPv4 or IPv6 address.
</p>
</li>
</ul>
</div>
<p>
These rules apply to specifying a network namespace for an
address:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
A network namespace can be specified for an IP address
or a host name.
</p>
</li>
<li class="listitem">
<p>
A network namespace cannot be specified for a wildcard
IP address.
</p>
</li>
<li class="listitem">
<p>
For a given address, the network namespace is optional.
If given, it must be specified as a
<code class="literal">
/
<em class="replaceable">
<code>
ns
</code>
</em>
</code>
suffix
immediately following the address.
</p>
</li>
<li class="listitem">
<p>
An address with no
<code class="literal">
/
<em class="replaceable">
<code>
ns
</code>
</em>
</code>
suffix
uses the host system global namespace. The global
namespace is therefore the default.
</p>
</li>
<li class="listitem">
<p>
An address with a
<code class="literal">
/
<em class="replaceable">
<code>
ns
</code>
</em>
</code>
suffix
uses the namespace named
<em class="replaceable">
<code>
ns
</code>
</em>
.
</p>
</li>
<li class="listitem">
<p>
The host system must support network namespaces and each
named namespace must previously have been set up. Naming
a nonexistent namespace produces an error.
</p>
</li>
<li class="listitem">
<p>
If the variable value specifies multiple addresses, it
can include addresses in the global namespace, in named
namespaces, or a mix.
</p>
</li>
</ul>
</div>
<p>
For additional information about network namespaces, see
<a class="xref" href="network-namespace-support.html" title="7.1.14 Network Namespace Support">
Section 7.1.14, “Network Namespace Support”
</a>
.
</p>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Important
</div>
<p>
Because X Plugin is not a mandatory plugin, it does not
prevent server startup if there is an error in the
specified address or list of addresses (as MySQL Server
does for
<a class="link" href="server-system-variables.html#sysvar_bind_address">
<code class="literal">
bind_address
</code>
</a>
errors). With X Plugin, if one of the listed addresses
cannot be parsed or if X Plugin cannot bind to it, the
address is skipped, an error message is logged, and
X Plugin attempts to bind to each of the remaining
addresses. X Plugin's
<a class="link" href="x-plugin-status-variables.html#statvar_Mysqlx_address">
<code class="literal">
Mysqlx_address
</code>
</a>
status
variable displays only those addresses from the list for
which the bind succeeded. If none of the listed addresses
results in a successful bind, or if a single specified
address fails, X Plugin logs the error message
<a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_xplugin_failed_to_prepare_io_interfaces" target="_top">
<code class="literal">
ER_XPLUGIN_FAILED_TO_PREPARE_IO_INTERFACES
</code>
</a>
stating that X Protocol cannot be used.
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address">
<code class="literal">
mysqlx_bind_address
</code>
</a>
is
not dynamic, so to fix any issues you must stop the
server, correct the system variable value, and restart the
server.
</p>
</div>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_compression_algorithms">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_compression_algorithms">
<code class="literal">
mysqlx_compression_algorithms
</code>
</a>
</p>
<a class="indexterm" name="idm46045125697584">
</a>
<a class="indexterm" name="idm46045125696480">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_compression_algorithms">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-compression-algorithms=value
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_compression_algorithms">
mysqlx_compression_algorithms
</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>
Set
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
deflate_stream,lz4_message,zstd_stream
</code>
</td>
</tr>
<tr>
<th>
Valid Values
</th>
<td>
<p class="valid-value">
<code class="literal">
deflate_stream
</code>
</p>
<p class="valid-value">
<code class="literal">
lz4_message
</code>
</p>
<p class="valid-value">
<code class="literal">
zstd_stream
</code>
</p>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The compression algorithms that are permitted for use on
X Protocol connections. By default, the Deflate, LZ4, and
zstd algorithms are all permitted. To disallow any of the
algorithms, set
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_compression_algorithms">
<code class="literal">
mysqlx_compression_algorithms
</code>
</a>
to include only the ones you permit. The algorithm names
<code class="literal">
deflate_stream
</code>
,
<code class="literal">
lz4_message
</code>
, and
<code class="literal">
zstd_stream
</code>
can be specified in any
combination, and the order and case are not important. If
you set the system variable to the empty string, no
compression algorithms are permitted and only uncompressed
connections are used. Use the algorithm-specific system
variables to adjust the default and maximum compression
level for each permitted algorithm. For more details, and
information on how connection compression for X Protocol
relates to the equivalent settings for MySQL Server, see
<a class="xref" href="x-plugin-connection-compression.html" title="22.5.5 Connection Compression with X Plugin">
Section 22.5.5, “Connection Compression with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_connect_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_connect_timeout">
<code class="literal">
mysqlx_connect_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045125662064">
</a>
<a class="indexterm" name="idm46045125661024">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_connect_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-connect-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_connect_timeout">
mysqlx_connect_timeout
</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">
30
</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">
1000000000
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The number of seconds X Plugin waits for the first packet
to be received from newly connected clients. This is the
X Plugin equivalent of
<a class="link" href="server-system-variables.html#sysvar_connect_timeout">
<code class="literal">
connect_timeout
</code>
</a>
; see that
variable description for more information.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_deflate_default_compression_level">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_deflate_default_compression_level">
<code class="literal">
mysqlx_deflate_default_compression_level
</code>
</a>
</p>
<a class="indexterm" name="idm46045125628096">
</a>
<a class="indexterm" name="idm46045125626976">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_deflate_default_compression_level">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx_deflate_default_compression_level=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_deflate_default_compression_level">
mysqlx_deflate_default_compression_level
</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">
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">
9
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The default compression level that the server uses for the
Deflate algorithm on X Protocol connections. Specify the
level as an integer from 1 (the lowest compression effort)
to 9 (the highest effort). This level is used if the client
does not request a compression level during capability
negotiation. If you do not specify this system variable, the
server uses level 3 as the default. For more information,
see
<a class="xref" href="x-plugin-connection-compression.html" title="22.5.5 Connection Compression with X Plugin">
Section 22.5.5, “Connection Compression with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_deflate_max_client_compression_level">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_deflate_max_client_compression_level">
<code class="literal">
mysqlx_deflate_max_client_compression_level
</code>
</a>
</p>
<a class="indexterm" name="idm46045125596208">
</a>
<a class="indexterm" name="idm46045125595088">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_deflate_max_client_compression_level">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx_deflate_max_client_compression_level=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_deflate_max_client_compression_level">
mysqlx_deflate_max_client_compression_level
</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">
5
</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">
9
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The maximum compression level that the server permits for
the Deflate algorithm on X Protocol connections. The range
is the same as for the default compression level for this
algorithm. If the client requests a higher compression level
than this, the server uses the level you set here. If you do
not specify this system variable, the server sets a maximum
compression level of 5.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_document_id_unique_prefix">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_document_id_unique_prefix">
<code class="literal">
mysqlx_document_id_unique_prefix
</code>
</a>
</p>
<a class="indexterm" name="idm46045125565184">
</a>
<a class="indexterm" name="idm46045125564080">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_document_id_unique_prefix">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-document-id-unique-prefix=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_document_id_unique_prefix">
mysqlx_document_id_unique_prefix
</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">
65535
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Sets the first 4 bytes of document IDs generated by the
server when documents are added to a collection. By setting
this variable to a unique value per instance, you can ensure
document IDs are unique across instances. See
<a class="ulink" href="/doc/x-devapi-userguide/en/understanding-automatic-document-ids.html" target="_top">
Understanding Document IDs
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_enable_hello_notice">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_enable_hello_notice">
<code class="literal">
mysqlx_enable_hello_notice
</code>
</a>
</p>
<a class="indexterm" name="idm46045125532784">
</a>
<a class="indexterm" name="idm46045125531680">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_enable_hello_notice">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-enable-hello-notice[={OFF|ON}]
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_enable_hello_notice">
mysqlx_enable_hello_notice
</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>
Controls messages sent to classic MySQL protocol clients that try
to connect over X Protocol. When enabled, clients which do
not support X Protocol that attempt to connect to the
server X Protocol port receive an error explaining they are
using the wrong protocol.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_idle_worker_thread_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_idle_worker_thread_timeout">
<code class="literal">
mysqlx_idle_worker_thread_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045125506656">
</a>
<a class="indexterm" name="idm46045125505616">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_idle_worker_thread_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-idle-worker-thread-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_idle_worker_thread_timeout">
mysqlx_idle_worker_thread_timeout
</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">
60
</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">
3600
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The number of seconds after which idle worker threads are
terminated.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_interactive_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_interactive_timeout">
<code class="literal">
mysqlx_interactive_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045125474000">
</a>
<a class="indexterm" name="idm46045125472896">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_interactive_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-interactive-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_interactive_timeout">
mysqlx_interactive_timeout
</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">
28800
</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">
2147483
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The default value of the
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_wait_timeout">
<code class="literal">
mysqlx_wait_timeout
</code>
</a>
session
variable for interactive clients. (The number of seconds to
wait for interactive clients to timeout.)
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_lz4_default_compression_level">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_lz4_default_compression_level">
<code class="literal">
mysqlx_lz4_default_compression_level
</code>
</a>
</p>
<a class="indexterm" name="idm46045125439824">
</a>
<a class="indexterm" name="idm46045125438784">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_lz4_default_compression_level">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx_lz4_default_compression_level=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_lz4_default_compression_level">
mysqlx_lz4_default_compression_level
</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">
2
</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">
16
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The default compression level that the server uses for the
LZ4 algorithm on X Protocol connections. Specify the level
as an integer from 0 (the lowest compression effort) to 16
(the highest effort). This level is used if the client does
not request a compression level during capability
negotiation. If you do not specify this system variable, the
server uses level 2 as the default. For more information,
see
<a class="xref" href="x-plugin-connection-compression.html" title="22.5.5 Connection Compression with X Plugin">
Section 22.5.5, “Connection Compression with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_lz4_max_client_compression_level">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_lz4_max_client_compression_level">
<code class="literal">
mysqlx_lz4_max_client_compression_level
</code>
</a>
</p>
<a class="indexterm" name="idm46045125408000">
</a>
<a class="indexterm" name="idm46045125406960">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_lz4_max_client_compression_level">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx_lz4_max_client_compression_level=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_lz4_max_client_compression_level">
mysqlx_lz4_max_client_compression_level
</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">
8
</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">
16
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The maximum compression level that the server permits for
the LZ4 algorithm on X Protocol connections. The range is
the same as for the default compression level for this
algorithm. If the client requests a higher compression level
than this, the server uses the level you set here. If you do
not specify this system variable, the server sets a maximum
compression level of 8.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_max_allowed_packet">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_max_allowed_packet">
<code class="literal">
mysqlx_max_allowed_packet
</code>
</a>
</p>
<a class="indexterm" name="idm46045125377104">
</a>
<a class="indexterm" name="idm46045125376000">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_max_allowed_packet">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-max-allowed-packet=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_max_allowed_packet">
mysqlx_max_allowed_packet
</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">
67108864
</code>
</td>
</tr>
<tr>
<th>
Minimum Value
</th>
<td>
<code class="literal">
512
</code>
</td>
</tr>
<tr>
<th>
Maximum Value
</th>
<td>
<code class="literal">
1073741824
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
bytes
</td>
</tr>
</tbody>
</table>
</div>
<p>
The maximum size of network packets that can be received by
X Plugin. This limit also applies when compression is used
for the connection, so the network packet must be smaller
than this size after the message has been decompressed. This
is the X Plugin equivalent of
<a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
<code class="literal">
max_allowed_packet
</code>
</a>
; see
that variable description for more information.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_max_connections">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_max_connections">
<code class="literal">
mysqlx_max_connections
</code>
</a>
</p>
<a class="indexterm" name="idm46045125342864">
</a>
<a class="indexterm" name="idm46045125341824">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_max_connections">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-max-connections=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_max_connections">
mysqlx_max_connections
</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">
100
</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">
65535
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The maximum number of concurrent client connections
X Plugin can accept. This is the X Plugin equivalent of
<a class="link" href="server-system-variables.html#sysvar_max_connections">
<code class="literal">
max_connections
</code>
</a>
; see that
variable description for more information.
</p>
<p>
For modifications to this variable, if the new value is
smaller than the current number of connections, the new
limit is taken into account only for new connections.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_min_worker_threads">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_min_worker_threads">
<code class="literal">
mysqlx_min_worker_threads
</code>
</a>
</p>
<a class="indexterm" name="idm46045125310464">
</a>
<a class="indexterm" name="idm46045125309360">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_min_worker_threads">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-min-worker-threads=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_min_worker_threads">
mysqlx_min_worker_threads
</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">
2
</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">
100
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The minimum number of worker threads used by X Plugin for
handling client requests.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_port">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port">
<code class="literal">
mysqlx_port
</code>
</a>
</p>
<a class="indexterm" name="idm46045125280000">
</a>
<a class="indexterm" name="idm46045125278912">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_port">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-port=port_num
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port">
mysqlx_port
</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">
33060
</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">
65535
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The network port on which X Plugin listens for TCP/IP
connections. This is the X Plugin equivalent of
<a class="link" href="server-system-variables.html#sysvar_port">
<code class="literal">
port
</code>
</a>
; see that variable
description for more information.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_port_open_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port_open_timeout">
<code class="literal">
mysqlx_port_open_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045125248176">
</a>
<a class="indexterm" name="idm46045125247072">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_port_open_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-port-open-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port_open_timeout">
mysqlx_port_open_timeout
</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">
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">
120
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The number of seconds X Plugin waits for a TCP/IP port to
become free.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_read_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_read_timeout">
<code class="literal">
mysqlx_read_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045125215568">
</a>
<a class="indexterm" name="idm46045125214528">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_read_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-read-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_read_timeout">
mysqlx_read_timeout
</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>
Integer
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
30
</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">
2147483
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The number of seconds that X Plugin waits for blocking read
operations to complete. After this time, if the read
operation is not successful, X Plugin closes the connection
and returns a warning notice with the error code
<span class="errorcode">
ER_IO_READ_ERROR
</span>
to the client
application.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_socket">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_socket">
<code class="literal">
mysqlx_socket
</code>
</a>
</p>
<a class="indexterm" name="idm46045125182160">
</a>
<a class="indexterm" name="idm46045125181072">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_socket">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-socket=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_socket">
mysqlx_socket
</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>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
/tmp/mysqlx.sock
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The path to a Unix socket file which X Plugin uses for
connections. This setting is only used by MySQL Server when
running on Unix operating systems. Clients can use this
socket to connect to MySQL Server using X Plugin.
</p>
<p>
The default
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_socket">
<code class="literal">
mysqlx_socket
</code>
</a>
path and file name is based on the default path and file
name for the main socket file for MySQL Server, with the
addition of an
<code class="literal">
x
</code>
appended to the file
name. The default path and file name for the main socket
file is
<code class="literal">
/tmp/mysql.sock
</code>
, therefore the
default path and file name for the X Plugin socket file is
<code class="literal">
/tmp/mysqlx.sock
</code>
.
</p>
<p>
If you specify an alternative path and file name for the
main socket file at server startup using the
<a class="link" href="server-system-variables.html#sysvar_socket">
<code class="literal">
socket
</code>
</a>
system variable,
this does not affect the default for the X Plugin socket
file. In this situation, if you want to store both sockets
at a single path, you must set the
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_socket">
<code class="literal">
mysqlx_socket
</code>
</a>
system
variable as well. For example in a configuration file:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa84504865"><div class="copy-help left">Press ⌘+C to 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">socket</span><span class="token attr-value"><span class="token punctuation">=</span>/home/sockets/mysqld/mysql.sock</span>
<span class="token constant">mysqlx_socket</span><span class="token attr-value"><span class="token punctuation">=</span>/home/sockets/xplugin/xplugin.sock</span></code></pre>
</div>
<p>
If you change the default path and file name for the main
socket file at compile time using the
<a class="link" href="source-configuration-options.html#option_cmake_mysql_unix_addr">
<code class="option">
MYSQL_UNIX_ADDR
</code>
</a>
compile
option, this does affect the default for the X Plugin
socket file, which is formed by appending an
<code class="literal">
x
</code>
to the
<a class="link" href="source-configuration-options.html#option_cmake_mysql_unix_addr">
<code class="option">
MYSQL_UNIX_ADDR
</code>
</a>
file name. If
you want to set a different default for the X Plugin socket
file at compile time, use the
<a class="link" href="source-configuration-options.html#option_cmake_mysqlx_unix_addr">
<code class="option">
MYSQLX_UNIX_ADDR
</code>
</a>
compile
option.
</p>
<p>
The
<code class="literal">
MYSQLX_UNIX_PORT
</code>
environment variable
can also be used to set a default for the X Plugin socket
file at server startup (see
<a class="xref" href="environment-variables.html" title="6.9 Environment Variables">
Section 6.9, “Environment Variables”
</a>
). If you set this
environment variable, it overrides the compiled
<a class="link" href="source-configuration-options.html#option_cmake_mysqlx_unix_addr">
<code class="option">
MYSQLX_UNIX_ADDR
</code>
</a>
value, but is
overridden by the
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_socket">
<code class="literal">
mysqlx_socket
</code>
</a>
value.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_ca">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_ca">
<code class="literal">
mysqlx_ssl_ca
</code>
</a>
</p>
<a class="indexterm" name="idm46045125139200">
</a>
<a class="indexterm" name="idm46045125138112">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_ca">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-ca=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_ca">
mysqlx_ssl_ca
</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>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_ca">
<code class="literal">
mysqlx_ssl_ca
</code>
</a>
system
variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_ca">
<code class="literal">
ssl_ca
</code>
</a>
,
except that it applies to X Plugin rather than the MySQL
Server main connection interface. For information about
configuring encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_capath">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_capath">
<code class="literal">
mysqlx_ssl_capath
</code>
</a>
</p>
<a class="indexterm" name="idm46045125110176">
</a>
<a class="indexterm" name="idm46045125109136">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_capath">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-capath=dir_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_capath">
mysqlx_ssl_capath
</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>
Directory name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_capath">
<code class="literal">
mysqlx_ssl_capath
</code>
</a>
system variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_capath">
<code class="literal">
ssl_capath
</code>
</a>
, except that it
applies to X Plugin rather than the MySQL Server main
connection interface. For information about configuring
encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_cert">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_cert">
<code class="literal">
mysqlx_ssl_cert
</code>
</a>
</p>
<a class="indexterm" name="idm46045125081232">
</a>
<a class="indexterm" name="idm46045125080144">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_cert">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-cert=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_cert">
mysqlx_ssl_cert
</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>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_cert">
<code class="literal">
mysqlx_ssl_cert
</code>
</a>
system
variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_cert">
<code class="literal">
ssl_cert
</code>
</a>
,
except that it applies to X Plugin rather than the MySQL
Server main connection interface. For information about
configuring encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_cipher">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_cipher">
<code class="literal">
mysqlx_ssl_cipher
</code>
</a>
</p>
<a class="indexterm" name="idm46045125052208">
</a>
<a class="indexterm" name="idm46045125051168">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_cipher">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-cipher=name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_cipher">
mysqlx_ssl_cipher
</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>
String
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_cipher">
<code class="literal">
mysqlx_ssl_cipher
</code>
</a>
system variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_cipher">
<code class="literal">
ssl_cipher
</code>
</a>
, except that it
applies to X Plugin rather than the MySQL Server main
connection interface. For information about configuring
encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_crl">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_crl">
<code class="literal">
mysqlx_ssl_crl
</code>
</a>
</p>
<a class="indexterm" name="idm46045125023264">
</a>
<a class="indexterm" name="idm46045125022176">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_crl">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-crl=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_crl">
mysqlx_ssl_crl
</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>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_crl">
<code class="literal">
mysqlx_ssl_crl
</code>
</a>
system
variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_crl">
<code class="literal">
ssl_crl
</code>
</a>
,
except that it applies to X Plugin rather than the MySQL
Server main connection interface. For information about
configuring encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_crlpath">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_crlpath">
<code class="literal">
mysqlx_ssl_crlpath
</code>
</a>
</p>
<a class="indexterm" name="idm46045124994304">
</a>
<a class="indexterm" name="idm46045124993264">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_crlpath">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-crlpath=dir_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_crlpath">
mysqlx_ssl_crlpath
</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>
Directory name
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_crlpath">
<code class="literal">
mysqlx_ssl_crlpath
</code>
</a>
system variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_crlpath">
<code class="literal">
ssl_crlpath
</code>
</a>
, except that it
applies to X Plugin rather than the MySQL Server main
connection interface. For information about configuring
encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_ssl_key">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_key">
<code class="literal">
mysqlx_ssl_key
</code>
</a>
</p>
<a class="indexterm" name="idm46045124965424">
</a>
<a class="indexterm" name="idm46045124964336">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_ssl_key">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-ssl-key=file_name
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_key">
mysqlx_ssl_key
</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>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
NULL
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_ssl_key">
<code class="literal">
mysqlx_ssl_key
</code>
</a>
system
variable is like
<a class="link" href="server-system-variables.html#sysvar_ssl_key">
<code class="literal">
ssl_key
</code>
</a>
,
except that it applies to X Plugin rather than the MySQL
Server main connection interface. For information about
configuring encryption support for X Plugin, see
<a class="xref" href="x-plugin-encrypted-connections.html" title="22.5.3 Using Encrypted Connections with X Plugin">
Section 22.5.3, “Using Encrypted Connections with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_wait_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_wait_timeout">
<code class="literal">
mysqlx_wait_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045124936400">
</a>
<a class="indexterm" name="idm46045124935360">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_wait_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-wait-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_wait_timeout">
mysqlx_wait_timeout
</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>
Integer
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
28800
</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">
2147483
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The number of seconds that X Plugin waits for activity on a
connection. After this time, if the read operation is not
successful, X Plugin closes the connection. If the client
is noninteractive, the initial value of the session variable
is copied from the global
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_wait_timeout">
<code class="literal">
mysqlx_wait_timeout
</code>
</a>
variable. For interactive clients, the initial value is
copied from the session
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_interactive_timeout">
<code class="literal">
mysqlx_interactive_timeout
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_write_timeout">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_write_timeout">
<code class="literal">
mysqlx_write_timeout
</code>
</a>
</p>
<a class="indexterm" name="idm46045124900976">
</a>
<a class="indexterm" name="idm46045124899936">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_write_timeout">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx-write-timeout=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_write_timeout">
mysqlx_write_timeout
</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>
Integer
</td>
</tr>
<tr>
<th>
Default Value
</th>
<td>
<code class="literal">
60
</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">
2147483
</code>
</td>
</tr>
<tr>
<th>
Unit
</th>
<td>
seconds
</td>
</tr>
</tbody>
</table>
</div>
<p>
The number of seconds that X Plugin waits for blocking
write operations to complete. After this time, if the write
operation is not successful, X Plugin closes the
connection.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_zstd_default_compression_level">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_zstd_default_compression_level">
<code class="literal">
mysqlx_zstd_default_compression_level
</code>
</a>
</p>
<a class="indexterm" name="idm46045124868208">
</a>
<a class="indexterm" name="idm46045124867168">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_zstd_default_compression_level">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx_zstd_default_compression_level=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_zstd_default_compression_level">
mysqlx_zstd_default_compression_level
</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">
3
</code>
</td>
</tr>
<tr>
<th>
Minimum Value
</th>
<td>
<code class="literal">
-131072
</code>
</td>
</tr>
<tr>
<th>
Maximum Value
</th>
<td>
<code class="literal">
22
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The default compression level that the server uses for the
zstd algorithm on X Protocol connections. For versions of
the zstd library from 1.4.0, you can set positive values
from 1 to 22 (the highest compression effort), or negative
values which represent progressively lower effort. A value
of 0 is converted to a value of 1. For earlier versions of
the zstd library, you can only specify the value 3. This
level is used if the client does not request a compression
level during capability negotiation. If you do not specify
this system variable, the server uses level 3 as the
default. For more information, see
<a class="xref" href="x-plugin-connection-compression.html" title="22.5.5 Connection Compression with X Plugin">
Section 22.5.5, “Connection Compression with X Plugin”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_mysqlx_zstd_max_client_compression_level">
</a>
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_zstd_max_client_compression_level">
<code class="literal">
mysqlx_zstd_max_client_compression_level
</code>
</a>
</p>
<a class="indexterm" name="idm46045124835056">
</a>
<a class="indexterm" name="idm46045124833936">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for mysqlx_zstd_max_client_compression_level">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--mysqlx_zstd_max_client_compression_level=#
</code>
</td>
</tr>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_zstd_max_client_compression_level">
mysqlx_zstd_max_client_compression_level
</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">
11
</code>
</td>
</tr>
<tr>
<th>
Minimum Value
</th>
<td>
<code class="literal">
-131072
</code>
</td>
</tr>
<tr>
<th>
Maximum Value
</th>
<td>
<code class="literal">
22
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The maximum compression level that the server permits for
the zstd algorithm on X Protocol connections. The range is
the same as for the default compression level for this
algorithm. If the client requests a higher compression level
than this, the server uses the level you set here. If you do
not specify this system variable, the server sets a maximum
compression level of 11.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/innodb-online-ddl-performance.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="innodb-online-ddl-performance">
</a>
17.12.2 Online DDL Performance and Concurrency
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045159629648">
</a>
<p>
Online DDL improves several aspects of MySQL operation:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Applications that access the table are more responsive because
queries and DML operations on the table can proceed while the
DDL operation is in progress. Reduced locking and waiting for
MySQL server resources leads to greater scalability, even for
operations that are not involved in the DDL operation.
</p>
</li>
<li class="listitem">
<p>
Instant 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>
<li class="listitem">
<p>
Online operations avoid the disk I/O and CPU cycles associated
with the table-copy method, which minimizes overall load on
the database. Minimizing load helps maintain good performance
and high throughput during the DDL operation.
</p>
</li>
<li class="listitem">
<p>
Online operations read less data into the buffer pool than
table-copy operations, which reduces purging of frequently
accessed data from memory. Purging of frequently accessed data
can cause a temporary performance dip after a DDL operation.
</p>
</li>
</ul>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="innodb-online-ddl-locking-options">
</a>
The LOCK clause
</h4>
</div>
</div>
</div>
<p>
By default, MySQL uses as little locking as possible during a
DDL operation. The
<code class="literal">
LOCK
</code>
clause can be
specified for in-place operations and some copy operations to
enforce more restrictive locking, if required. If the
<code class="literal">
LOCK
</code>
clause specifies a less restrictive
level of locking than is permitted for a particular DDL
operation, the statement fails with an error.
<code class="literal">
LOCK
</code>
clauses are described below, in order of
least to most restrictive:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
LOCK=NONE
</code>
:
</p>
<p>
Permits concurrent queries and DML.
</p>
<p>
For example, use this clause for tables involving customer
signups or purchases, to avoid making the tables unavailable
during lengthy DDL operations.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
LOCK=SHARED
</code>
:
</p>
<p>
Permits concurrent queries but blocks DML.
</p>
<p>
For example, use this clause on data warehouse tables, where
you can delay data load operations until the DDL operation
is finished, but queries cannot be delayed for long periods.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
LOCK=DEFAULT
</code>
:
</p>
<p>
Permits as much concurrency as possible (concurrent queries,
DML, or both). Omitting the
<code class="literal">
LOCK
</code>
clause
is the same as specifying
<code class="literal">
LOCK=DEFAULT
</code>
.
</p>
<p>
Use this clause when you do not expect the default locking
level of the DDL statement to cause any availability
problems for the table.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
LOCK=EXCLUSIVE
</code>
:
</p>
<p>
Blocks concurrent queries and DML.
</p>
<p>
Use this clause if the primary concern is finishing the DDL
operation in the shortest amount of time possible, and
concurrent query and DML access is not necessary. You might
also use this clause if the server is supposed to be idle,
to avoid unexpected table accesses.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="innodb-online-ddl-metadata-locks">
</a>
Online DDL and Metadata Locks
</h4>
</div>
</div>
</div>
<p>
Online DDL operations can be viewed as having three phases:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<span class="emphasis">
<em>
Phase 1: Initialization
</em>
</span>
</p>
<p>
In the initialization phase, the server determines how much
concurrency is permitted during the operation, taking into
account storage engine capabilities, operations specified in
the statement, and user-specified
<code class="literal">
ALGORITHM
</code>
and
<code class="literal">
LOCK
</code>
options. During this phase, a shared upgradeable metadata
lock is taken to protect the current table definition.
</p>
</li>
<li class="listitem">
<p>
<span class="emphasis">
<em>
Phase 2: Execution
</em>
</span>
</p>
<p>
In this phase, the statement is prepared and executed.
Whether the metadata lock is upgraded to exclusive depends
on the factors assessed in the initialization phase. If an
exclusive metadata lock is required, it is only taken
briefly during statement preparation.
</p>
</li>
<li class="listitem">
<p>
<span class="emphasis">
<em>
Phase 3: Commit Table Definition
</em>
</span>
</p>
<p>
In the commit table definition phase, the metadata lock is
upgraded to exclusive to evict the old table definition and
commit the new one. Once granted, the duration of the
exclusive metadata lock is brief.
</p>
</li>
</ul>
</div>
<p>
Due to the exclusive metadata lock requirements outlined above,
an online DDL operation may have to wait for concurrent
transactions that hold metadata locks on the table to commit or
rollback. Transactions started before or during the DDL
operation can hold metadata locks on the table being altered. In
the case of a long running or inactive transaction, an online
DDL operation can time out waiting for an exclusive metadata
lock. Additionally, a pending exclusive metadata lock requested
by an online DDL operation blocks subsequent transactions on the
table.
</p>
<p>
The following example demonstrates an online DDL operation
waiting for an exclusive metadata lock, and how a pending
metadata lock blocks subsequent transactions on the table.
</p>
<p>
Session 1:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46055172"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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 keyword">ENGINE</span><span class="token operator">=</span>InnoDB<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">START</span> <span class="token keyword">TRANSACTION</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t1<span class="token punctuation">;</span></code></pre>
</div>
<p>
The session 1
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement
takes a shared metadata lock on table t1.
</p>
<p>
Session 2:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa21226582"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> t1 <span class="token keyword">ADD</span> <span class="token keyword">COLUMN</span> x <span class="token datatype">INT</span><span class="token punctuation">,</span> <span class="token keyword">ALGORITHM</span><span class="token operator">=</span><span class="token keyword">INPLACE</span><span class="token punctuation">,</span> <span class="token keyword">LOCK</span><span class="token operator">=</span><span class="token keyword">NONE</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The online DDL operation in session 2, which requires an
exclusive metadata lock on table t1 to commit table definition
changes, must wait for the session 1 transaction to commit or
roll back.
</p>
<p>
Session 3:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa38507094"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t1<span class="token punctuation">;</span></code></pre>
</div>
<p>
The
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement issued in
session 3 is blocked waiting for the exclusive metadata lock
requested by the
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
operation in session 2 to be granted.
</p>
<p>
You can use
<a class="link" href="show-processlist.html" title="15.7.7.31 SHOW PROCESSLIST Statement">
<code class="literal">
SHOW FULL
PROCESSLIST
</code>
</a>
to determine if transactions are waiting
for a metadata lock.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17736453"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">FULL</span> <span class="token keyword">PROCESSLIST</span>\G
<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> 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> 5
User<span class="token punctuation">:</span> root
Host<span class="token punctuation">:</span> localhost
db<span class="token punctuation">:</span> test
Command<span class="token punctuation">:</span> Query
Time<span class="token punctuation">:</span> 44
State<span class="token punctuation">:</span> Waiting for table metadata lock
Info<span class="token punctuation">:</span> ALTER TABLE t1 ADD COLUMN x INT, ALGORITHM=INPLACE, LOCK=NONE
...
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 4. 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> 7
User<span class="token punctuation">:</span> root
Host<span class="token punctuation">:</span> localhost
db<span class="token punctuation">:</span> test
Command<span class="token punctuation">:</span> Query
Time<span class="token punctuation">:</span> 5
State<span class="token punctuation">:</span> Waiting for table metadata lock
Info<span class="token punctuation">:</span> SELECT <span class="token punctuation">*</span> FROM t1
</span><span class="token output">4 rows in set (0.00 sec)</span></code></pre>
</div>
<p>
Metadata lock information is also exposed through the
Performance Schema
<a class="link" href="performance-schema-metadata-locks-table.html" title="29.12.13.3 The metadata_locks Table">
<code class="literal">
metadata_locks
</code>
</a>
table, which provides information about metadata lock
dependencies between sessions, the metadata lock a session is
waiting for, and the session that currently holds the metadata
lock. For more information, see
<a class="xref" href="performance-schema-metadata-locks-table.html" title="29.12.13.3 The metadata_locks Table">
Section 29.12.13.3, “The metadata_locks Table”
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="innodb-online-ddl-performance-comparison">
</a>
Online DDL Performance
</h4>
</div>
</div>
</div>
<p>
The performance of a DDL operation is largely determined by
whether the operation is performed instantly, in place, and
whether it rebuilds the table.
</p>
<p>
To assess the relative performance of a DDL operation, you can
compare results using
<code class="literal">
ALGORITHM=INSTANT
</code>
,
<code class="literal">
ALGORITHM=INPLACE
</code>
, and
<code class="literal">
ALGORITHM=COPY
</code>
. A statement can also be run
with
<a class="link" href="server-system-variables.html#sysvar_old_alter_table">
<code class="literal">
old_alter_table
</code>
</a>
enabled to
force the use of
<code class="literal">
ALGORITHM=COPY
</code>
.
</p>
<p>
For DDL operations that modify table data, you can determine
whether a DDL operation performs changes in place or performs a
table copy by looking at the
<span class="quote">
“
<span class="quote">
rows affected
</span>
”
</span>
value
displayed after the command finishes. For example:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Changing the default value of a column (fast, does not
affect the table data):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa79954440"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token output">Query OK, 0 rows affected (0.07 sec)</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
Adding an index (takes time, but
<code class="literal">
0 rows
affected
</code>
shows that the table is not copied):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa85596302"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token output">Query OK, 0 rows affected (21.42 sec)</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
Changing the data type of a column (takes substantial time
and requires rebuilding all the rows of the table):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa77001594"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token output">Query OK, 1671168 rows affected (1 min 35.54 sec)</span></code></pre>
</div>
</li>
</ul>
</div>
<p>
Before running a DDL operation on a large table, check whether
the operation is fast or slow as follows:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
Clone the table structure.
</p>
</li>
<li class="listitem">
<p>
Populate the cloned table with a small amount of data.
</p>
</li>
<li class="listitem">
<p>
Run the DDL operation on the cloned table.
</p>
</li>
<li class="listitem">
<p>
Check whether the
<span class="quote">
“
<span class="quote">
rows affected
</span>
”
</span>
value is zero
or not. A nonzero value means the operation copies table
data, which might require special planning. For example, you
might do the DDL operation during a period of scheduled
downtime, or on each replica server one at a time.
</p>
</li>
</ol>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
For a greater understanding of the MySQL processing associated
with a DDL operation, examine Performance Schema and
<code class="literal">
INFORMATION_SCHEMA
</code>
tables related to
<code class="literal">
InnoDB
</code>
before and after DDL operations to
see the number of physical reads, writes, memory allocations,
and so on.
</p>
<p>
Performance Schema stage events can be used to monitor
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
progress. See
<a class="xref" href="monitor-alter-table-performance-schema.html" title="17.16.1 Monitoring ALTER TABLE Progress for InnoDB Tables Using Performance Schema">
Section 17.16.1, “Monitoring ALTER TABLE Progress for InnoDB Tables Using Performance
Schema”
</a>
.
</p>
</div>
<p>
Because there is some processing work involved with recording
the changes made by concurrent DML operations, then applying
those changes at the end, an online DDL operation could take
longer overall than the table-copy mechanism that blocks table
access from other sessions. The reduction in raw performance is
balanced against better responsiveness for applications that use
the table. When evaluating the techniques for changing table
structure, consider end-user perception of performance, based on
factors such as load times for web pages.
</p>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/proxy-users.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="proxy-users">
</a>
8.2.19 Proxy Users
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045247869792">
</a>
<p>
The MySQL server authenticates client connections using
authentication plugins. The plugin that authenticates a given
connection may request that the connecting (external) user be
treated as a different user for privilege-checking purposes. This
enables the external user to be a proxy for the second user; that
is, to assume the privileges of the second user:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The external user is a
<span class="quote">
“
<span class="quote">
proxy user
</span>
”
</span>
(a user who
can impersonate or become known as another user).
</p>
</li>
<li class="listitem">
<p>
The second user is a
<span class="quote">
“
<span class="quote">
proxied user
</span>
”
</span>
(a user whose
identity and privileges can be assumed by a proxy user).
</p>
</li>
</ul>
</div>
<p>
This section describes how the proxy user capability works. For
general information about authentication plugins, see
<a class="xref" href="pluggable-authentication.html" title="8.2.17 Pluggable Authentication">
Section 8.2.17, “Pluggable Authentication”
</a>
. For information about
specific plugins, see
<a class="xref" href="authentication-plugins.html" title="8.4.1 Authentication Plugins">
Section 8.4.1, “Authentication Plugins”
</a>
.
For information about writing authentication plugins that support
proxy users, see
<a class="ulink" href="/doc/extending-mysql/8.4/en/writing-authentication-plugins-proxy-users.html" target="_top">
Implementing Proxy User Support in Authentication Plugins
</a>
.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#proxy-users-support-requirements" title="Requirements for Proxy User Support">
Requirements for Proxy User Support
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#proxy-users-example" title="Simple Proxy User Example">
Simple Proxy User Example
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#preventing-proxied-account-direct-login" title="Preventing Direct Login to Proxied Accounts">
Preventing Direct Login to Proxied Accounts
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#proxy-users-granting-proxy-privilege" title="Granting and Revoking the PROXY Privilege">
Granting and Revoking the PROXY Privilege
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#default-proxy-users" title="Default Proxy Users">
Default Proxy Users
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#proxy-users-conflicts" title="Default Proxy User and Anonymous User Conflicts">
Default Proxy User and Anonymous User Conflicts
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#proxy-users-server-user-mapping" title="Server Support for Proxy User Mapping">
Server Support for Proxy User Mapping
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="proxy-users.html#proxy-users-system-variables" title="Proxy User System Variables">
Proxy User System Variables
</a>
</p>
</li>
</ul>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
One administrative benefit to be gained by proxying is that the
DBA can set up a single account with a set of privileges and
then enable multiple proxy users to have those privileges
without having to assign the privileges individually to each of
those users. As an alternative to proxy users, DBAs may find
that roles provide a suitable way to map users onto specific
sets of named privileges. Each user can be granted a given
single role to, in effect, be granted the appropriate set of
privileges. See
<a class="xref" href="roles.html" title="8.2.10 Using Roles">
Section 8.2.10, “Using Roles”
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="proxy-users-support-requirements">
</a>
Requirements for Proxy User Support
</h4>
</div>
</div>
</div>
<p>
For proxying to occur for a given authentication plugin, these
conditions must be satisfied:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Proxying must be supported, either by the plugin itself, or
by the MySQL server on behalf of the plugin. In the latter
case, server support may need to be enabled explicitly; see
<a class="xref" href="proxy-users.html#proxy-users-server-user-mapping" title="Server Support for Proxy User Mapping">
Server Support for Proxy User Mapping
</a>
.
</p>
</li>
<li class="listitem">
<p>
The account for the external proxy user must be set up to be
authenticated by the plugin. Use the
<a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
<code class="literal">
CREATE USER
</code>
</a>
statement to
associate an account with an authentication plugin, or
<a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
<code class="literal">
ALTER USER
</code>
</a>
to change its
plugin.
</p>
</li>
<li class="listitem">
<p>
The account for the proxied user must exist and be granted
the privileges to be assumed by the proxy user. Use 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="grant.html" title="15.7.1.6 GRANT Statement">
<code class="literal">
GRANT
</code>
</a>
statements for this.
</p>
</li>
<li class="listitem">
<p>
Normally, the proxied user is configured so that it can be
used only in proxying scenarios and not for direct logins.
</p>
</li>
<li class="listitem">
<p>
The proxy user account must have the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege for the
proxied account. Use the
<a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
<code class="literal">
GRANT
</code>
</a>
statement for this.
</p>
</li>
<li class="listitem">
<p>
For a client connecting to the proxy account to be treated
as a proxy user, the authentication plugin must return a
user name different from the client user name, to indicate
the user name of the proxied account that defines the
privileges to be assumed by the proxy user.
</p>
<p>
Alternatively, for plugins that are provided proxy mapping
by the server, the proxied user is determined from the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege held by the
proxy user.
</p>
</li>
</ul>
</div>
<p>
The proxy mechanism permits mapping only the external client
user name to the proxied user name. There is no provision for
mapping host names:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
When a client connects to the server, the server determines
the proper account based on the user name passed by the
client program and the host from which the client connects.
</p>
</li>
<li class="listitem">
<p>
If that account is a proxy account, the server attempts to
determine the appropriate proxied account by finding a match
for a proxied account using the user name returned by the
authentication plugin and the host name of the proxy
account. The host name in the proxied account is ignored.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="proxy-users-example">
</a>
Simple Proxy User Example
</h4>
</div>
</div>
</div>
<p>
Consider the following account definitions:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72511099"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- create proxy account</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'employee_ext'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> my_auth_plugin
<span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">my_auth_string</em>'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- create proxied account and grant its privileges;</span>
<span class="token comment" spellcheck="true">-- use mysql_no_login plugin to prevent direct login</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'employee'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_no_login<span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">ALL</span>
<span class="token keyword">ON</span> employees<span class="token punctuation">.</span><span class="token operator">*</span>
<span class="token keyword">TO</span> <span class="token string">'employee'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- grant to proxy account the</span>
<span class="token comment" spellcheck="true">-- PROXY privilege for proxied account</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span>
<span class="token keyword">ON</span> <span class="token string">'employee'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">TO</span> <span class="token string">'employee_ext'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
When a client connects as
<code class="literal">
employee_ext
</code>
from
the local host, MySQL uses the plugin named
<code class="literal">
my_auth_plugin
</code>
to perform authentication.
Suppose that
<code class="literal">
my_auth_plugin
</code>
returns a user
name of
<code class="literal">
employee
</code>
to the server, based on the
content of
<code class="literal">
'
<em class="replaceable">
<code>
my_auth_string
</code>
</em>
'
</code>
and perhaps by consulting some external authentication system.
The name
<code class="literal">
employee
</code>
differs from
<code class="literal">
employee_ext
</code>
, so returning
<code class="literal">
employee
</code>
serves as a request to the server to
treat the
<code class="literal">
employee_ext
</code>
external user, for
purposes of privilege checking, as the
<code class="literal">
employee
</code>
local user.
</p>
<p>
In this case,
<code class="literal">
employee_ext
</code>
is the proxy user
and
<code class="literal">
employee
</code>
is the proxied user.
</p>
<p>
The server verifies that proxy authentication for
<code class="literal">
employee
</code>
is possible for the
<code class="literal">
employee_ext
</code>
user by checking whether
<code class="literal">
employee_ext
</code>
(the proxy user) has the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege for
<code class="literal">
employee
</code>
(the proxied user). If this
privilege has not been granted, an error occurs. Otherwise,
<code class="literal">
employee_ext
</code>
assumes the privileges of
<code class="literal">
employee
</code>
. The server checks statements
executed during the client session by
<code class="literal">
employee_ext
</code>
against the privileges granted
to
<code class="literal">
employee
</code>
. In this case,
<code class="literal">
employee_ext
</code>
can access tables in the
<code class="literal">
employees
</code>
database.
</p>
<p>
The proxied account,
<code class="literal">
employee
</code>
, uses the
<code class="literal">
mysql_no_login
</code>
authentication plugin to
prevent clients from using the account to log in directly. (This
assumes that the plugin is installed. For instructions, see
<a class="xref" href="no-login-pluggable-authentication.html" title="8.4.1.9 No-Login Pluggable Authentication">
Section 8.4.1.9, “No-Login Pluggable Authentication”
</a>
.) For
alternative methods of protecting proxied accounts against
direct use, see
<a class="xref" href="proxy-users.html#preventing-proxied-account-direct-login" title="Preventing Direct Login to Proxied Accounts">
Preventing Direct Login to Proxied Accounts
</a>
.
</p>
<p>
When proxying occurs, the
<a class="link" href="information-functions.html#function_user">
<code class="literal">
USER()
</code>
</a>
and
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER()
</code>
</a>
functions can
be used to see the difference between the connecting user (the
proxy user) and the account whose privileges apply during the
current session (the proxied user). For the example just
described, those functions return these values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38325963"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">CURRENT_USER</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>
<span class="token output"><span class="token punctuation">|</span> USER() <span class="token punctuation">|</span> CURRENT_USER() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> employee_ext@localhost <span class="token punctuation">|</span> employee@localhost <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
</div>
<p>
In the
<a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
<code class="literal">
CREATE USER
</code>
</a>
statement that
creates the proxy user account, the
<code class="literal">
IDENTIFIED
WITH
</code>
clause that names the proxy-supporting
authentication plugin is optionally followed by an
<code class="literal">
AS
'
<em class="replaceable">
<code>
auth_string
</code>
</em>
'
</code>
clause
specifying a string that the server passes to the plugin when
the user connects. If present, the string provides information
that helps the plugin determine how to map the proxy (external)
client user name to a proxied user name. It is up to each plugin
whether it requires the
<code class="literal">
AS
</code>
clause. If so, the
format of the authentication string depends on how the plugin
intends to use it. Consult the documentation for a given plugin
for information about the authentication string values it
accepts.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="preventing-proxied-account-direct-login">
</a>
Preventing Direct Login to Proxied Accounts
</h4>
</div>
</div>
</div>
<p>
Proxied accounts generally are intended to be used only by means
of proxy accounts. That is, clients connect using a proxy
account, then are mapped onto and assume the privileges of the
appropriate proxied user.
</p>
<p>
There are multiple ways to ensure that a proxied account cannot
be used directly:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Associate the account with the
<code class="literal">
mysql_no_login
</code>
authentication plugin. In
this case, the account cannot be used for direct logins
under any circumstances. This assumes that the plugin is
installed. For instructions, see
<a class="xref" href="no-login-pluggable-authentication.html" title="8.4.1.9 No-Login Pluggable Authentication">
Section 8.4.1.9, “No-Login Pluggable Authentication”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Include the
<code class="literal">
ACCOUNT LOCK
</code>
option when you
create the account. 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>
. With
this method, also include a password so that if the account
is unlocked later, it cannot be accessed with no password.
(If the
<code class="literal">
validate_password
</code>
component is
enabled, creating an account without a password is not
permitted, even if the account is locked. 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>
.)
</p>
</li>
<li class="listitem">
<p>
Create the account with a password but do not tell anyone
else the password. If you do not let anyone know the
password for the account, clients cannot use it to connect
directly to the MySQL server.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="proxy-users-granting-proxy-privilege">
</a>
Granting and Revoking the PROXY Privilege
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045247782016">
</a>
<p>
The
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege is needed to
enable an external user to connect as and have the privileges of
another user. To grant this privilege, use the
<a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
<code class="literal">
GRANT
</code>
</a>
statement. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa73216205"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">GRANT</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> <span class="token string">'<em class="replaceable">proxied_user</em>'</span> <span class="token keyword">TO</span> <span class="token string">'<em class="replaceable">proxy_user</em>'</span><span class="token punctuation">;</span></code></pre>
</div>
<a class="indexterm" name="idm46045247775744">
</a>
<a class="indexterm" name="idm46045247774256">
</a>
<p>
The statement creates a row in the
<code class="literal">
mysql.proxies_priv
</code>
grant table.
</p>
<p>
At connect time,
<em class="replaceable">
<code>
proxy_user
</code>
</em>
must
represent a valid externally authenticated MySQL user, and
<em class="replaceable">
<code>
proxied_user
</code>
</em>
must represent a valid
locally authenticated user. Otherwise, the connection attempt
fails.
</p>
<p>
The corresponding
<a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
<code class="literal">
REVOKE
</code>
</a>
syntax
is:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa25645216"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">REVOKE</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> <span class="token string">'<em class="replaceable">proxied_user</em>'</span> <span class="token keyword">FROM</span> <span class="token string">'<em class="replaceable">proxy_user</em>'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
MySQL
<a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
<code class="literal">
GRANT
</code>
</a>
and
<a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
<code class="literal">
REVOKE
</code>
</a>
syntax extensions work as
usual. Examples:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36933335"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- grant PROXY to multiple accounts</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> <span class="token string">'a'</span> <span class="token keyword">TO</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 string">'d'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- revoke PROXY from multiple accounts</span>
<span class="token keyword">REVOKE</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> <span class="token string">'a'</span> <span class="token keyword">FROM</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 string">'d'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- grant PROXY to an account and enable the account to grant</span>
<span class="token comment" spellcheck="true">-- PROXY to the proxied account</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> <span class="token string">'a'</span> <span class="token keyword">TO</span> <span class="token string">'d'</span> <span class="token keyword">WITH</span> <span class="token keyword">GRANT</span> <span class="token keyword">OPTION</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- grant PROXY to default proxy account</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> <span class="token string">'a'</span> <span class="token keyword">TO</span> <span class="token string">''</span>@<span class="token string">''</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege can be
granted in these cases:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
By a user that has
<code class="literal">
GRANT PROXY ... WITH GRANT
OPTION
</code>
for
<em class="replaceable">
<code>
proxied_user
</code>
</em>
.
</p>
</li>
<li class="listitem">
<p>
By
<em class="replaceable">
<code>
proxied_user
</code>
</em>
for itself: The
value of
<a class="link" href="information-functions.html#function_user">
<code class="literal">
USER()
</code>
</a>
must exactly
match
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER()
</code>
</a>
and
<em class="replaceable">
<code>
proxied_user
</code>
</em>
, for both the user
name and host name parts of the account name.
</p>
</li>
</ul>
</div>
<p>
The initial
<code class="literal">
root
</code>
account created during MySQL
installation has the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY ... WITH GRANT
OPTION
</code>
</a>
privilege for
<code class="literal">
''@''
</code>
, that
is, for all users and all hosts. This enables
<code class="literal">
root
</code>
to set up proxy users, as well as to
delegate to other accounts the authority to set up proxy users.
For example,
<code class="literal">
root
</code>
can do this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40679365"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">'admin'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">admin_password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span>
<span class="token keyword">ON</span> <span class="token string">''</span>@<span class="token string">''</span>
<span class="token keyword">TO</span> <span class="token string">'admin'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">WITH</span> <span class="token keyword">GRANT</span> <span class="token keyword">OPTION</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Those statements create an
<code class="literal">
admin
</code>
user that
can manage all
<code class="literal">
GRANT PROXY
</code>
mappings. For
example,
<code class="literal">
admin
</code>
can do this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa25997537"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">GRANT</span> <span class="token keyword">PROXY</span> <span class="token keyword">ON</span> sally <span class="token keyword">TO</span> joe<span class="token punctuation">;</span></code></pre>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="default-proxy-users">
</a>
Default Proxy Users
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045247743104">
</a>
<a class="indexterm" name="idm46045247741616">
</a>
<p>
To specify that some or all users should connect using a given
authentication plugin, create a
<span class="quote">
“
<span class="quote">
blank
</span>
”
</span>
MySQL
account with an empty user name and host name
(
<code class="literal">
''@''
</code>
), associate it with that plugin, and
let the plugin return the real authenticated user name (if
different from the blank user). Suppose that there exists a
plugin named
<code class="literal">
ldap_auth
</code>
that implements LDAP
authentication and maps connecting users onto either a developer
or manager account. To set up proxying of users onto these
accounts, use the following statements:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa81906700"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- create default proxy account</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">''</span>@<span class="token string">''</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> ldap_auth
<span class="token keyword">AS</span> <span class="token string">'O=Oracle, OU=MySQL'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- create proxied accounts; use</span>
<span class="token comment" spellcheck="true">-- mysql_no_login plugin to prevent direct login</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'developer'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_no_login<span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'manager'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_no_login<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- grant to default proxy account the</span>
<span class="token comment" spellcheck="true">-- PROXY privilege for proxied accounts</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span>
<span class="token keyword">ON</span> <span class="token string">'manager'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">TO</span> <span class="token string">''</span>@<span class="token string">''</span><span class="token punctuation">;</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span>
<span class="token keyword">ON</span> <span class="token string">'developer'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">TO</span> <span class="token string">''</span>@<span class="token string">''</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Now assume that a client connects as follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa8079512"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysql</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>myuser</span> <span class="token property">--password</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
Enter password<span class="token punctuation">:</span> <em class="replaceable">myuser_password</em></code></pre>
</div>
<p>
The server does not find
<code class="literal">
myuser
</code>
defined as a
MySQL user, but because there is a blank user account
(
<code class="literal">
''@''
</code>
) that matches the client user name and
host name, the server authenticates the client against that
account. The server invokes the
<code class="literal">
ldap_auth
</code>
authentication plugin and passes
<code class="literal">
myuser
</code>
and
<em class="replaceable">
<code>
myuser_password
</code>
</em>
to it as the user
name and password.
</p>
<p>
If the
<code class="literal">
ldap_auth
</code>
plugin finds in the LDAP
directory that
<em class="replaceable">
<code>
myuser_password
</code>
</em>
is not
the correct password for
<code class="literal">
myuser
</code>
,
authentication fails and the server rejects the connection.
</p>
<p>
If the password is correct and
<code class="literal">
ldap_auth
</code>
finds that
<code class="literal">
myuser
</code>
is a developer, it returns
the user name
<code class="literal">
developer
</code>
to the MySQL server,
rather than
<code class="literal">
myuser
</code>
. Returning a user name
different from the client user name of
<code class="literal">
myuser
</code>
signals to the server that it should treat
<code class="literal">
myuser
</code>
as a proxy. The server verifies that
<code class="literal">
''@''
</code>
can authenticate as
<code class="literal">
developer
</code>
(because
<code class="literal">
''@''
</code>
has the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege to do so)
and accepts the connection. The session proceeds with
<code class="literal">
myuser
</code>
having the privileges of the
<code class="literal">
developer
</code>
proxied user. (These privileges
should be set up by the DBA using
<a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
<code class="literal">
GRANT
</code>
</a>
statements, not shown.) The
<a class="link" href="information-functions.html#function_user">
<code class="literal">
USER()
</code>
</a>
and
<a class="link" href="information-functions.html#function_current-user">
<code class="literal">
CURRENT_USER()
</code>
</a>
functions return
these values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa12649166"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">CURRENT_USER</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>
<span class="token output"><span class="token punctuation">|</span> USER() <span class="token punctuation">|</span> CURRENT_USER() <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> myuser@localhost <span class="token punctuation">|</span> developer@localhost <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
</div>
<p>
If the plugin instead finds in the LDAP directory that
<code class="literal">
myuser
</code>
is a manager, it returns
<code class="literal">
manager
</code>
as the user name and the session
proceeds with
<code class="literal">
myuser
</code>
having the privileges of
the
<code class="literal">
manager
</code>
proxied user.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21098138"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">CURRENT_USER</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>
<span class="token output"><span class="token punctuation">|</span> USER() <span class="token punctuation">|</span> CURRENT_USER() <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> myuser@localhost <span class="token punctuation">|</span> manager@localhost <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
</div>
<p>
For simplicity, external authentication cannot be multilevel:
Neither the credentials for
<code class="literal">
developer
</code>
nor
those for
<code class="literal">
manager
</code>
are taken into account in
the preceding example. However, they are still used if a client
tries to connect and authenticate directly as the
<code class="literal">
developer
</code>
or
<code class="literal">
manager
</code>
account, which is why those proxied accounts should be protected
against direct login (see
<a class="xref" href="proxy-users.html#preventing-proxied-account-direct-login" title="Preventing Direct Login to Proxied Accounts">
Preventing Direct Login to Proxied Accounts
</a>
).
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="proxy-users-conflicts">
</a>
Default Proxy User and Anonymous User Conflicts
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045247700704">
</a>
<p>
If you intend to create a default proxy user, check for other
existing
<span class="quote">
“
<span class="quote">
match any user
</span>
”
</span>
accounts that take
precedence over the default proxy user because they can prevent
that user from working as intended.
</p>
<p>
In the preceding discussion, the default proxy user account has
<code class="literal">
''
</code>
in the host part, which matches any host.
If you set up a default proxy user, take care to also check
whether nonproxy accounts exist with the same user part and
<code class="literal">
'%'
</code>
in the host part, because
<code class="literal">
'%'
</code>
also matches any host, but has precedence
over
<code class="literal">
''
</code>
by the rules that the server uses to
sort account rows internally (see
<a class="xref" href="connection-access.html" title="8.2.6 Access Control, Stage 1: Connection Verification">
Section 8.2.6, “Access Control, Stage 1: Connection Verification”
</a>
).
</p>
<p>
Suppose that a MySQL installation includes these two accounts:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa54187854"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- create default proxy account</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">''</span>@<span class="token string">''</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> some_plugin
<span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">some_auth_string</em>'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- create anonymous account</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">''</span>@<span class="token string">'%'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">anon_user_password</em>'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The first account (
<code class="literal">
''@''
</code>
) is intended as the
default proxy user, used to authenticate connections for users
who do not otherwise match a more-specific account. The second
account (
<code class="literal">
''@'%'
</code>
) is an anonymous-user
account, which might have been created, for example, to enable
users without their own account to connect anonymously.
</p>
<p>
Both accounts have the same user part (
<code class="literal">
''
</code>
),
which matches any user. And each account has a host part that
matches any host. Nevertheless, there is a priority in account
matching for connection attempts because the matching rules sort
a host of
<code class="literal">
'%'
</code>
ahead of
<code class="literal">
''
</code>
.
For accounts that do not match any more-specific account, the
server attempts to authenticate them against
<code class="literal">
''@'%'
</code>
(the anonymous user) rather than
<code class="literal">
''@''
</code>
(the default proxy user). As a result,
the default proxy account is never used.
</p>
<p>
To avoid this problem, use one of the following strategies:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Remove the anonymous account so that it does not conflict
with the default proxy user.
</p>
</li>
<li class="listitem">
<p>
Use a more-specific default proxy user that matches ahead of
the anonymous user. For example, to permit only
<code class="literal">
localhost
</code>
proxy connections, use
<code class="literal">
''@'localhost'
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa5904123"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">''</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> some_plugin
<span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">some_auth_string</em>'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
In addition, modify any
<code class="literal">
GRANT PROXY
</code>
statements to name
<code class="literal">
''@'localhost'
</code>
rather
than
<code class="literal">
''@''
</code>
as the proxy user.
</p>
<p>
Be aware that this strategy prevents anonymous-user
connections from
<code class="literal">
localhost
</code>
.
</p>
</li>
<li class="listitem">
<p>
Use a named default account rather than an anonymous default
account. For an example of this technique, consult the
instructions for using the
<code class="literal">
authentication_windows
</code>
plugin. See
<a class="xref" href="windows-pluggable-authentication.html" title="8.4.1.6 Windows Pluggable Authentication">
Section 8.4.1.6, “Windows Pluggable Authentication”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Create multiple proxy users, one for local connections and
one for
<span class="quote">
“
<span class="quote">
everything else
</span>
”
</span>
(remote connections).
This can be useful particularly when local users should have
different privileges from remote users.
</p>
<p>
Create the proxy users:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa98898047"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- create proxy user for local connections</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">''</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> some_plugin
<span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">some_auth_string</em>'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- create proxy user for remote connections</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">''</span>@<span class="token string">'%'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> some_plugin
<span class="token keyword">AS</span> <span class="token string">'<em class="replaceable">some_auth_string</em>'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Create the proxied users:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa52199561"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- create proxied user for local connections</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'developer'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_no_login<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- create proxied user for remote connections</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'developer'</span>@<span class="token string">'%'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_no_login<span class="token punctuation">;</span></code></pre>
</div>
<p>
Grant to each proxy account the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege for the
corresponding proxied account:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46574725"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">GRANT</span> <span class="token keyword">PROXY</span>
<span class="token keyword">ON</span> <span class="token string">'developer'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">TO</span> <span class="token string">''</span>@<span class="token string">'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> <span class="token string">'developer'</span>@<span class="token string">'%'</span>
<span class="token keyword">TO</span> <span class="token string">''</span>@<span class="token string">'%'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Finally, grant appropriate privileges to the local and
remote proxied users (not shown).
</p>
<p>
Assume that the
<code class="literal">
some_plugin
</code>
/
<code class="literal">
'
<em class="replaceable">
<code>
some_auth_string
</code>
</em>
'
</code>
combination causes
<code class="literal">
some_plugin
</code>
to map the
client user name to
<code class="literal">
developer
</code>
. Local
connections match the
<code class="literal">
''@'localhost'
</code>
proxy user, which maps to the
<code class="literal">
'developer'@'localhost'
</code>
proxied user.
Remote connections match the
<code class="literal">
''@'%'
</code>
proxy
user, which maps to the
<code class="literal">
'developer'@'%'
</code>
proxied user.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="proxy-users-server-user-mapping">
</a>
Server Support for Proxy User Mapping
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045247656368">
</a>
<p>
Some authentication plugins implement proxy user mapping for
themselves (for example, the PAM and Windows authentication
plugins). Other authentication plugins do not support proxy
users by default. Of these, some can request that the MySQL
server itself map proxy users according to granted proxy
privileges:
<code class="literal">
mysql_native_password
</code>
(deprecated),
<code class="literal">
sha256_password
</code>
(deprecated).
If the
<a class="link" href="server-system-variables.html#sysvar_check_proxy_users">
<code class="literal">
check_proxy_users
</code>
</a>
system
variable is enabled, the server performs proxy user mapping for
any authentication plugins that make such a request:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
By default,
<a class="link" href="server-system-variables.html#sysvar_check_proxy_users">
<code class="literal">
check_proxy_users
</code>
</a>
is
disabled, so the server performs no proxy user mapping even
for authentication plugins that request server support for
proxy users.
</p>
<a class="indexterm" name="idm46045247648864">
</a>
<a class="indexterm" name="idm46045247647824">
</a>
</li>
<li class="listitem">
<p>
If
<a class="link" href="server-system-variables.html#sysvar_check_proxy_users">
<code class="literal">
check_proxy_users
</code>
</a>
is
enabled, it may also be necessary to enable a
plugin-specific system variable to take advantage of server
proxy user mapping support:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
For the deprecated
<code class="literal">
mysql_native_password
</code>
plugin, enable
<a class="link" href="server-system-variables.html#sysvar_mysql_native_password_proxy_users">
<code class="literal">
mysql_native_password_proxy_users
</code>
</a>
.
</p>
<a class="indexterm" name="idm46045247641024">
</a>
<a class="indexterm" name="idm46045247639984">
</a>
</li>
<li class="listitem">
<p>
For the deprecated
<code class="literal">
sha256_password
</code>
plugin, enable
<a class="link" href="server-system-variables.html#sysvar_sha256_password_proxy_users">
<code class="literal">
sha256_password_proxy_users
</code>
</a>
.
</p>
<a class="indexterm" name="idm46045247635632">
</a>
<a class="indexterm" name="idm46045247634528">
</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>
For example, to enable all the preceding capabilities, start the
server with these lines in the
<code class="filename">
my.cnf
</code>
file:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa26393327"><div class="copy-help left">Press ⌘+C to 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">check_proxy_users</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span>
<span class="token constant">mysql_native_password_proxy_users</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span>
<span class="token constant">sha256_password_proxy_users</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span></code></pre>
</div>
<p>
Assuming that the relevant system variables have been enabled,
create the proxy user as usual using
<a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
<code class="literal">
CREATE
USER
</code>
</a>
, then grant it the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege to a single other
account to be treated as the proxied user. When the server
receives a successful connection request for the proxy user, it
finds that the user has the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege and uses it to determine the proper proxied user.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99916182"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">-- create proxy account</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'proxy_user'</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>
<span class="token comment" spellcheck="true">-- create proxied account and grant its privileges;</span>
<span class="token comment" spellcheck="true">-- use mysql_no_login plugin to prevent direct login</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'proxied_user'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">IDENTIFIED</span> <span class="token keyword">WITH</span> mysql_no_login<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- grant privileges to proxied account</span>
<span class="token keyword">GRANT</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token keyword">ON</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token keyword">TO</span> <span class="token string">'proxied_user'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">-- grant to proxy account the</span>
<span class="token comment" spellcheck="true">-- PROXY privilege for proxied account</span>
<span class="token keyword">GRANT</span> <span class="token keyword">PROXY</span>
<span class="token keyword">ON</span> <span class="token string">'proxied_user'</span>@<span class="token string">'localhost'</span>
<span class="token keyword">TO</span> <span class="token string">'proxy_user'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
To use the proxy account, connect to the server using its name
and password:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa957534"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysql</span> <span class="token property">-u</span> proxy_user <span class="token property">-p</span>
Enter password<span class="token punctuation">:</span> <span class="token punctuation"></span><em class="replaceable"><span class="token punctuation">(</span>enter proxy_user password here<span class="token punctuation">)</span></em><span class="token punctuation"></span></code></pre>
</div>
<p>
Authentication succeeds, the server finds that
<code class="literal">
proxy_user
</code>
has the
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege for
<code class="literal">
proxied_user
</code>
, and the session proceeds with
<code class="literal">
proxy_user
</code>
having the privileges of
<code class="literal">
proxied_user
</code>
.
</p>
<p>
Proxy user mapping performed by the server is subject to these
restrictions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The server does not proxy to or from an anonymous user, even
if the associated
<a class="link" href="privileges-provided.html#priv_proxy">
<code class="literal">
PROXY
</code>
</a>
privilege is granted.
</p>
</li>
<li class="listitem">
<p>
When a single account has been granted proxy privileges for
more than one proxied account, server proxy user mapping is
nondeterministic. Therefore, granting to a single account
proxy privileges for multiple proxied accounts is
discouraged.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="proxy-users-system-variables">
</a>
Proxy User System Variables
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045247611264">
</a>
<p>
Two system variables help trace the proxy login process:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="server-system-variables.html#sysvar_proxy_user">
<code class="literal">
proxy_user
</code>
</a>
: This value is
<code class="literal">
NULL
</code>
if proxying is not used. Otherwise,
it indicates the proxy user account. For example, if a
client authenticates through the
<code class="literal">
''@''
</code>
proxy account, this variable is set as follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89230921"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token variable">@@proxy_user</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>
<span class="token output"><span class="token punctuation">|</span> @@proxy_user <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>
<span class="token output"><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></code></pre>
</div>
</li>
<li class="listitem">
<p>
<a class="link" href="server-system-variables.html#sysvar_external_user">
<code class="literal">
external_user
</code>
</a>
: Sometimes
the authentication plugin may use an external user to
authenticate to the MySQL server. For example, when using
Windows native authentication, a plugin that authenticates
using the windows API does not need the login ID passed to
it. However, it still uses a Windows user ID to
authenticate. The plugin may return this external user ID
(or the first 512 UTF-8 bytes of it) to the server using the
<code class="literal">
external_user
</code>
read-only session variable.
If the plugin does not set this variable, its value is
<code class="literal">
NULL
</code>
.
</p>
</li>
</ul>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/apis-python.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="apis-python">
</a>
31.10 MySQL Python API
</h2>
</div>
</div>
</div>
<a class="indexterm" name="idm46045060303568">
</a>
<p>
<code class="literal">
MySQLdb
</code>
is a third-party driver that provides
MySQL support for Python, compliant with the Python DB API version
2.0. It can be found at
<a class="ulink" href="http://sourceforge.net/projects/mysql-python/" target="_blank">
http://sourceforge.net/projects/mysql-python/
</a>
.
</p>
<p>
The new MySQL Connector/Python component provides an interface to
the same Python API, and is built into the MySQL Server and
supported by Oracle. See
<a class="ulink" href="/doc/connector-python/en/" target="_top">
MySQL Connector/Python Developer Guide
</a>
for
details on the Connector, as well as coding guidelines for Python
applications and sample Python code.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-keyring-keys-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="performance-schema-keyring-keys-table">
</a>
29.12.18.2 The keyring_keys table
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045069486944">
</a>
<a class="indexterm" name="idm46045069485456">
</a>
<p>
MySQL Server supports a keyring that enables internal server
components and plugins to securely store sensitive information
for later retrieval. See
<a class="xref" href="keyring.html" title="8.4.4 The MySQL Keyring">
Section 8.4.4, “The MySQL Keyring”
</a>
.
</p>
<p>
The
<a class="link" href="performance-schema-keyring-keys-table.html" title="29.12.18.2 The keyring_keys table">
<code class="literal">
keyring_keys
</code>
</a>
table exposes
metadata for keys in the keyring. Key metadata includes key
IDs, key owners, and backend key IDs. The
<a class="link" href="performance-schema-keyring-keys-table.html" title="29.12.18.2 The keyring_keys table">
<code class="literal">
keyring_keys
</code>
</a>
table does
<span class="emphasis">
<em>
not
</em>
</span>
expose any sensitive keyring data
such as key contents.
</p>
<p>
The
<a class="link" href="performance-schema-keyring-keys-table.html" title="29.12.18.2 The keyring_keys table">
<code class="literal">
keyring_keys
</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">
KEY_ID
</code>
</p>
<p>
The key identifier.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
KEY_OWNER
</code>
</p>
<p>
The owner of the key.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
BACKEND_KEY_ID
</code>
</p>
<p>
The ID used for the key by the keyring backend.
</p>
</li>
</ul>
</div>
<p>
The
<a class="link" href="performance-schema-keyring-keys-table.html" title="29.12.18.2 The keyring_keys table">
<code class="literal">
keyring_keys
</code>
</a>
table has no
indexes.
</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-keyring-keys-table.html" title="29.12.18.2 The keyring_keys table">
<code class="literal">
keyring_keys
</code>
</a>
table.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/resource-groups.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="resource-groups">
</a>
7.1.16 Resource Groups
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045260278160">
</a>
<p>
MySQL supports creation and management of resource groups, and
permits assigning threads running within the server to particular
groups so that threads execute according to the resources
available to the group. Group attributes enable control over its
resources, to enable or restrict resource consumption by threads
in the group. DBAs can modify these attributes as appropriate for
different workloads.
</p>
<p>
Currently, CPU time is a manageable resource, represented by the
concept of
<span class="quote">
“
<span class="quote">
virtual CPU
</span>
”
</span>
as a term that includes CPU
cores, hyperthreads, hardware threads, and so forth. The server
determines at startup how many virtual CPUs are available, and
database administrators with appropriate privileges can associate
these CPUs with resource groups and assign threads to groups.
</p>
<p>
For example, to manage execution of batch jobs that need not
execute with high priority, a DBA can create a
<code class="literal">
Batch
</code>
resource group, and adjust its priority
up or down depending on how busy the server is. (Perhaps batch
jobs assigned to the group should run at lower priority during the
day and at higher priority during the night.) The DBA can also
adjust the set of CPUs available to the group. Groups can be
enabled or disabled to control whether threads are assignable to
them.
</p>
<p>
The following sections describe aspects of resource group use in
MySQL:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="xref" href="resource-groups.html#resource-group-elements" title="Resource Group Elements">
Resource Group Elements
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="resource-groups.html#resource-group-attributes" title="Resource Group Attributes">
Resource Group Attributes
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="resource-groups.html#resource-group-management" title="Resource Group Management">
Resource Group Management
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="resource-groups.html#resource-group-replication" title="Resource Group Replication">
Resource Group Replication
</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="resource-groups.html#resource-group-restrictions" title="Resource Group Restrictions">
Resource Group Restrictions
</a>
</p>
</li>
</ul>
</div>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Important
</div>
<p>
On some platforms or MySQL server configurations, resource
groups are unavailable or have limitations. In particular, Linux
systems might require a manual step for some installation
methods. For details, see
<a class="xref" href="resource-groups.html#resource-group-restrictions" title="Resource Group Restrictions">
Resource Group Restrictions
</a>
.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="resource-group-elements">
</a>
Resource Group Elements
</h4>
</div>
</div>
</div>
<p>
These capabilities provide the SQL interface for resource group
management in MySQL:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
SQL statements enable creating, altering, and dropping
resource groups, and enable assigning threads to resource
groups. An optimizer hint enables assigning individual
statements to resource groups.
</p>
</li>
<li class="listitem">
<p>
Resource group privileges provide control over which users
can perform resource group operations.
</p>
</li>
<li class="listitem">
<p>
The Information Schema
<a class="link" href="information-schema-resource-groups-table.html" title="28.3.26 The INFORMATION_SCHEMA RESOURCE_GROUPS Table">
<code class="literal">
RESOURCE_GROUPS
</code>
</a>
table exposes
information about resource group definitions and the
Performance Schema
<a class="link" href="performance-schema-threads-table.html" title="29.12.22.8 The threads Table">
<code class="literal">
threads
</code>
</a>
table shows the resource group assignment for each thread.
</p>
</li>
<li class="listitem">
<p>
Status variables provide execution counts for each
management SQL statement.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="resource-group-attributes">
</a>
Resource Group Attributes
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045260255744">
</a>
<p>
Resource groups have attributes that define the group. All
attributes can be set at group creation time. Some attributes
are fixed at creation time; others can be modified any time
thereafter.
</p>
<p>
These attributes are defined at resource group creation time and
cannot be modified:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Each group has a name. Resource group names are identifiers
like table and column names, and need not be quoted in SQL
statements unless they contain special characters or are
reserved words. Group names are not case-sensitive and may
be up to 64 characters long.
</p>
</li>
<li class="listitem">
<p>
Each group has a type, which is either
<code class="literal">
SYSTEM
</code>
or
<code class="literal">
USER
</code>
. The
resource group type affects the range of priority values
assignable to the group, as described later. This attribute
together with the differences in permitted priorities
enables system threads to be identified so as to protect
them from contention for CPU resources against user threads.
</p>
<p>
System and user threads correspond to background and
foreground threads as listed in the Performance Schema
<a class="link" href="performance-schema-threads-table.html" title="29.12.22.8 The threads Table">
<code class="literal">
threads
</code>
</a>
table.
</p>
</li>
</ul>
</div>
<p>
These attributes are defined at resource group creation time and
can be modified any time thereafter:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The CPU affinity is the set of virtual CPUs the resource
group can use. An affinity can be any nonempty subset of the
available CPUs. If a group has no affinity, it can use all
available CPUs.
</p>
</li>
<li class="listitem">
<p>
The thread priority is the execution priority for threads
assigned to the resource group. Priority values range from
-20 (highest priority) to 19 (lowest priority). The default
priority is 0, for both system and user groups.
</p>
<p>
System groups are permitted a higher priority than user
groups, ensuring that user threads never have a higher
priority than system threads:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
For system resource groups, the permitted priority range
is -20 to 0.
</p>
</li>
<li class="listitem">
<p>
For user resource groups, the permitted priority range
is 0 to 19.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
Each group can be enabled or disabled, affording
administrators control over thread assignment. Threads can
be assigned only to enabled groups.
</p>
</li>
</ul>
</div>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="resource-group-management">
</a>
Resource Group Management
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045260239104">
</a>
<p>
By default, there is one system group and one user group, named
<code class="literal">
SYS_default
</code>
and
<code class="literal">
USR_default
</code>
, respectively. These default
groups cannot be dropped and their attributes cannot be
modified. Each default group has no CPU affinity and priority 0.
</p>
<p>
Newly created system and user threads are assigned to the
<code class="literal">
SYS_default
</code>
and
<code class="literal">
USR_default
</code>
groups, respectively.
</p>
<p>
For user-defined resource groups, all attributes are assigned at
group creation time. After a group has been created, its
attributes can be modified, with the exception of the name and
type attributes.
</p>
<p>
To create and manage user-defined resource groups, use these SQL
statements:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="create-resource-group.html" title="15.7.2.2 CREATE RESOURCE GROUP Statement">
<code class="literal">
CREATE RESOURCE GROUP
</code>
</a>
creates
a new group. See
<a class="xref" href="create-resource-group.html" title="15.7.2.2 CREATE RESOURCE GROUP Statement">
Section 15.7.2.2, “CREATE RESOURCE GROUP Statement”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="alter-resource-group.html" title="15.7.2.1 ALTER RESOURCE GROUP Statement">
<code class="literal">
ALTER RESOURCE GROUP
</code>
</a>
modifies
an existing group. See
<a class="xref" href="alter-resource-group.html" title="15.7.2.1 ALTER RESOURCE GROUP Statement">
Section 15.7.2.1, “ALTER RESOURCE GROUP Statement”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="drop-resource-group.html" title="15.7.2.3 DROP RESOURCE GROUP Statement">
<code class="literal">
DROP RESOURCE GROUP
</code>
</a>
drops an
existing group. See
<a class="xref" href="drop-resource-group.html" title="15.7.2.3 DROP RESOURCE GROUP Statement">
Section 15.7.2.3, “DROP RESOURCE GROUP Statement”
</a>
.
</p>
</li>
</ul>
</div>
<p>
Those statements require the
<a class="link" href="privileges-provided.html#priv_resource-group-admin">
<code class="literal">
RESOURCE_GROUP_ADMIN
</code>
</a>
privilege.
</p>
<p>
To manage resource group assignments, use these capabilities:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a class="link" href="set-resource-group.html" title="15.7.2.4 SET RESOURCE GROUP Statement">
<code class="literal">
SET RESOURCE GROUP
</code>
</a>
assigns
threads to a group. See
<a class="xref" href="set-resource-group.html" title="15.7.2.4 SET RESOURCE GROUP Statement">
Section 15.7.2.4, “SET RESOURCE GROUP Statement”
</a>
.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="optimizer-hints.html#optimizer-hints-resource-group" title="Resource Group Hint Syntax">
<code class="literal">
RESOURCE_GROUP
</code>
</a>
optimizer hint assigns individual statements to a group. See
<a class="xref" href="optimizer-hints.html" title="10.9.3 Optimizer Hints">
Section 10.9.3, “Optimizer Hints”
</a>
.
</p>
</li>
</ul>
</div>
<p>
Those operations require the
<a class="link" href="privileges-provided.html#priv_resource-group-admin">
<code class="literal">
RESOURCE_GROUP_ADMIN
</code>
</a>
or
<a class="link" href="privileges-provided.html#priv_resource-group-user">
<code class="literal">
RESOURCE_GROUP_USER
</code>
</a>
privilege.
</p>
<p>
Resource group definitions are stored in the
<code class="literal">
resource_groups
</code>
data dictionary table so that
groups persist across server restarts. Because
<code class="literal">
resource_groups
</code>
is part of the data
dictionary, it is not directly accessible by users. Resource
group information is available using the Information Schema
<a class="link" href="information-schema-resource-groups-table.html" title="28.3.26 The INFORMATION_SCHEMA RESOURCE_GROUPS Table">
<code class="literal">
RESOURCE_GROUPS
</code>
</a>
table, which is
implemented as a view on the data dictionary table. See
<a class="xref" href="information-schema-resource-groups-table.html" title="28.3.26 The INFORMATION_SCHEMA RESOURCE_GROUPS Table">
Section 28.3.26, “The INFORMATION_SCHEMA RESOURCE_GROUPS Table”
</a>
.
</p>
<p>
Initially, the
<a class="link" href="information-schema-resource-groups-table.html" title="28.3.26 The INFORMATION_SCHEMA RESOURCE_GROUPS Table">
<code class="literal">
RESOURCE_GROUPS
</code>
</a>
table has these rows describing the default groups:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66622112"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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>RESOURCE_GROUPS\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>
RESOURCE_GROUP_NAME<span class="token punctuation">:</span> USR_default
RESOURCE_GROUP_TYPE<span class="token punctuation">:</span> USER
RESOURCE_GROUP_ENABLED<span class="token punctuation">:</span> 1
VCPU_IDS<span class="token punctuation">:</span> 0-3
THREAD_PRIORITY<span class="token punctuation">:</span> 0
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span 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>
RESOURCE_GROUP_NAME<span class="token punctuation">:</span> SYS_default
RESOURCE_GROUP_TYPE<span class="token punctuation">:</span> SYSTEM
RESOURCE_GROUP_ENABLED<span class="token punctuation">:</span> 1
VCPU_IDS<span class="token punctuation">:</span> 0-3
THREAD_PRIORITY<span class="token punctuation">:</span> 0</span></code></pre>
</div>
<p>
The
<code class="literal">
THREAD_PRIORITY
</code>
values are 0, indicating
the default priority. The
<code class="literal">
VCPU_IDS
</code>
values
show a range comprising all available CPUs. For the default
groups, the displayed value varies depending on the system on
which the MySQL server runs.
</p>
<p>
Earlier discussion mentioned a scenario involving a resource
group named
<code class="literal">
Batch
</code>
to manage execution of
batch jobs that need not execute with high priority. To create
such a group, use a statement similar to this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa8951867"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">RESOURCE</span> <span class="token keyword">GROUP</span> Batch
<span class="token keyword">TYPE</span> <span class="token operator">=</span> <span class="token keyword">USER</span>
<span class="token keyword">VCPU</span> <span class="token operator">=</span> <span class="token number">2</span><span class="token operator">-</span><span class="token number">3</span> <span class="token comment" spellcheck="true">-- assumes a system with at least 4 CPUs</span>
<span class="token keyword">THREAD_PRIORITY</span> <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
To verify that the resource group was created as expected, check
the
<a class="link" href="information-schema-resource-groups-table.html" title="28.3.26 The INFORMATION_SCHEMA RESOURCE_GROUPS Table">
<code class="literal">
RESOURCE_GROUPS
</code>
</a>
table:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa95868055"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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>RESOURCE_GROUPS
<span class="token keyword">WHERE</span> RESOURCE_GROUP_NAME <span class="token operator">=</span> <span class="token string">'Batch'</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>
RESOURCE_GROUP_NAME<span class="token punctuation">:</span> Batch
RESOURCE_GROUP_TYPE<span class="token punctuation">:</span> USER
RESOURCE_GROUP_ENABLED<span class="token punctuation">:</span> 1
VCPU_IDS<span class="token punctuation">:</span> 2-3
THREAD_PRIORITY<span class="token punctuation">:</span> 10</span></code></pre>
</div>
<p>
If the
<code class="literal">
THREAD_PRIORITY
</code>
value is 0 rather than
10, check whether your platform or system configuration limits
the resource group capability; see
<a class="xref" href="resource-groups.html#resource-group-restrictions" title="Resource Group Restrictions">
Resource Group Restrictions
</a>
.
</p>
<p>
To assign a thread to the
<code class="literal">
Batch
</code>
group, do
this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa57787496"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">RESOURCE</span> <span class="token keyword">GROUP</span> Batch <span class="token keyword">FOR</span> <em class="replaceable">thread_id</em><span class="token punctuation">;</span></code></pre>
</div>
<p>
Thereafter, statements in the named thread execute with
<code class="literal">
Batch
</code>
group resources.
</p>
<p>
If a session's own current thread should be in the
<code class="literal">
Batch
</code>
group, execute this statement within
the session:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa96337957"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">RESOURCE</span> <span class="token keyword">GROUP</span> Batch<span class="token punctuation">;</span></code></pre>
</div>
<p>
Thereafter, statements in the session execute with
<code class="literal">
Batch
</code>
group resources.
</p>
<p>
To execute a single statement using the
<code class="literal">
Batch
</code>
group, use the
<a class="link" href="optimizer-hints.html#optimizer-hints-resource-group" title="Resource Group Hint Syntax">
<code class="literal">
RESOURCE_GROUP
</code>
</a>
optimizer hint:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa2152698"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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 comment" spellcheck="true">/*+ RESOURCE_GROUP(Batch) */</span> <span class="token keyword">INTO</span> t2 <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 punctuation">;</span></code></pre>
</div>
<p>
Threads assigned to the
<code class="literal">
Batch
</code>
group execute
with its resources, which can be modified as desired:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For times when the system is highly loaded, decrease the
number of CPUs assigned to the group, lower its priority, or
(as shown) both:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa55282027"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">RESOURCE</span> <span class="token keyword">GROUP</span> Batch
<span class="token keyword">VCPU</span> <span class="token operator">=</span> <span class="token number">3</span>
<span class="token keyword">THREAD_PRIORITY</span> <span class="token operator">=</span> <span class="token number">19</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
For times when the system is lightly loaded, increase the
number of CPUs assigned to the group, raise its priority, or
(as shown) both:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa52537407"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">RESOURCE</span> <span class="token keyword">GROUP</span> Batch
<span class="token keyword">VCPU</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token operator">-</span><span class="token number">3</span>
<span class="token keyword">THREAD_PRIORITY</span> <span class="token operator">=</span> <span class="token number">0</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="resource-group-replication">
</a>
Resource Group Replication
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045260175536">
</a>
<p>
Resource group management is local to the server on which it
occurs. Resource group SQL statements and modifications to the
<code class="literal">
resource_groups
</code>
data dictionary table are not
written to the binary log and are not replicated.
</p>
</div>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h4 class="title">
<a name="resource-group-restrictions">
</a>
Resource Group Restrictions
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045260171488">
</a>
<a class="indexterm" name="idm46045260170000">
</a>
<p>
On some platforms or MySQL server configurations, resource
groups are unavailable or have limitations:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Resource groups are unavailable if the thread pool plugin is
installed.
</p>
<a class="indexterm" name="idm46045260166960">
</a>
</li>
<li class="listitem">
<p>
Resource groups are unavailable on macOS, which provides no
API for binding CPUs to a thread.
</p>
</li>
<li class="listitem">
<p>
On FreeBSD and Solaris, resource group thread priorities are
ignored. (Effectively, all threads run at priority 0.)
Attempts to change priorities result in a warning:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa75967417"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">ALTER</span> <span class="token keyword">RESOURCE</span> <span class="token keyword">GROUP</span> abc <span class="token keyword">THREAD_PRIORITY</span> <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected, 1 warning (0.18 sec)</span>
<span class="token prompt">mysql></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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> Warning <span class="token punctuation">|</span> 4560 <span class="token punctuation">|</span> Attribute thread_priority is ignored (using default value). <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 class="token punctuation">+</span></span></code></pre>
</div>
</li>
<li class="listitem">
<p>
On Linux, resource groups thread priorities are ignored
unless the
<code class="literal">
CAP_SYS_NICE
</code>
capability is
set. Granting
<code class="literal">
CAP_SYS_NICE
</code>
capability to
a process enables a range of privileges; consult
<a class="ulink" href="http://man7.org/linux/man-pages/man7/capabilities.7.html" target="_blank">
http://man7.org/linux/man-pages/man7/capabilities.7.html
</a>
for the full list. Please be careful when enabling this
capability.
</p>
<p>
On Linux platforms using systemd and kernel support for
Ambient Capabilities (Linux 4.3 or newer), the recommended
way to enable
<code class="literal">
CAP_SYS_NICE
</code>
capability is
to modify the MySQL service file and leave the
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
binary unmodified. To adjust the
service file for MySQL, use this procedure:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
Run the appropriate command for your platform:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
Oracle Linux, Red Hat, and Fedora systems:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa46074179"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">sudo</span> systemctl edit mysqld</code></pre>
</div>
</li>
<li class="listitem">
<p>
SUSE, Ubuntu, and Debian systems:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa96976010"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">sudo</span> systemctl edit mysql</code></pre>
</div>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
Using an editor, add the following text to the service
file:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa27244530"><div class="copy-help left">Press ⌘+C to 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">[Service]</span>
<span class="token constant">AmbientCapabilities</span><span class="token attr-value"><span class="token punctuation">=</span>CAP_SYS_NICE</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
Restart the MySQL service.
</p>
</li>
</ol>
</div>
<p>
If you cannot enable the
<code class="literal">
CAP_SYS_NICE
</code>
capability as just described, it can be set manually using
the
<span class="command">
<strong>
setcap
</strong>
</span>
command, specifying the path
name to the
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
executable (this
requires
<span class="command">
<strong>
sudo
</strong>
</span>
access). You can check the
capabilities using
<span class="command">
<strong>
getcap
</strong>
</span>
. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa37122869"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">sudo</span> setcap cap_sys_nice+ep <em class="replaceable">/path/to/mysqld</em>
<span class="token prompt">$> </span><span class="token command">getcap</span> <em class="replaceable">/path/to/mysqld</em>
<em class="replaceable">/path/to/mysqld</em> = cap_sys_nice+ep</code></pre>
</div>
<p>
As a safety measure, restrict execution of the
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
binary to the
<code class="literal">
root
</code>
user and users with
<code class="literal">
mysql
</code>
group membership:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa9854294"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">sudo</span> chown root<span class="token punctuation">:</span>mysql <em class="replaceable">/path/to/mysqld</em>
<span class="token prompt">$> </span><span class="token command">sudo</span> chmod 0750 <em class="replaceable">/path/to/mysqld</em></code></pre>
</div>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Important
</div>
<p>
If manual use of
<span class="command">
<strong>
setcap
</strong>
</span>
is required, it
must be performed after each reinstall.
</p>
</div>
</li>
<li class="listitem">
<p>
On Windows, threads run at one of five thread priority
levels. The resource group thread priority range of -20 to
19 maps onto those levels as indicated in the following
table.
</p>
<div class="table">
<a name="windows-thread-priority-table">
</a>
<p class="title">
<b>
Table 7.6 Resource Group Thread Priority on Windows
</b>
</p>
<div class="table-contents">
<table summary="Priority ranges for resource group threads on Windows.">
<colgroup>
<col style="width: 20%"/>
<col style="width: 40%"/>
</colgroup>
<thead>
<tr>
<th>
Priority Range
</th>
<th>
Windows Priority Level
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
-20 to -10
</td>
<td>
<code class="literal">
THREAD_PRIORITY_HIGHEST
</code>
</td>
</tr>
<tr>
<td>
-9 to -1
</td>
<td>
<code class="literal">
THREAD_PRIORITY_ABOVE_NORMAL
</code>
</td>
</tr>
<tr>
<td>
0
</td>
<td>
<code class="literal">
THREAD_PRIORITY_NORMAL
</code>
</td>
</tr>
<tr>
<td>
1 to 10
</td>
<td>
<code class="literal">
THREAD_PRIORITY_BELOW_NORMAL
</code>
</td>
</tr>
<tr>
<td>
11 to 19
</td>
<td>
<code class="literal">
THREAD_PRIORITY_LOWEST
</code>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
</li>
</ul>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/create-function.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="create-function">
</a>
15.1.14 CREATE FUNCTION Statement
</h3>
</div>
</div>
</div>
<p>
The
<a class="link" href="create-function.html" title="15.1.14 CREATE FUNCTION Statement">
<code class="literal">
CREATE FUNCTION
</code>
</a>
statement is
used to create stored functions and loadable functions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For information about creating stored functions, see
<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>
<li class="listitem">
<p>
For information about creating loadable functions, see
<a class="xref" href="create-function-loadable.html" title="15.7.4.1 CREATE FUNCTION Statement for Loadable Functions">
Section 15.7.4.1, “CREATE FUNCTION Statement for Loadable Functions”
</a>
.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/partitioning-overview.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="partitioning-overview">
</a>
26.1 Overview of Partitioning in MySQL
</h2>
</div>
</div>
</div>
<a class="indexterm" name="idm46045084973440">
</a>
<p>
This section provides a conceptual overview of partitioning in
MySQL 8.4.
</p>
<p>
For information on partitioning restrictions and feature
limitations, see
<a class="xref" href="partitioning-limitations.html" title="26.6 Restrictions and Limitations on Partitioning">
Section 26.6, “Restrictions and Limitations on Partitioning”
</a>
.
</p>
<p>
The SQL standard does not provide much in the way of guidance
regarding the physical aspects of data storage. The SQL language
itself is intended to work independently of any data structures or
media underlying the schemas, tables, rows, or columns with which
it works. Nonetheless, most advanced database management systems
have evolved some means of determining the physical location to be
used for storing specific pieces of data in terms of the file
system, hardware or even both. In MySQL, the
<code class="literal">
InnoDB
</code>
storage engine has long supported the
notion of a tablespace (see
<a class="xref" href="innodb-tablespace.html" title="17.6.3 Tablespaces">
Section 17.6.3, “Tablespaces”
</a>
),
and the MySQL Server, even prior to the introduction of
partitioning, could be configured to employ different physical
directories for storing different databases (see
<a class="xref" href="symbolic-links.html" title="10.12.2 Using Symbolic Links">
Section 10.12.2, “Using Symbolic Links”
</a>
, for an explanation of how this
is done).
</p>
<p>
<span class="firstterm">
Partitioning
</span>
takes this
notion a step further, by enabling you to distribute portions of
individual tables across a file system according to rules which
you can set largely as needed. In effect, different portions of a
table are stored as separate tables in different locations. The
user-selected rule by which the division of data is accomplished
is known as a
<span class="firstterm">
partitioning
function
</span>
, which in MySQL can be the modulus, simple
matching against a set of ranges or value lists, an internal
hashing function, or a linear hashing function. The function is
selected according to the partitioning type specified by the user,
and takes as its parameter the value of a user-supplied
expression. This expression can be a column value, a function
acting on one or more column values, or a set of one or more
column values, depending on the type of partitioning that is used.
</p>
<p>
In the case of
<code class="literal">
RANGE
</code>
,
<code class="literal">
LIST
</code>
,
and [
<code class="literal">
LINEAR
</code>
]
<code class="literal">
HASH
</code>
partitioning, the value of the partitioning column is passed to
the partitioning function, which returns an integer value
representing the number of the partition in which that particular
record should be stored. This function must be nonconstant and
nonrandom. It may not contain any queries, but may use an SQL
expression that is valid in MySQL, as long as that expression
returns either
<code class="literal">
NULL
</code>
or an integer
<em class="replaceable">
<code>
intval
</code>
</em>
such that
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa70818585"><div class="copy-help left">Press ⌘+C to 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 operator">-</span>MAXVALUE <span class="token operator"><=</span> <em class="replaceable">intval</em> <span class="token operator"><=</span> MAXVALUE</code></pre>
</div>
<p>
(
<code class="literal">
MAXVALUE
</code>
is used to represent the least upper
bound for the type of integer in question.
<code class="literal">
-MAXVALUE
</code>
represents the greatest lower bound.)
</p>
<p>
For [
<code class="literal">
LINEAR
</code>
]
<code class="literal">
KEY
</code>
,
<code class="literal">
RANGE COLUMNS
</code>
, and
<code class="literal">
LIST
COLUMNS
</code>
partitioning, the partitioning expression
consists of a list of one or more columns.
</p>
<p>
For [
<code class="literal">
LINEAR
</code>
]
<code class="literal">
KEY
</code>
partitioning, the partitioning function is supplied by MySQL.
</p>
<p>
For more information about permitted partitioning column types and
partitioning functions, see
<a class="xref" href="partitioning-types.html" title="26.2 Partitioning Types">
Section 26.2, “Partitioning Types”
</a>
,
as well as
<a class="xref" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
Section 15.1.20, “CREATE TABLE Statement”
</a>
, which provides
partitioning syntax descriptions and additional examples. For
information about restrictions on partitioning functions, see
<a class="xref" href="partitioning-limitations-functions.html" title="26.6.3 Partitioning Limitations Relating to Functions">
Section 26.6.3, “Partitioning Limitations Relating to Functions”
</a>
.
</p>
<p>
This is known as
<span class="firstterm">
horizontal
partitioning
</span>
—that is, different rows of a table
may be assigned to different physical partitions. MySQL
8.4 does not support
<span class="firstterm">
vertical partitioning
</span>
, in
which different columns of a table are assigned to different
physical partitions. There are no plans at this time to introduce
vertical partitioning into MySQL.
</p>
<p>
For creating partitioned tables, you must use a storage engine
that supports them. In MySQL 8.4, all partitions of
the same partitioned table must use the same storage engine.
However, there is nothing preventing you from using different
storage engines for different partitioned tables on the same MySQL
server or even in the same database.
</p>
<p>
In MySQL 8.4, the only storage engines that support
partitioning are
<code class="literal">
InnoDB
</code>
and
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
. Partitioning cannot be used with
storage engines that do not support it; these include the
<code class="literal">
MyISAM
</code>
,
<code class="literal">
MERGE
</code>
,
<code class="literal">
CSV
</code>
, and
<code class="literal">
FEDERATED
</code>
storage
engines.
</p>
<p>
Partitioning by
<code class="literal">
KEY
</code>
or
<code class="literal">
LINEAR
KEY
</code>
is possible with
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
,
but other types of user-defined partitioning are not supported for
tables using this storage engine. In addition, an
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
table that employs user-defined
partitioning must have an explicit primary key, and any columns
referenced in the table's partitioning expression must be
part of the primary key. However, if no columns are listed in the
<code class="literal">
PARTITION BY KEY
</code>
or
<code class="literal">
PARTITION BY
LINEAR KEY
</code>
clause of 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-partition-operations.html" title="15.1.9.1 ALTER TABLE Partition Operations">
<code class="literal">
ALTER
TABLE
</code>
</a>
statement used to create or modify a
user-partitioned
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
table, then the
table is not required to have an explicit primary key. For more
information, see
<a class="xref" href="mysql-cluster-limitations-syntax.html" title="25.2.7.1 Noncompliance with SQL Syntax in NDB Cluster">
Section 25.2.7.1, “Noncompliance with SQL Syntax in NDB Cluster”
</a>
.
</p>
<p>
When creating a partitioned table, the default storage engine is
used just as when creating any other table; to override this
behavior, it is necessary only to use the
<code class="literal">
[STORAGE]
ENGINE
</code>
option just as you would for a table that is not
partitioned. The target storage engine must provide native
partitioning support, or the statement fails. You should keep in
mind that
<code class="literal">
[STORAGE] ENGINE
</code>
(and other table
options) need to be listed
<span class="emphasis">
<em>
before
</em>
</span>
any
partitioning options are used in a
<a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
<code class="literal">
CREATE
TABLE
</code>
</a>
statement. This example shows how to create a
table that is partitioned by hash into 6 partitions and which uses
the
<code class="literal">
InnoDB
</code>
storage engine (regardless of the
value of
<a class="link" href="server-system-variables.html#sysvar_default_storage_engine">
<code class="literal">
default_storage_engine
</code>
</a>
):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24054923"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> ti <span class="token punctuation">(</span>id <span class="token datatype">INT</span><span class="token punctuation">,</span> amount <span class="token datatype">DECIMAL</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> tr_date <span class="token datatype">DATE</span><span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span><span class="token operator">=</span>INNODB
<span class="token keyword">PARTITION</span> <span class="token keyword">BY</span> <span class="token keyword">HASH</span><span class="token punctuation">(</span> <span class="token function">MONTH</span><span class="token punctuation">(</span>tr_date<span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token keyword">PARTITIONS</span> <span class="token number">6</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Each
<code class="literal">
PARTITION
</code>
clause can include a
<code class="literal">
[STORAGE] ENGINE
</code>
option, but in MySQL
8.4 this has no effect.
</p>
<p>
Unless otherwise specified, the remaining examples in this
discussion assume that
<a class="link" href="server-system-variables.html#sysvar_default_storage_engine">
<code class="literal">
default_storage_engine
</code>
</a>
is
<code class="literal">
InnoDB
</code>
.
</p>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Important
</div>
<p>
Partitioning applies to all data and indexes of a table; you
cannot partition only the data and not the indexes, or vice
versa, nor can you partition only a portion of the table.
</p>
</div>
<p>
Data and indexes for each partition can be assigned to a specific
directory using the
<code class="literal">
DATA DIRECTORY
</code>
and
<code class="literal">
INDEX DIRECTORY
</code>
options for the
<code class="literal">
PARTITION
</code>
clause of the
<a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
<code class="literal">
CREATE TABLE
</code>
</a>
statement used to
create the partitioned table.
</p>
<p>
Only the
<code class="literal">
DATA DIRECTORY
</code>
option is supported for
individual partitions and subpartitions of
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
tables. The directory
specified in a
<code class="literal">
DATA DIRECTORY
</code>
clause must be
known to
<code class="literal">
InnoDB
</code>
. For more information, see
<a class="xref" href="innodb-create-table-external.html#innodb-create-table-external-data-directory" title="Using the DATA DIRECTORY Clause">
Using the DATA DIRECTORY Clause
</a>
.
</p>
<a class="indexterm" name="idm46045084907280">
</a>
<a class="indexterm" name="idm46045084905792">
</a>
<p>
All columns used in the table's partitioning expression must
be part of every unique key that the table may have, including any
primary key. This means that a table such as this one, created by
the following SQL statement, cannot be partitioned:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa97884470"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> tnp <span class="token punctuation">(</span>
id <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
ref <span class="token datatype">BIGINT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
<span class="token keyword">name</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 punctuation">,</span>
<span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> pk <span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token keyword">UNIQUE</span> <span class="token keyword">KEY</span> uk <span class="token punctuation">(</span><span class="token keyword">name</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Because the keys
<code class="literal">
pk
</code>
and
<code class="literal">
uk
</code>
have no columns in common, there are no columns available for use
in a partitioning expression. Possible workarounds in this
situation include adding the
<code class="literal">
name
</code>
column to the
table's primary key, adding the
<code class="literal">
id
</code>
column
to
<code class="literal">
uk
</code>
, or simply removing the unique key
altogether. See
<a class="xref" href="partitioning-limitations-partitioning-keys-unique-keys.html" title="26.6.1 Partitioning Keys, Primary Keys, and Unique Keys">
Section 26.6.1, “Partitioning Keys, Primary Keys, and Unique Keys”
</a>
,
for more information.
</p>
<p>
In addition,
<code class="literal">
MAX_ROWS
</code>
and
<code class="literal">
MIN_ROWS
</code>
can be used to determine the maximum
and minimum numbers of rows, respectively, that can be stored in
each partition. See
<a class="xref" href="partitioning-management.html" title="26.3 Partition Management">
Section 26.3, “Partition Management”
</a>
, for
more information on these options.
</p>
<a class="indexterm" name="idm46045084894976">
</a>
<p>
The
<code class="literal">
MAX_ROWS
</code>
option can also be useful for
creating NDB Cluster tables with extra partitions, thus allowing
for greater storage of hash indexes. See the documentation for the
<a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datamemory">
<code class="literal">
DataMemory
</code>
</a>
data node
configuration parameter, as well as
<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>
, for more
information.
</p>
<a class="indexterm" name="idm46045084890192">
</a>
<p>
Some advantages of partitioning are listed here:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Partitioning makes it possible to store more data in one table
than can be held on a single disk or file system partition.
</p>
</li>
<li class="listitem">
<p>
Data that loses its usefulness can often be easily removed
from a partitioned table by dropping the partition (or
partitions) containing only that data. Conversely, the process
of adding new data can in some cases be greatly facilitated by
adding one or more new partitions for storing specifically
that data.
</p>
</li>
<li class="listitem">
<p>
Some queries can be greatly optimized in virtue of the fact
that data satisfying a given
<code class="literal">
WHERE
</code>
clause
can be stored only on one or more partitions, which
automatically excludes any remaining partitions from the
search. Because partitions can be altered after a partitioned
table has been created, you can reorganize your data to
enhance frequent queries that may not have been often used
when the partitioning scheme was first set up. This ability to
exclude non-matching partitions (and thus any rows they
contain) is often referred to as
<span class="firstterm">
partition pruning
</span>
. For
more information, see
<a class="xref" href="partitioning-pruning.html" title="26.4 Partition Pruning">
Section 26.4, “Partition Pruning”
</a>
.
</p>
<p>
In addition, MySQL supports explicit partition selection for
queries. For example,
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT * FROM t
PARTITION (p0,p1) WHERE c < 5
</code>
</a>
selects only those
rows in partitions
<code class="literal">
p0
</code>
and
<code class="literal">
p1
</code>
that match the
<code class="literal">
WHERE
</code>
condition. In this case, MySQL does not check any other
partitions of table
<code class="literal">
t
</code>
; this can greatly
speed up queries when you already know which partition or
partitions you wish to examine. Partition selection is also
supported for the data modification statements
<a class="link" href="delete.html" title="15.2.2 DELETE Statement">
<code class="literal">
DELETE
</code>
</a>
,
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
,
<a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
<code class="literal">
REPLACE
</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="load-data.html" title="15.2.9 LOAD DATA Statement">
<code class="literal">
LOAD DATA
</code>
</a>
,
<a class="link" href="load-xml.html" title="15.2.10 LOAD XML Statement">
<code class="literal">
LOAD XML
</code>
</a>
. See the descriptions
of these statements for more information and examples.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/performance-schema-objects-summary-global-by-type-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="performance-schema-objects-summary-global-by-type-table">
</a>
29.12.20.6 Object Wait Summary Table
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045068553888">
</a>
<a class="indexterm" name="idm46045068552384">
</a>
<p>
The Performance Schema maintains the
<a class="link" href="performance-schema-objects-summary-global-by-type-table.html" title="29.12.20.6 Object Wait Summary Table">
<code class="literal">
objects_summary_global_by_type
</code>
</a>
table for aggregating object wait events.
</p>
<p>
Example object wait event summary information:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa83877157"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>objects_summary_global_by_type\G
<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> 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>
OBJECT_TYPE<span class="token punctuation">:</span> TABLE
OBJECT_SCHEMA<span class="token punctuation">:</span> test
OBJECT_NAME<span class="token punctuation">:</span> t
COUNT_STAR<span class="token punctuation">:</span> 3
SUM_TIMER_WAIT<span class="token punctuation">:</span> 263126976
MIN_TIMER_WAIT<span class="token punctuation">:</span> 1522272
AVG_TIMER_WAIT<span class="token punctuation">:</span> 87708678
MAX_TIMER_WAIT<span class="token punctuation">:</span> 258428280
...
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 10. 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>
OBJECT_TYPE<span class="token punctuation">:</span> TABLE
OBJECT_SCHEMA<span class="token punctuation">:</span> mysql
OBJECT_NAME<span class="token punctuation">:</span> user
COUNT_STAR<span class="token punctuation">:</span> 14
SUM_TIMER_WAIT<span class="token punctuation">:</span> 365567592
MIN_TIMER_WAIT<span class="token punctuation">:</span> 1141704
AVG_TIMER_WAIT<span class="token punctuation">:</span> 26111769
MAX_TIMER_WAIT<span class="token punctuation">:</span> 334783032
...</span></code></pre>
</div>
<p>
The
<a class="link" href="performance-schema-objects-summary-global-by-type-table.html" title="29.12.20.6 Object Wait Summary Table">
<code class="literal">
objects_summary_global_by_type
</code>
</a>
table has these grouping columns to indicate how the table
aggregates events:
<code class="literal">
OBJECT_TYPE
</code>
,
<code class="literal">
OBJECT_SCHEMA
</code>
, and
<code class="literal">
OBJECT_NAME
</code>
. Each row summarizes events for
the given object.
</p>
<p>
<a class="link" href="performance-schema-objects-summary-global-by-type-table.html" title="29.12.20.6 Object Wait Summary Table">
<code class="literal">
objects_summary_global_by_type
</code>
</a>
has the same summary columns as the
<code class="literal">
events_waits_summary_by_
<em class="replaceable">
<code>
xxx
</code>
</em>
</code>
tables. See
<a class="xref" href="performance-schema-wait-summary-tables.html" title="29.12.20.1 Wait Event Summary Tables">
Section 29.12.20.1, “Wait Event Summary Tables”
</a>
.
</p>
<p>
The
<a class="link" href="performance-schema-objects-summary-global-by-type-table.html" title="29.12.20.6 Object Wait Summary Table">
<code class="literal">
objects_summary_global_by_type
</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">
OBJECT_TYPE
</code>
,
<code class="literal">
OBJECT_SCHEMA
</code>
,
<code class="literal">
OBJECT_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 permitted for
the object summary table. It resets the summary columns to
zero rather than removing rows.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/gis-wkb-functions.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="gis-wkb-functions">
</a>
14.16.4 Functions That Create Geometry Values from WKB Values
</h3>
</div>
</div>
</div>
<p>
These functions take as arguments a
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
containing a Well-Known Binary
(WKB) representation and, optionally, a spatial reference system
identifier (SRID). They return the corresponding geometry. For a
description of WKB format, see
<a class="xref" href="gis-data-formats.html#gis-wkb-format" title="Well-Known Binary (WKB) Format">
Well-Known Binary (WKB) Format
</a>
.
</p>
<p>
Functions in this section detect arguments in either Cartesian or
geographic spatial reference systems (SRSs), and return results
appropriate to the SRS.
</p>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-geomfromwkb">
<code class="literal">
ST_GeomFromWKB()
</code>
</a>
accepts a WKB
value of any geometry type as its first argument. Other functions
provide type-specific construction functions for construction of
geometry values of each geometry type.
</p>
<p>
Prior to MySQL 8.4, these functions also accepted
geometry objects as returned by the functions in
<a class="xref" href="gis-mysql-specific-functions.html" title="14.16.5 MySQL-Specific Functions That Create Geometry Values">
Section 14.16.5, “MySQL-Specific Functions That Create Geometry Values”
</a>
. Geometry arguments
are no longer permitted and produce an error. To migrate calls
from using geometry arguments to using WKB arguments, follow these
guidelines:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Rewrite constructs such as
<code class="literal">
ST_GeomFromWKB(Point(0,
0))
</code>
as
<code class="literal">
Point(0, 0)
</code>
.
</p>
</li>
<li class="listitem">
<p>
Rewrite constructs such as
<code class="literal">
ST_GeomFromWKB(Point(0,
0), 4326)
</code>
as
<code class="literal">
ST_SRID(Point(0, 0),
4326)
</code>
or
<code class="literal">
ST_GeomFromWKB(ST_AsWKB(Point(0,
0)), 4326)
</code>
.
</p>
</li>
</ul>
</div>
<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 the WKB or SRID argument is
<code class="literal">
NULL
</code>
, the
return value is
<code class="literal">
NULL
</code>
.
</p>
</li>
<li class="listitem">
<p>
By default, geographic coordinates (latitude, longitude) are
interpreted as in the order specified by the spatial reference
system of geometry arguments. An optional
<em class="replaceable">
<code>
options
</code>
</em>
argument may be given to
override the default axis order.
<code class="option">
options
</code>
consists of a list of comma-separated
<code class="literal">
<em class="replaceable">
<code>
key
</code>
</em>
=
<em class="replaceable">
<code>
value
</code>
</em>
</code>
.
The only permitted
<em class="replaceable">
<code>
key
</code>
</em>
value is
<code class="literal">
axis-order
</code>
, with permitted values of
<code class="literal">
lat-long
</code>
,
<code class="literal">
long-lat
</code>
and
<code class="literal">
srid-defined
</code>
(the default).
</p>
<p>
If the
<em class="replaceable">
<code>
options
</code>
</em>
argument is
<code class="literal">
NULL
</code>
, the return value is
<code class="literal">
NULL
</code>
. If the
<em class="replaceable">
<code>
options
</code>
</em>
argument is invalid, an
error occurs to indicate why.
</p>
</li>
<li class="listitem">
<p>
If an SRID argument refers to 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>
For geographic SRS geometry arguments, if any argument has a
longitude or latitude that is out of range, an error occurs:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<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_longitude_out_of_range" target="_top">
<code class="literal">
ER_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_latitude_out_of_range" target="_top">
<code class="literal">
ER_LATITUDE_OUT_OF_RANGE
</code>
</a>
error occurs.
</p>
</li>
</ul>
</div>
<p>
Ranges shown are in degrees. If an SRS uses another unit, the
range uses the corresponding values in its unit. The exact
range limits deviate slightly due to floating-point
arithmetic.
</p>
</li>
</ul>
</div>
<p>
These functions are available for creating geometries from WKB
values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a name="function_st-geomcollfromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-geomcollfromwkb">
<code class="literal">
ST_GeomCollFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-geomcollfromwkb">
<code class="literal">
ST_GeometryCollectionFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197856352">
</a>
<a class="indexterm" name="idm46045197855280">
</a>
<p>
Constructs a
<code class="literal">
GeometryCollection
</code>
value using
its WKB representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-geomfromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-geomfromwkb">
<code class="literal">
ST_GeomFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-geomfromwkb">
<code class="literal">
ST_GeometryFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197843712">
</a>
<a class="indexterm" name="idm46045197842640">
</a>
<p>
Constructs a geometry value of any type using its WKB
representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-linefromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-linefromwkb">
<code class="literal">
ST_LineFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-linefromwkb">
<code class="literal">
ST_LineStringFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197831776">
</a>
<a class="indexterm" name="idm46045197830704">
</a>
<p>
Constructs a
<code class="literal">
LineString
</code>
value using its WKB
representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-mlinefromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-mlinefromwkb">
<code class="literal">
ST_MLineFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-mlinefromwkb">
<code class="literal">
ST_MultiLineStringFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197819024">
</a>
<a class="indexterm" name="idm46045197817952">
</a>
<p>
Constructs a
<code class="literal">
MultiLineString
</code>
value using
its WKB representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-mpointfromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-mpointfromwkb">
<code class="literal">
ST_MPointFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-mpointfromwkb">
<code class="literal">
ST_MultiPointFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197806224">
</a>
<a class="indexterm" name="idm46045197805152">
</a>
<p>
Constructs a
<code class="literal">
MultiPoint
</code>
value using its WKB
representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-mpolyfromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-mpolyfromwkb">
<code class="literal">
ST_MPolyFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-mpolyfromwkb">
<code class="literal">
ST_MultiPolygonFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197793552">
</a>
<a class="indexterm" name="idm46045197792480">
</a>
<p>
Constructs a
<code class="literal">
MultiPolygon
</code>
value using its
WKB representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-pointfromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-pointfromwkb">
<code class="literal">
ST_PointFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197783440">
</a>
<p>
Constructs a
<code class="literal">
Point
</code>
value using its WKB
representation and SRID.
</p>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-pointfromwkb">
<code class="literal">
ST_PointFromWKB()
</code>
</a>
handles its
arguments as described in the introduction to this section.
</p>
</li>
<li class="listitem">
<a name="function_st-polyfromwkb">
</a>
<p>
<a class="link" href="gis-wkb-functions.html#function_st-polyfromwkb">
<code class="literal">
ST_PolyFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
,
<a class="link" href="gis-wkb-functions.html#function_st-polyfromwkb">
<code class="literal">
ST_PolygonFromWKB(
<em class="replaceable">
<code>
wkb
</code>
</em>
[,
<em class="replaceable">
<code>
srid
</code>
</em>
[,
<em class="replaceable">
<code>
options
</code>
</em>
]])
</code>
</a>
</p>
<a class="indexterm" name="idm46045197770720">
</a>
<a class="indexterm" name="idm46045197769648">
</a>
<p>
Constructs a
<code class="literal">
Polygon
</code>
value using its WKB
representation and SRID.
</p>
<p>
These functions handle their arguments as described in the
introduction to this section.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-solutions-partitioning.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="replication-solutions-partitioning">
</a>
19.4.6 Replicating Different Databases to Different Replicas
</h3>
</div>
</div>
</div>
<p>
There may be situations where you have a single source server and
want to replicate different databases to different replicas. For
example, you may want to distribute different sales data to
different departments to help spread the load during data
analysis. A sample of this layout is shown in
<a class="xref" href="replication-solutions-partitioning.html#figure_replication-multi-db" title="Figure 19.2 Replicating Databases to Separate Replicas">
Figure 19.2, “Replicating Databases to Separate Replicas”
</a>
.
</p>
<div class="figure">
<a name="figure_replication-multi-db">
</a>
<p class="title">
<b>
Figure 19.2 Replicating Databases to Separate Replicas
</b>
</p>
<div class="figure-contents">
<div class="mediaobject">
<img alt="The MySQL source has three databases, databaseA, databaseB, and databaseC. databaseA is replicated only to MySQL Replica 1, databaseB is replicated only to MySQL Replica 2, and databaseC is replicated only to MySQL Replica 3." src="images/multi-db.png" style="width: 100%; max-width: 370px;"/>
</div>
</div>
</div>
<br class="figure-break"/>
<p>
You can achieve this separation by configuring the source and
replicas as normal, and then limiting the binary log statements
that each replica processes by using the
<a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-do-table">
<code class="option">
--replicate-wild-do-table
</code>
</a>
configuration option on each replica.
</p>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Important
</div>
<p>
You should
<span class="emphasis">
<em>
not
</em>
</span>
use
<a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db">
<code class="option">
--replicate-do-db
</code>
</a>
for this
purpose when using statement-based replication, since
statement-based replication causes this option's effects to
vary according to the database that is currently selected. This
applies to mixed-format replication as well, since this enables
some updates to be replicated using the statement-based format.
</p>
<p>
However, it should be safe to use
<a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db">
<code class="option">
--replicate-do-db
</code>
</a>
for this
purpose if you are using row-based replication only, since in
this case the currently selected database has no effect on the
option's operation.
</p>
</div>
<p>
For example, to support the separation as shown in
<a class="xref" href="replication-solutions-partitioning.html#figure_replication-multi-db" title="Figure 19.2 Replicating Databases to Separate Replicas">
Figure 19.2, “Replicating Databases to Separate Replicas”
</a>
, you should
configure each replica as follows, before executing
<a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
<code class="literal">
START REPLICA
</code>
</a>
:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Replica 1 should use
<code class="option">
--replicate-wild-do-table=databaseA.%
</code>
.
</p>
</li>
<li class="listitem">
<p>
Replica 2 should use
<code class="option">
--replicate-wild-do-table=databaseB.%
</code>
.
</p>
</li>
<li class="listitem">
<p>
Replica 3 should use
<code class="option">
--replicate-wild-do-table=databaseC.%
</code>
.
</p>
</li>
</ul>
</div>
<p>
Each replica in this configuration receives the entire binary log
from the source, but executes only those events from the binary
log that apply to the databases and tables included by the
<a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-do-table">
<code class="option">
--replicate-wild-do-table
</code>
</a>
option in
effect on that replica.
</p>
<p>
If you have data that must be synchronized to the replicas before
replication starts, you have a number of choices:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Synchronize all the data to each replica, and delete the
databases, tables, or both that you do not want to keep.
</p>
</li>
<li class="listitem">
<p>
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 a separate dump
file for each database and load the appropriate dump file on
each replica.
</p>
</li>
<li class="listitem">
<p>
Use a raw data file dump and include only the specific files
and databases that you need for each replica.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
This does not work with
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
databases unless you use
<a class="link" href="innodb-parameters.html#sysvar_innodb_file_per_table">
<code class="literal">
innodb_file_per_table
</code>
</a>
.
</p>
</div>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/charset-gb18030.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="charset-gb18030">
</a>
12.10.7.2 The gb18030 Character Set
</h4>
</div>
</div>
</div>
<p>
In MySQL, the
<code class="literal">
gb18030
</code>
character set
corresponds to the
<em class="citetitle">
Chinese National Standard GB
18030-2005: Information technology — Chinese coded
character set
</em>
, which is the official character set
of the People's Republic of China (PRC).
</p>
<h5>
<a name="idm46045215559328">
</a>
Characteristics of the MySQL gb18030 Character Set
</h5>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Supports all code points defined by the GB 18030-2005
standard. Unassigned code points in the ranges
(GB+8431A439, GB+90308130) and (GB+E3329A36, GB+EF39EF39)
are treated as '
<code class="literal">
?
</code>
' (0x3F). Conversion
of unassigned code points returns '
<code class="literal">
?
</code>
'.
</p>
</li>
<li class="listitem">
<p>
Supports UPPER and LOWER conversion for all GB18030 code
points. Case folding defined by Unicode is also supported
(based on
<code class="filename">
CaseFolding-6.3.0.txt
</code>
).
</p>
</li>
<li class="listitem">
<p>
Supports Conversion of data to and from other character
sets.
</p>
</li>
<li class="listitem">
<p>
Supports SQL statements such as
<a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
<code class="literal">
SET
NAMES
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
Supports comparison between
<code class="literal">
gb18030
</code>
strings, and between
<code class="literal">
gb18030
</code>
strings
and strings of other character sets. There is a conversion
if strings have different character sets. Comparisons that
include or ignore trailing spaces are also supported.
</p>
</li>
<li class="listitem">
<p>
The private use area (U+E000, U+F8FF) in Unicode is mapped
to
<code class="literal">
gb18030
</code>
.
</p>
</li>
<li class="listitem">
<p>
There is no mapping between (U+D800, U+DFFF) and GB18030.
Attempted conversion of code points in this range returns
'
<code class="literal">
?
</code>
'.
</p>
</li>
<li class="listitem">
<p>
If an incoming sequence is illegal, an error or warning is
returned. If an illegal sequence is used in
<code class="literal">
CONVERT()
</code>
, an error is returned.
Otherwise, a warning is returned.
</p>
</li>
<li class="listitem">
<p>
For consistency with
<code class="literal">
utf8mb3
</code>
and
<code class="literal">
utf8mb4
</code>
, UPPER is not supported for
ligatures.
</p>
</li>
<li class="listitem">
<p>
Searches for ligatures also match uppercase ligatures when
using the
<code class="literal">
gb18030_unicode_520_ci
</code>
collation.
</p>
</li>
<li class="listitem">
<p>
If a character has more than one uppercase character, the
chosen uppercase character is the one whose lowercase is
the character itself.
</p>
</li>
<li class="listitem">
<p>
The minimum multibyte length is 1 and the maximum is 4.
The character set determines the length of a sequence
using the first 1 or 2 bytes.
</p>
</li>
</ul>
</div>
<h5>
<a name="idm46045215537792">
</a>
Supported Collations
</h5>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
gb18030_bin
</code>
: A binary collation.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
gb18030_chinese_ci
</code>
: The default
collation, which supports Pinyin. Sorting of non-Chinese
characters is based on the order of the original sort key.
The original sort key is
<code class="literal">
GB(UPPER(ch))
</code>
if
<code class="literal">
UPPER(ch)
</code>
exists. Otherwise, the
original sort key is
<code class="literal">
GB(ch)
</code>
. Chinese
characters are sorted according to the Pinyin collation
defined in the Unicode Common Locale Data Repository (CLDR
24). Non-Chinese characters are sorted before Chinese
characters with the exception of
<code class="literal">
GB+FE39FE39
</code>
, which is the code point
maximum.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
gb18030_unicode_520_ci
</code>
: A Unicode
collation. Use this collation if you need to ensure that
ligatures are sorted correctly.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/charset-collation-effect.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="charset-collation-effect">
</a>
12.8.6 Examples of the Effect of Collation
</h3>
</div>
</div>
</div>
<p>
<span class="bold">
<strong>
Example 1: Sorting German
Umlauts
</strong>
</span>
</p>
<p>
Suppose that column
<code class="literal">
X
</code>
in table
<code class="literal">
T
</code>
has these
<code class="literal">
latin1
</code>
column
values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-none"><div class="docs-select-all right" id="sa37754468"><div class="copy-help left">Press ⌘+C to 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">Muffler
Müller
MX Systems
MySQL</code></pre>
</div>
<p>
Suppose also that the column values are retrieved using the
following statement:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa71823285"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> X <span class="token keyword">FROM</span> T <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> X <span class="token keyword">COLLATE</span> <em class="replaceable">collation_name</em><span class="token punctuation">;</span></code></pre>
</div>
<p>
The following table shows the resulting order of the values if
we use
<code class="literal">
ORDER BY
</code>
with different collations.
</p>
<div class="informaltable">
<table summary="An example of the effect of collation, as described in the preceding text. The table shows the resulting order of values for three collations (latin1_swedish_ci, latin1_german1_ci, latin1_german2_ci) when using ORDER BY.">
<colgroup>
<col style="width: 30%"/>
<col style="width: 30%"/>
<col style="width: 30%"/>
</colgroup>
<thead>
<tr>
<th scope="col">
<code class="literal">
latin1_swedish_ci
</code>
</th>
<th scope="col">
<code class="literal">
latin1_german1_ci
</code>
</th>
<th scope="col">
<code class="literal">
latin1_german2_ci
</code>
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
Muffler
</th>
<td>
Muffler
</td>
<td>
Müller
</td>
</tr>
<tr>
<th scope="row">
MX Systems
</th>
<td>
Müller
</td>
<td>
Muffler
</td>
</tr>
<tr>
<th scope="row">
Müller
</th>
<td>
MX Systems
</td>
<td>
MX Systems
</td>
</tr>
<tr>
<th scope="row">
MySQL
</th>
<td>
MySQL
</td>
<td>
MySQL
</td>
</tr>
</tbody>
</table>
</div>
<p>
The character that causes the different sort orders in this
example is
<code class="literal">
ü
</code>
(German
<span class="quote">
“
<span class="quote">
U-umlaut
</span>
”
</span>
).
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The first column shows the result of the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
using the
Swedish/Finnish collating rule, which says that U-umlaut
sorts with Y.
</p>
</li>
<li class="listitem">
<p>
The second column shows the result of the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
using the German DIN-1
rule, which says that U-umlaut sorts with U.
</p>
</li>
<li class="listitem">
<p>
The third column shows the result of the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
using the German DIN-2
rule, which says that U-umlaut sorts with UE.
</p>
</li>
</ul>
</div>
<p>
<span class="bold">
<strong>
Example 2: Searching for German
Umlauts
</strong>
</span>
</p>
<p>
Suppose that you have three tables that differ only by the
character set and collation used:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa52958409"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token keyword">NAMES</span> utf8mb4<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> german1 <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 punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> latin1 <span class="token keyword">COLLATE</span> latin1_german1_ci<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> german2 <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 punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> latin1 <span class="token keyword">COLLATE</span> latin1_german2_ci<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> germanutf8 <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 punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4 <span class="token keyword">COLLATE</span> utf8mb4_unicode_ci<span class="token punctuation">;</span></code></pre>
</div>
<p>
Each table contains two records:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa22901894"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> german1 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">'Bar'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'Bär'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> german2 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">'Bar'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'Bär'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> germanutf8 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">'Bar'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'Bär'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Two of the above collations have an
<code class="literal">
A = Ä
</code>
equality, and one has no such equality
(
<code class="literal">
latin1_german2_ci
</code>
). For that reason,
comparisons yield the results shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56464269"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> german1 <span class="token keyword">WHERE</span> c <span class="token operator">=</span> <span class="token string">'Bär'</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>
<span class="token output"><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>
<span class="token output"><span class="token punctuation">|</span> Bar <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Bär <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 prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> german2 <span class="token keyword">WHERE</span> c <span class="token operator">=</span> <span class="token string">'Bär'</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>
<span class="token output"><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>
<span class="token output"><span class="token punctuation">|</span> Bär <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 prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> germanutf8 <span class="token keyword">WHERE</span> c <span class="token operator">=</span> <span class="token string">'Bär'</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>
<span class="token output"><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>
<span class="token output"><span class="token punctuation">|</span> Bar <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Bär <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></code></pre>
</div>
<p>
This is not a bug but rather a consequence of the sorting
properties of
<code class="literal">
latin1_german1_ci
</code>
and
<code class="literal">
utf8mb4_unicode_ci
</code>
(the sorting shown is done
according to the German DIN 5007 standard).
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/flow-control-functions.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="flow-control-functions">
</a>
14.5 Flow Control Functions
</h2>
</div>
</div>
</div>
<a class="indexterm" name="idm46045206787360">
</a>
<a class="indexterm" name="idm46045206786288">
</a>
<div class="table">
<a name="idm46045206784800">
</a>
<p class="title">
<b>
Table 14.7 Flow Control Operators
</b>
</p>
<div class="table-contents">
<table frame="box" rules="all" summary="A reference that lists flow control 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="flow-control-functions.html#operator_case">
<code class="literal">
CASE
</code>
</a>
</td>
<td>
Case operator
</td>
</tr>
<tr>
<td>
<a class="link" href="flow-control-functions.html#function_if">
<code class="literal">
IF()
</code>
</a>
</td>
<td>
If/else construct
</td>
</tr>
<tr>
<td>
<a class="link" href="flow-control-functions.html#function_ifnull">
<code class="literal">
IFNULL()
</code>
</a>
</td>
<td>
Null if/else construct
</td>
</tr>
<tr>
<td>
<a class="link" href="flow-control-functions.html#function_nullif">
<code class="literal">
NULLIF()
</code>
</a>
</td>
<td>
Return NULL if expr1 = expr2
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a name="operator_case">
</a>
<p>
<a class="link" href="flow-control-functions.html#operator_case">
<code class="literal">
CASE
<em class="replaceable">
<code>
value
</code>
</em>
WHEN
<em class="replaceable">
<code>
compare_value
</code>
</em>
THEN
<em class="replaceable">
<code>
result
</code>
</em>
[WHEN
<em class="replaceable">
<code>
compare_value
</code>
</em>
THEN
<em class="replaceable">
<code>
result
</code>
</em>
...] [ELSE
<em class="replaceable">
<code>
result
</code>
</em>
] END
</code>
</a>
</p>
<p>
<a class="link" href="flow-control-functions.html#operator_case">
<code class="literal">
CASE WHEN
<em class="replaceable">
<code>
condition
</code>
</em>
THEN
<em class="replaceable">
<code>
result
</code>
</em>
[WHEN
<em class="replaceable">
<code>
condition
</code>
</em>
THEN
<em class="replaceable">
<code>
result
</code>
</em>
...] [ELSE
<em class="replaceable">
<code>
result
</code>
</em>
] END
</code>
</a>
</p>
<a class="indexterm" name="idm46045206755040">
</a>
<p>
The first
<a class="link" href="flow-control-functions.html#operator_case">
<code class="literal">
CASE
</code>
</a>
syntax returns the
<em class="replaceable">
<code>
result
</code>
</em>
for the first
<code class="literal">
<em class="replaceable">
<code>
value
</code>
</em>
=
<em class="replaceable">
<code>
compare_value
</code>
</em>
</code>
comparison that is true. The second syntax returns the result
for the first condition that is true. If no comparison or
condition is true, the result after
<code class="literal">
ELSE
</code>
is
returned, or
<code class="literal">
NULL
</code>
if there is no
<code class="literal">
ELSE
</code>
part.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
The syntax of the
<a class="link" href="flow-control-functions.html#operator_case">
<code class="literal">
CASE
</code>
</a>
<span class="emphasis">
<em>
operator
</em>
</span>
described here differs
slightly from that of the SQL
<a class="link" href="case.html" title="15.6.5.1 CASE Statement">
<code class="literal">
CASE
</code>
</a>
<span class="emphasis">
<em>
statement
</em>
</span>
described in
<a class="xref" href="case.html" title="15.6.5.1 CASE Statement">
Section 15.6.5.1, “CASE Statement”
</a>
, for use inside stored programs. The
<a class="link" href="case.html" title="15.6.5.1 CASE Statement">
<code class="literal">
CASE
</code>
</a>
statement cannot have an
<code class="literal">
ELSE NULL
</code>
clause, and it is terminated
with
<code class="literal">
END CASE
</code>
instead of
<code class="literal">
END
</code>
.
</p>
</div>
<p>
The return type of a
<a class="link" href="flow-control-functions.html#operator_case">
<code class="literal">
CASE
</code>
</a>
expression result is the aggregated type of all result values:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
If all types are numeric, the aggregated type is also
numeric:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
If at least one argument is double precision, the
result is double precision.
</p>
</li>
<li class="listitem">
<p>
Otherwise, if at least one argument is
<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>
, the result is
<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>
.
</p>
</li>
<li class="listitem">
<p>
Otherwise, the result is an integer type (with one
exception):
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
If all integer types are all signed or all
unsigned, the result is the same sign and the
precision is the highest of all specified integer
types (that is,
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
TINYINT
</code>
</a>
,
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
SMALLINT
</code>
</a>
,
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
MEDIUMINT
</code>
</a>
,
<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>
, or
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
BIGINT
</code>
</a>
).
</p>
</li>
<li class="listitem">
<p>
If there is a combination of signed and unsigned
integer types, the result is signed and the
precision may be higher. For example, if the types
are signed
<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>
and
unsigned
<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>
, the
result is signed
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
BIGINT
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
The exception is unsigned
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
BIGINT
</code>
</a>
combined
with any signed integer type. The result is
<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>
with
sufficient precision and scale 0.
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
If all types are
<a class="link" href="bit-type.html" title="13.1.5 Bit-Value Type - BIT">
<code class="literal">
BIT
</code>
</a>
, the
result is
<a class="link" href="bit-type.html" title="13.1.5 Bit-Value Type - BIT">
<code class="literal">
BIT
</code>
</a>
. Otherwise,
<a class="link" href="bit-type.html" title="13.1.5 Bit-Value Type - BIT">
<code class="literal">
BIT
</code>
</a>
arguments are treated
similar to
<a class="link" href="integer-types.html" title="13.1.2 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT">
<code class="literal">
BIGINT
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
If all types are
<a class="link" href="year.html" title="13.2.4 The YEAR Type">
<code class="literal">
YEAR
</code>
</a>
, the
result is
<a class="link" href="year.html" title="13.2.4 The YEAR Type">
<code class="literal">
YEAR
</code>
</a>
. Otherwise,
<code class="literal">
YEAR
</code>
arguments are treated similar to
<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>
If all types are character string
(
<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>
), the result is
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
with maximum length
determined by the longest character length of the
operands.
</p>
</li>
<li class="listitem">
<p>
If all types are character or binary string, the result is
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
VARBINARY
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="set.html" title="13.3.6 The SET Type">
<code class="literal">
SET
</code>
</a>
and
<a class="link" href="enum.html" title="13.3.5 The ENUM Type">
<code class="literal">
ENUM
</code>
</a>
are treated similar to
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
; the result is
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
If all types are
<a class="link" href="json.html" title="13.5 The JSON Data Type">
<code class="literal">
JSON
</code>
</a>
, the
result is
<a class="link" href="json.html" title="13.5 The JSON Data Type">
<code class="literal">
JSON
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
If all types are temporal, the result is temporal:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; ">
<li class="listitem">
<p>
If all temporal types are
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATE
</code>
</a>
,
<a class="link" href="time.html" title="13.2.3 The TIME Type">
<code class="literal">
TIME
</code>
</a>
, or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
, the result
is
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATE
</code>
</a>
,
<a class="link" href="time.html" title="13.2.3 The TIME Type">
<code class="literal">
TIME
</code>
</a>
, or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
,
respectively.
</p>
</li>
<li class="listitem">
<p>
Otherwise, for a mix of temporal types, the result is
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
If all types are
<code class="literal">
GEOMETRY
</code>
, the result
is
<code class="literal">
GEOMETRY
</code>
.
</p>
</li>
<li class="listitem">
<p>
If any type is
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
, the
result is
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
For all other type combinations, the result is
<a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
<code class="literal">
VARCHAR
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
Literal
<code class="literal">
NULL
</code>
operands are ignored for
type aggregation.
</p>
</li>
</ul>
</div>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46420354"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">CASE</span> <span class="token number">1</span> <span class="token keyword">WHEN</span> <span class="token number">1</span> <span class="token keyword">THEN</span> <span class="token string">'one'</span>
<span class="token prompt"> -></span> <span class="token keyword">WHEN</span> <span class="token number">2</span> <span class="token keyword">THEN</span> <span class="token string">'two'</span> <span class="token keyword">ELSE</span> <span class="token string">'more'</span> <span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token string">'one'</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">CASE</span> <span class="token keyword">WHEN</span> <span class="token number">1</span><span class="token operator">></span><span class="token number">0</span> <span class="token keyword">THEN</span> <span class="token string">'true'</span> <span class="token keyword">ELSE</span> <span class="token string">'false'</span> <span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token string">'true'</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token operator">CASE</span> <span class="token datatype">BINARY</span> <span class="token string">'B'</span>
<span class="token prompt"> -></span> <span class="token keyword">WHEN</span> <span class="token string">'a'</span> <span class="token keyword">THEN</span> <span class="token number">1</span> <span class="token keyword">WHEN</span> <span class="token string">'b'</span> <span class="token keyword">THEN</span> <span class="token number">2</span> <span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token boolean">NULL</span></code></pre>
</div>
</li>
<li class="listitem">
<a name="function_if">
</a>
<p>
<a class="link" href="flow-control-functions.html#function_if">
<code class="literal">
IF(
<em class="replaceable">
<code>
expr1
</code>
</em>
,
<em class="replaceable">
<code>
expr2
</code>
</em>
,
<em class="replaceable">
<code>
expr3
</code>
</em>
)
</code>
</a>
</p>
<a class="indexterm" name="idm46045206655344">
</a>
<p>
If
<em class="replaceable">
<code>
expr1
</code>
</em>
is
<code class="literal">
TRUE
</code>
(
<code class="literal">
<em class="replaceable">
<code>
expr1
</code>
</em>
<>
0
</code>
and
<code class="literal">
<em class="replaceable">
<code>
expr1
</code>
</em>
IS
NOT NULL
</code>
),
<a class="link" href="flow-control-functions.html#function_if">
<code class="literal">
IF()
</code>
</a>
returns
<em class="replaceable">
<code>
expr2
</code>
</em>
. Otherwise, it
returns
<em class="replaceable">
<code>
expr3
</code>
</em>
.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
There is also an
<a class="link" href="if.html" title="15.6.5.2 IF Statement">
<code class="literal">
IF
</code>
</a>
<span class="emphasis">
<em>
statement
</em>
</span>
, which differs from the
<a class="link" href="flow-control-functions.html#function_if">
<code class="literal">
IF()
</code>
</a>
<span class="emphasis">
<em>
function
</em>
</span>
described here. See
<a class="xref" href="if.html" title="15.6.5.2 IF Statement">
Section 15.6.5.2, “IF Statement”
</a>
.
</p>
</div>
<p>
If only one of
<em class="replaceable">
<code>
expr2
</code>
</em>
or
<em class="replaceable">
<code>
expr3
</code>
</em>
is explicitly
<code class="literal">
NULL
</code>
, the result type of the
<a class="link" href="flow-control-functions.html#function_if">
<code class="literal">
IF()
</code>
</a>
function is the type of
the non-
<code class="literal">
NULL
</code>
expression.
</p>
<p>
The default return type of
<a class="link" href="flow-control-functions.html#function_if">
<code class="literal">
IF()
</code>
</a>
(which may matter when it is stored into a temporary table) is
calculated as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
If
<em class="replaceable">
<code>
expr2
</code>
</em>
or
<em class="replaceable">
<code>
expr3
</code>
</em>
produce a string, the
result is a string.
</p>
<p>
If
<em class="replaceable">
<code>
expr2
</code>
</em>
and
<em class="replaceable">
<code>
expr3
</code>
</em>
are both strings, the
result is case-sensitive if either string is
case-sensitive.
</p>
</li>
<li class="listitem">
<p>
If
<em class="replaceable">
<code>
expr2
</code>
</em>
or
<em class="replaceable">
<code>
expr3
</code>
</em>
produce a floating-point
value, the result is a floating-point value.
</p>
</li>
<li class="listitem">
<p>
If
<em class="replaceable">
<code>
expr2
</code>
</em>
or
<em class="replaceable">
<code>
expr3
</code>
</em>
produce an integer, the
result is an integer.
</p>
</li>
</ul>
</div>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa12775564"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">></span><span class="token number">2</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 punctuation">;</span>
<span class="token prompt"> -></span> <span class="token number">3</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator"><</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">'yes'</span><span class="token punctuation">,</span><span class="token string">'no'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token string">'yes'</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">IF</span><span class="token punctuation">(</span><span class="token function">STRCMP</span><span class="token punctuation">(</span><span class="token string">'test'</span><span class="token punctuation">,</span><span class="token string">'test1'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token string">'no'</span><span class="token punctuation">,</span><span class="token string">'yes'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token string">'no'</span></code></pre>
</div>
</li>
<li class="listitem">
<a name="function_ifnull">
</a>
<p>
<a class="link" href="flow-control-functions.html#function_ifnull">
<code class="literal">
IFNULL(
<em class="replaceable">
<code>
expr1
</code>
</em>
,
<em class="replaceable">
<code>
expr2
</code>
</em>
)
</code>
</a>
</p>
<a class="indexterm" name="idm46045206620304">
</a>
<a class="indexterm" name="idm46045206618816">
</a>
<p>
If
<em class="replaceable">
<code>
expr1
</code>
</em>
is not
<code class="literal">
NULL
</code>
,
<a class="link" href="flow-control-functions.html#function_ifnull">
<code class="literal">
IFNULL()
</code>
</a>
returns
<em class="replaceable">
<code>
expr1
</code>
</em>
; otherwise it returns
<em class="replaceable">
<code>
expr2
</code>
</em>
.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42453710"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">IFNULL</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token number">1</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">IFNULL</span><span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token number">10</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">IFNULL</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">/</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token number">10</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">IFNULL</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">/</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token string">'yes'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt"> -></span> <span class="token string">'yes'</span></code></pre>
</div>
<p>
The default return type of
<a class="link" href="flow-control-functions.html#function_ifnull">
<code class="literal">
IFNULL(
<em class="replaceable">
<code>
expr1
</code>
</em>
,
<em class="replaceable">
<code>
expr2
</code>
</em>
)
</code>
</a>
is the more
<span class="quote">
“
<span class="quote">
general
</span>
”
</span>
of the two expressions, in
the order
<code class="literal">
STRING
</code>
,
<code class="literal">
REAL
</code>
,
or
<code class="literal">
INTEGER
</code>
. Consider the case of a table
based on expressions or where MySQL must internally store a
value returned by
<a class="link" href="flow-control-functions.html#function_ifnull">
<code class="literal">
IFNULL()
</code>
</a>
in a
temporary table:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa38931563"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> tmp <span class="token keyword">SELECT</span> <span class="token function">IFNULL</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">'test'</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> test<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">DESCRIBE</span> tmp<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Field <span class="token punctuation">|</span> Type <span class="token punctuation">|</span> Null <span class="token punctuation">|</span> Key <span class="token punctuation">|</span> Default <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>
<span class="token output"><span class="token punctuation">|</span> test <span class="token punctuation">|</span> varbinary(4) <span class="token punctuation">|</span> NO <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><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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 this example, the type of the
<code class="literal">
test
</code>
column is
<a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
<code class="literal">
VARBINARY(4)
</code>
</a>
(a
string type).
</p>
</li>
<li class="listitem">
<a name="function_nullif">
</a>
<p>
<a class="link" href="flow-control-functions.html#function_nullif">
<code class="literal">
NULLIF(
<em class="replaceable">
<code>
expr1
</code>
</em>
,
<em class="replaceable">
<code>
expr2
</code>
</em>
)
</code>
</a>
</p>
<a class="indexterm" name="idm46045206591232">
</a>
<p>
Returns
<code class="literal">
NULL
</code>
if
<code class="literal">
<em class="replaceable">
<code>
expr1
</code>
</em>
=
<em class="replaceable">
<code>
expr2
</code>
</em>
</code>
is true, otherwise
returns
<em class="replaceable">
<code>
expr1
</code>
</em>
. This is the same as
<a class="link" href="flow-control-functions.html#operator_case">
<code class="literal">
CASE WHEN
<em class="replaceable">
<code>
expr1
</code>
</em>
=
<em class="replaceable">
<code>
expr2
</code>
</em>
THEN NULL ELSE
<em class="replaceable">
<code>
expr1
</code>
</em>
END
</code>
</a>
.
</p>
<p>
The return value has the same type as the first argument.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa93576609"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token function">NULLIF</span><span class="token punctuation">(</span><span class="token number">1</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 prompt"> -></span> <span class="token boolean">NULL</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token function">NULLIF</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 prompt"> -></span> <span class="token number">1</span></code></pre>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
MySQL evaluates
<em class="replaceable">
<code>
expr1
</code>
</em>
twice if
the arguments are not equal.
</p>
</div>
</li>
</ul>
</div>
<p>
For each of these functions, if the first argument contains only
characters present in the character set and collation used by the
second argument (and it is constant), the latter character set and
collation is used to make the comparison. System variable values
are handled as column values of the same character and collation.
Some queries using these functions with system variables may be
rejected with
<span class="errortext">
Illegal mix of collations
</span>
as
a result. In such cases, you should cast the system variable to
the correct character set and collation.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/information-schema-innodb-session-temp-tablespaces-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="information-schema-innodb-session-temp-tablespaces-table">
</a>
28.4.22 The INFORMATION_SCHEMA INNODB_SESSION_TEMP_TABLESPACES Table
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045076564064">
</a>
<p>
The
<a class="link" href="information-schema-innodb-session-temp-tablespaces-table.html" title="28.4.22 The INFORMATION_SCHEMA INNODB_SESSION_TEMP_TABLESPACES Table">
<code class="literal">
INNODB_SESSION_TEMP_TABLESPACES
</code>
</a>
table provides metadata about session temporary tablespaces used
for internal and user-created temporary tables.
</p>
<p>
The
<a class="link" href="information-schema-innodb-session-temp-tablespaces-table.html" title="28.4.22 The INFORMATION_SCHEMA INNODB_SESSION_TEMP_TABLESPACES Table">
<code class="literal">
INNODB_SESSION_TEMP_TABLESPACES
</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 process or session ID.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SPACE
</code>
</p>
<p>
The tablespace ID. A range of 400 thousand space IDs is
reserved for session temporary tablespaces. Session temporary
tablespaces are recreated each time the server is started.
Space IDs are not persisted when the server is shut down and
may be reused.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
PATH
</code>
</p>
<p>
The tablespace data file path. A session temporary tablespace
has an
<code class="filename">
ibt
</code>
file extension.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SIZE
</code>
</p>
<p>
The size of the tablespace, in bytes.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
STATE
</code>
</p>
<p>
The state of the tablespace.
<code class="literal">
ACTIVE
</code>
indicates that the tablespace is currently used by a session.
<code class="literal">
INACTIVE
</code>
indicates that the tablespace is
in the pool of available session temporary tablespaces.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
PURPOSE
</code>
</p>
<p>
The purpose of the tablespace.
<code class="literal">
INTRINSIC
</code>
indicates that the tablespace is used for optimized internal
temporary tables use by the optimizer.
<code class="literal">
SLAVE
</code>
indicates that the tablespace is
allocated for storing user-created temporary tables on a
replica.
<code class="literal">
USER
</code>
indicates that the tablespace
is used for user-created temporary tables.
<code class="literal">
NONE
</code>
indicates that the tablespace is not
in use.
</p>
</li>
</ul>
</div>
<h4>
<a name="idm46045076541200">
</a>
Example
</h4>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58145539"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></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_SESSION_TEMP_TABLESPACES<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> ID <span class="token punctuation">|</span> SPACE <span class="token punctuation">|</span> PATH <span class="token punctuation">|</span> SIZE <span class="token punctuation">|</span> STATE <span class="token punctuation">|</span> PURPOSE <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> 8 <span class="token punctuation">|</span> 4294566162 <span class="token punctuation">|</span> ./#innodb_temp/temp_10.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> ACTIVE <span class="token punctuation">|</span> INTRINSIC <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 8 <span class="token punctuation">|</span> 4294566161 <span class="token punctuation">|</span> ./#innodb_temp/temp_9.ibt <span class="token punctuation">|</span> 98304 <span class="token punctuation">|</span> ACTIVE <span class="token punctuation">|</span> USER <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566153 <span class="token punctuation">|</span> ./#innodb_temp/temp_1.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566154 <span class="token punctuation">|</span> ./#innodb_temp/temp_2.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566155 <span class="token punctuation">|</span> ./#innodb_temp/temp_3.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566156 <span class="token punctuation">|</span> ./#innodb_temp/temp_4.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566157 <span class="token punctuation">|</span> ./#innodb_temp/temp_5.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566158 <span class="token punctuation">|</span> ./#innodb_temp/temp_6.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566159 <span class="token punctuation">|</span> ./#innodb_temp/temp_7.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 0 <span class="token punctuation">|</span> 4294566160 <span class="token punctuation">|</span> ./#innodb_temp/temp_8.ibt <span class="token punctuation">|</span> 81920 <span class="token punctuation">|</span> INACTIVE <span class="token punctuation">|</span> NONE <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>
<h4>
<a name="idm46045076537712">
</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/fractional-seconds.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="fractional-seconds">
</a>
13.2.6 Fractional Seconds in Time Values
</h3>
</div>
</div>
</div>
<p>
MySQL has fractional seconds support for
<a class="link" href="time.html" title="13.2.3 The TIME Type">
<code class="literal">
TIME
</code>
</a>
,
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
, and
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
values, with up to
microseconds (6 digits) precision:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
To define a column that includes a fractional seconds part,
use the syntax
<code class="literal">
<em class="replaceable">
<code>
type_name
</code>
</em>
(
<em class="replaceable">
<code>
fsp
</code>
</em>
)
</code>
,
where
<em class="replaceable">
<code>
type_name
</code>
</em>
is
<a class="link" href="time.html" title="13.2.3 The TIME Type">
<code class="literal">
TIME
</code>
</a>
,
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
, or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
, and
<em class="replaceable">
<code>
fsp
</code>
</em>
is the fractional seconds
precision. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa65193861"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>t <span class="token function">TIME</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> dt <span class="token datatype">DATETIME</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The
<em class="replaceable">
<code>
fsp
</code>
</em>
value, if given, must be
in the range 0 to 6. A value of 0 signifies that there is no
fractional part. If omitted, the default precision is 0.
(This differs from the standard SQL default of 6, for
compatibility with previous MySQL versions.)
</p>
</li>
<li class="listitem">
<p>
Inserting a
<a class="link" href="time.html" title="13.2.3 The TIME Type">
<code class="literal">
TIME
</code>
</a>
,
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATE
</code>
</a>
, or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
value with a
fractional seconds part into a column of the same type but
having fewer fractional digits results in rounding. Consider
a table created and populated as follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa87503594"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> fractest<span class="token punctuation">(</span> c1 <span class="token function">TIME</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> c2 <span class="token datatype">DATETIME</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> c3 <span class="token function">TIMESTAMP</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 keyword">INSERT</span> <span class="token keyword">INTO</span> fractest <span class="token keyword">VALUES</span>
<span class="token punctuation">(</span><span class="token string">'17:51:04.777'</span><span class="token punctuation">,</span> <span class="token string">'2018-09-08 17:51:04.777'</span><span class="token punctuation">,</span> <span class="token string">'2018-09-08 17:51:04.777'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The temporal values are inserted into the table with
rounding:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99431619"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> fractest<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>
<span class="token output"><span class="token punctuation">|</span> c1 <span class="token punctuation">|</span> c2 <span class="token punctuation">|</span> c3 <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>
<span class="token output"><span class="token punctuation">|</span> 17:51:04.78 <span class="token punctuation">|</span> 2018<span class="token punctuation">-</span>09<span class="token punctuation">-</span>08 17:51:04.78 <span class="token punctuation">|</span> 2018<span class="token punctuation">-</span>09<span class="token punctuation">-</span>08 17:51:04.78 <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></code></pre>
</div>
<p>
No warning or error is given when such rounding occurs. This
behavior follows the SQL standard.
</p>
<p>
To insert the values with truncation instead, enable the
<a class="link" href="sql-mode.html#sqlmode_time_truncate_fractional">
<code class="literal">
TIME_TRUNCATE_FRACTIONAL
</code>
</a>
SQL mode:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa29361467"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">@@sql_mode</span> <span class="token operator">=</span> sys<span class="token punctuation">.</span>list_add<span class="token punctuation">(</span><span class="token variable">@@sql_mode</span><span class="token punctuation">,</span> <span class="token string">'TIME_TRUNCATE_FRACTIONAL'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
With that SQL mode enabled, the temporal values are inserted
with truncation:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40606366"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> fractest<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>
<span class="token output"><span class="token punctuation">|</span> c1 <span class="token punctuation">|</span> c2 <span class="token punctuation">|</span> c3 <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>
<span class="token output"><span class="token punctuation">|</span> 17:51:04.77 <span class="token punctuation">|</span> 2018<span class="token punctuation">-</span>09<span class="token punctuation">-</span>08 17:51:04.77 <span class="token punctuation">|</span> 2018<span class="token punctuation">-</span>09<span class="token punctuation">-</span>08 17:51:04.77 <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></code></pre>
</div>
</li>
<li class="listitem">
<p>
Functions that take temporal arguments accept values with
fractional seconds. Return values from temporal functions
include fractional seconds as appropriate. For example,
<a class="link" href="date-and-time-functions.html#function_now">
<code class="literal">
NOW()
</code>
</a>
with no argument
returns the current date and time with no fractional part,
but takes an optional argument from 0 to 6 to specify that
the return value includes a fractional seconds part of that
many digits.
</p>
</li>
<li class="listitem">
<p>
Syntax for temporal literals produces temporal values:
<code class="literal">
DATE '
<em class="replaceable">
<code>
str
</code>
</em>
'
</code>
,
<code class="literal">
TIME '
<em class="replaceable">
<code>
str
</code>
</em>
'
</code>
,
and
<code class="literal">
TIMESTAMP
'
<em class="replaceable">
<code>
str
</code>
</em>
'
</code>
, and the
ODBC-syntax equivalents. The resulting value includes a
trailing fractional seconds part if specified. Previously,
the temporal type keyword was ignored and these constructs
produced the string value. See
<a class="xref" href="date-and-time-literals.html#date-and-time-standard-sql-literals" title="Standard SQL and ODBC Date and Time Literals">
Standard SQL and ODBC Date and Time Literals
</a>
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/group-replication-responses-failure-expel.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="group-replication-responses-failure-expel">
</a>
20.7.7.1 Expel Timeout
</h4>
</div>
</div>
</div>
<p>
You can use the
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
system variable to allow additional time between the creation of
a suspicion and the expulsion of the suspect member. A suspicion
is created when one server does not receive messages from
another server, as explained in
<a class="xref" href="group-replication-failure-detection.html" title="20.1.4.2 Failure Detection">
Section 20.1.4.2, “Failure Detection”
</a>
.
</p>
<p>
There is an initial 5-second detection period before a Group
Replication group member creates a suspicion of another member
(or of itself). A group member is then expelled when another
member's suspicion of it (or its own suspicion of itself) times
out. A further short period of time might elapse after that
before the expelling mechanism detects and implements the
expulsion.
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
specifies the period of time in seconds, called the expel
timeout, that a group member waits between creating a suspicion,
and expelling the suspected member. Suspect members are listed
as
<code class="literal">
UNREACHABLE
</code>
during this waiting period,
but are not removed from the group's membership list.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
If a suspect member becomes active again before the
suspicion times out at the end of the waiting period, the
member applies all the messages that were buffered by the
remaining group members in XCom's message cache and enters
<code class="literal">
ONLINE
</code>
state, without operator
intervention. In this situation, the member is considered by
the group as the same incarnation.
</p>
</li>
<li class="listitem">
<p>
If a suspect member becomes active only after the suspicion
times out and is able to resume communications, it receives
a view where it is expelled and at that point realises it
was expelled. You can use
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_autorejoin_tries">
<code class="literal">
group_replication_autorejoin_tries
</code>
</a>
to make the member try to rejoin the group automatically at
this point. This feature is active by default in MySQL
8.4, and the member makes three auto-rejoin
attempts. If the auto-rejoin procedure does not succeed or
is not attempted, the expelled member then follows the exit
action specified by
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_exit_state_action">
<code class="literal">
group_replication_exit_state_action
</code>
</a>
.
</p>
</li>
</ul>
</div>
<p>
The waiting period before expelling a member only applies to
members that have previously been active in the group.
Non-members that were never active in the group do not get this
waiting period and are removed after the initial detection
period because they took too long to join.
</p>
<p>
If
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
is set to 0, there is no waiting period, and a suspected member
is liable for expulsion immediately after the initial 5-second
detection period ends. The default is 5, meaning that a
suspected member is liable for expulsion 5 seconds after the
5-second detection period has expired. It is not mandatory for
all members of a group to have the same setting for
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
,
but it is recommended in order to avoid unexpected expulsions.
Any member can create a suspicion of any other member, including
itself, so the effective expel timeout is that of the member
with the lowest setting.
</p>
<p>
Consider increasing the value of
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
from the default in the following scenarios:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The network is slow and the default 5 or 10 seconds before
expulsion is not long enough for group members to always
exchange at least one message.
</p>
</li>
<li class="listitem">
<p>
The network sometimes has transient outages and you want to
avoid unnecessary expulsions and primary member changes at
these times.
</p>
</li>
<li class="listitem">
<p>
The network is not under your direct control and you want to
minimize the need for operator intervention.
</p>
</li>
<li class="listitem">
<p>
A temporary network outage is expected and you do not want
some or all of the members to be expelled due to this.
</p>
</li>
<li class="listitem">
<p>
An individual machine is experiencing a slowdown and you do
not want it to be expelled from the group.
</p>
</li>
</ul>
</div>
<p>
You can specify an expel timeout up to a maximum of 3600 seconds
(1 hour). It is important to ensure that XCom's message cache is
sufficiently large to contain the expected volume of messages in
your specified time period, plus the initial 5-second detection
period, otherwise members cannot reconnect. You can adjust the
cache size limit using the
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_message_cache_size">
<code class="literal">
group_replication_message_cache_size
</code>
</a>
system variable. For more information, see
<a class="xref" href="group-replication-performance-xcom-cache.html" title="20.7.6 XCom Cache Management">
Section 20.7.6, “XCom Cache Management”
</a>
.
</p>
<p>
If any members in a group are currently under suspicion, the
group membership cannot be reconfigured (by adding or removing
members or electing a new leader). If group membership changes
need to be implemented while one or more members are under
suspicion, and you want the suspect members to remain in the
group, take any actions required to make the members active
again, if that is possible. If you cannot make the members
active again and you want them to be expelled from the group,
you can force the suspicions to time out immediately. Do this by
changing the value of
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
on any active members to a value lower than the time that has
already elapsed since the suspicions were created. The suspect
members then become liable for expulsion immediately.
</p>
<p>
If a replication group member stops unexpectedly and is
immediately restarted (for example, because it was started with
<code class="literal">
mysqld_safe
</code>
), it automatically attempts to
rejoin the group if
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_start_on_boot">
<code class="literal">
group_replication_start_on_boot=on
</code>
</a>
is set. In this situation, it is possible for the restart and
rejoin attempt to take place before the member's previous
incarnation has been expelled from the group, in which case the
member cannot rejoin. Group Replication automatically uses a
Group Communication System (GCS) feature to retry the rejoin
attempt for the member 10 times, with a 5-second interval
between each retry. This should cover most cases and allow
enough time for the previous incarnation to be expelled from the
group, letting the member rejoin. Note that if the
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
system variable is set to specify a longer waiting period before
the member is expelled, the automatic rejoin attempts might
still not succeed.
</p>
<p>
For alternative mitigation strategies to avoid unnecessary
expulsions where the
<a class="link" href="group-replication-system-variables.html#sysvar_group_replication_member_expel_timeout">
<code class="literal">
group_replication_member_expel_timeout
</code>
</a>
system variable is not available, see
<a class="xref" href="group-replication-limitations.html" title="20.3.2 Group Replication Limitations">
Section 20.3.2, “Group Replication Limitations”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/installing.html | <div id="docs-body">
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title">
<a name="installing">
</a>
Chapter 2 Installing MySQL
</h1>
</div>
</div>
</div>
<div class="toc">
<p>
<b>
Table of Contents
</b>
</p>
<dl class="toc">
<dt>
<span class="section">
<a href="general-installation-issues.html">
2.1 General Installation Guidance
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="platform-support.html">
2.1.1 Supported Platforms
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="which-version.html">
2.1.2 Which MySQL Version and Distribution to Install
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="getting-mysql.html">
2.1.3 How to Get MySQL
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="verifying-package-integrity.html">
2.1.4 Verifying Package Integrity Using MD5 Checksums or GnuPG
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="installation-layouts.html">
2.1.5 Installation Layouts
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="compiler-characteristics.html">
2.1.6 Compiler-Specific Build Characteristics
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="binary-installation.html">
2.2 Installing MySQL on Unix/Linux Using Generic Binaries
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="windows-installation.html">
2.3 Installing MySQL on Microsoft Windows
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="windows-choosing-package.html">
2.3.1 Choosing an Installation Package
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-configurator.html">
2.3.2 Configuration: Using MySQL Configurator
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="windows-install-archive.html">
2.3.3 Configuration: Manually
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="windows-troubleshooting.html">
2.3.4 Troubleshooting a Microsoft Windows MySQL Server Installation
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="windows-postinstallation.html">
2.3.5 Windows Postinstallation Procedures
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="windows-restrictions.html">
2.3.6 Windows Platform Restrictions
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="macos-installation.html">
2.4 Installing MySQL on macOS
</a>
</span>
</dt>
<dd>
<dl>
<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>
</dd>
<dt>
<span class="section">
<a href="linux-installation.html">
2.5 Installing MySQL on Linux
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="linux-installation-yum-repo.html">
2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-apt-repo.html">
2.5.2 Installing MySQL on Linux Using the MySQL APT Repository
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-sles-repo.html">
2.5.3 Using the MySQL SLES Repository
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-rpm.html">
2.5.4 Installing MySQL on Linux Using RPM Packages from Oracle
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-debian.html">
2.5.5 Installing MySQL on Linux Using Debian Packages from Oracle
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-docker.html">
2.5.6 Deploying MySQL on Linux with Docker Containers
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-native.html">
2.5.7 Installing MySQL on Linux from the Native Software Repositories
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="linux-installation-juju.html">
2.5.8 Installing MySQL on Linux with Juju
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="using-systemd.html">
2.5.9 Managing MySQL Server with systemd
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="uln-installation.html">
2.6 Installing MySQL Using Unbreakable Linux Network (ULN)
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="solaris-installation.html">
2.7 Installing MySQL on Solaris
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="solaris-installation-pkg.html">
2.7.1 Installing MySQL on Solaris Using a Solaris PKG
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="source-installation.html">
2.8 Installing MySQL from Source
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="source-installation-methods.html">
2.8.1 Source Installation Methods
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="source-installation-prerequisites.html">
2.8.2 Source Installation Prerequisites
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="source-installation-layout.html">
2.8.3 MySQL Layout for Source Installation
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="installing-source-distribution.html">
2.8.4 Installing MySQL Using a Standard Source Distribution
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="installing-development-tree.html">
2.8.5 Installing MySQL Using a Development Source Tree
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="source-ssl-library-configuration.html">
2.8.6 Configuring SSL Library Support
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="source-configuration-options.html">
2.8.7 MySQL Source-Configuration Options
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="compilation-problems.html">
2.8.8 Dealing with Problems Compiling MySQL
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="source-configuration-third-party.html">
2.8.9 MySQL Configuration and Third-Party Tools
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="source-installation-doxygen.html">
2.8.10 Generating MySQL Doxygen Documentation Content
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="postinstallation.html">
2.9 Postinstallation Setup and Testing
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="data-directory-initialization.html">
2.9.1 Initializing the Data Directory
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="starting-server.html">
2.9.2 Starting the Server
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="testing-server.html">
2.9.3 Testing the Server
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="default-privileges.html">
2.9.4 Securing the Initial MySQL Account
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="automatic-start.html">
2.9.5 Starting and Stopping MySQL Automatically
</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="perl-support.html">
2.10 Perl Installation Notes
</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="perl-installation.html">
2.10.1 Installing Perl on Unix
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="activestate-perl.html">
2.10.2 Installing ActiveState Perl on Windows
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="perl-support-problems.html">
2.10.3 Problems Using the Perl DBI/DBD Interface
</a>
</span>
</dt>
</dl>
</dd>
</dl>
</div>
<a class="indexterm" name="idm46045333064112">
</a>
<p>
This chapter describes how to obtain and install MySQL. A summary of
the procedure follows and later sections provide the details. If you
plan to upgrade an existing version of MySQL to a newer version
rather than install MySQL for the first time, see
<a class="xref" href="upgrading.html" title="Chapter 3 Upgrading MySQL">
Chapter 3,
<i>
Upgrading MySQL
</i>
</a>
, for information about upgrade
procedures and about issues that you should consider before
upgrading.
</p>
<p>
If you are interested in migrating to MySQL from another database
system, see
<a class="xref" href="faqs-migration.html" title="A.8 MySQL 8.4 FAQ: Migration">
Section A.8, “MySQL 8.4 FAQ: Migration”
</a>
, which contains answers
to some common questions concerning migration issues.
</p>
<p>
Installation of MySQL generally follows the steps outlined here:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
<span class="bold">
<strong>
Determine whether MySQL runs and is
supported on your platform.
</strong>
</span>
</p>
<p>
Please note that not all platforms are equally suitable for
running MySQL, and that not all platforms on which MySQL is
known to run are officially supported by Oracle Corporation. For
information about those platforms that are officially supported,
see
<a class="ulink" href="https://www.mysql.com/support/supportedplatforms/database.html" target="_blank">
https://www.mysql.com/support/supportedplatforms/database.html
</a>
on the MySQL
website.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
Choose which track to install.
</strong>
</span>
</p>
<p>
MySQL offers an
<a class="link" href="glossary.html#glos_lts_series" title="LTS Series">
LTS
series
</a>
, such as MySQL 8.4, and an
<a class="link" href="glossary.html#glos_innovation_series" title="Innovation Series">
Innovation series
</a>
.
They address different use cases as described at
<a class="xref" href="mysql-releases.html" title="1.3 MySQL Releases: Innovation and LTS">
Section 1.3, “MySQL Releases: Innovation and LTS”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
Choose which distribution to
install.
</strong>
</span>
</p>
<p>
Several versions of MySQL are available, and most are available
in several distribution formats. You can choose from
pre-packaged distributions containing binary (precompiled)
programs or source code. When in doubt, use a binary
distribution. Oracle also provides access to the MySQL source
code for those who want to see recent developments and test new
code. To determine which version and type of distribution you
should use, see
<a class="xref" href="which-version.html" title="2.1.2 Which MySQL Version and Distribution to Install">
Section 2.1.2, “Which MySQL Version and Distribution to Install”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
Download the distribution that you want to
install.
</strong>
</span>
</p>
<p>
For instructions, see
<a class="xref" href="getting-mysql.html" title="2.1.3 How to Get MySQL">
Section 2.1.3, “How to Get MySQL”
</a>
. To verify
the integrity of the distribution, use the instructions in
<a class="xref" href="verifying-package-integrity.html" title="2.1.4 Verifying Package Integrity Using MD5 Checksums or GnuPG">
Section 2.1.4, “Verifying Package Integrity Using MD5 Checksums or GnuPG”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
Install the distribution.
</strong>
</span>
</p>
<p>
To install MySQL from a binary distribution, use the
instructions in
<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>
.
Alternatively, use the
<a class="ulink" href="/doc/mysql-secure-deployment-guide/en/" target="_top">
Secure
Deployment Guide
</a>
, which provides procedures for
deploying a generic binary distribution of MySQL Enterprise Edition Server with
features for managing the security of your MySQL installation.
</p>
<p>
To install MySQL from a source distribution or from the current
development source tree, use the instructions in
<a class="xref" href="source-installation.html" title="2.8 Installing MySQL from Source">
Section 2.8, “Installing MySQL from Source”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
Perform any necessary postinstallation
setup.
</strong>
</span>
</p>
<p>
After installing MySQL, see
<a class="xref" href="postinstallation.html" title="2.9 Postinstallation Setup and Testing">
Section 2.9, “Postinstallation Setup and Testing”
</a>
,
for information about making sure the MySQL server is working
properly. Also refer to the information provided in
<a class="xref" href="default-privileges.html" title="2.9.4 Securing the Initial MySQL Account">
Section 2.9.4, “Securing the Initial MySQL Account”
</a>
. This section describes how
to secure the initial MySQL
<code class="literal">
root
</code>
user
account,
<span class="emphasis">
<em>
which has no password until you assign
one
</em>
</span>
. The section applies whether you install MySQL
using a binary or source distribution.
</p>
</li>
<li class="listitem">
<p>
If you want to run the MySQL benchmark scripts, Perl support for
MySQL must be available. See
<a class="xref" href="perl-support.html" title="2.10 Perl Installation Notes">
Section 2.10, “Perl Installation Notes”
</a>
.
</p>
</li>
</ol>
</div>
<p>
Instructions for installing MySQL on different platforms and
environments is available on a platform by platform basis:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<span class="bold">
<strong>
Unix, Linux
</strong>
</span>
</p>
<p>
For instructions on installing MySQL on most Linux and Unix
platforms using a generic binary (for example, a
<code class="filename">
.tar.gz
</code>
package), see
<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>
For information on building MySQL entirely from the source code
distributions or the source code repositories, see
<a class="xref" href="source-installation.html" title="2.8 Installing MySQL from Source">
Section 2.8, “Installing MySQL from Source”
</a>
</p>
<p>
For specific platform help on installation, configuration, and
building from source see the corresponding platform section:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
Linux, including notes on distribution specific methods, see
<a class="xref" href="linux-installation.html" title="2.5 Installing MySQL on Linux">
Section 2.5, “Installing MySQL on Linux”
</a>
.
</p>
</li>
<li class="listitem">
<p>
IBM AIX, see
<a class="xref" href="solaris-installation.html" title="2.7 Installing MySQL on Solaris">
Section 2.7, “Installing MySQL on Solaris”
</a>
.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
Microsoft Windows
</strong>
</span>
</p>
<p>
For instructions on installing MySQL on Microsoft Windows, using
either the MSI installer or Zipped binary, see
<a class="xref" href="windows-installation.html" title="2.3 Installing MySQL on Microsoft Windows">
Section 2.3, “Installing MySQL on Microsoft Windows”
</a>
.
</p>
<p>
For details and instructions on building MySQL from source code,
see
<a class="xref" href="source-installation.html" title="2.8 Installing MySQL from Source">
Section 2.8, “Installing MySQL from Source”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<span class="bold">
<strong>
macOS
</strong>
</span>
</p>
<p>
For installation on macOS, including using both the binary
package and native PKG formats, see
<a class="xref" href="macos-installation.html" title="2.4 Installing MySQL on macOS">
Section 2.4, “Installing MySQL on macOS”
</a>
.
</p>
<p>
For information on making use of an macOS Launch Daemon to
automatically start and stop MySQL, see
<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>
.
</p>
<p>
For information on the MySQL Preference Pane, see
<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>
.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-ndbinfo-error-messages.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="mysql-cluster-ndbinfo-error-messages">
</a>
25.6.17.34 The ndbinfo error_messages Table
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045089331632">
</a>
<p>
The
<code class="literal">
error_messages
</code>
table provides information
about
</p>
<p>
The
<code class="literal">
error_messages
</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">
error_code
</code>
</p>
<p>
Numeric error code
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
error_description
</code>
</p>
<p>
Description of error
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
error_status
</code>
</p>
<p>
Error status code
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
error_classification
</code>
</p>
<p>
Error classification code
</p>
</li>
</ul>
</div>
<h5>
<a name="idm46045089319808">
</a>
Notes
</h5>
<p>
<code class="literal">
error_code
</code>
is a numeric NDB error code. This
is the same error code that can be supplied to
<a class="link" href="mysql-cluster-programs-ndb-perror.html" title="25.5.16 ndb_perror — Obtain NDB Error Message Information">
<span class="command">
<strong>
ndb_perror
</strong>
</span>
</a>
.
</p>
<p>
<code class="literal">
error_description
</code>
provides a basic
description of the condition causing the error.
</p>
<p>
The
<code class="literal">
error_status
</code>
column provides status
information relating to the error. Possible values for this
column are listed here:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
No error
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Illegal connect string
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Illegal server handle
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Illegal reply from server
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Illegal number of nodes
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Illegal node status
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Out of memory
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Management server not connected
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Could not connect to socket
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Start failed
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Stop failed
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Restart failed
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Could not start backup
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Could not abort backup
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Could not enter single user mode
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Could not exit single user mode
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Failed to complete configuration change
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Failed to get configuration
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Usage error
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Success
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Permanent error
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Temporary error
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Unknown result
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Temporary error, restart node
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Permanent error, external action needed
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Ndbd file system error, restart node
initial
</code>
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Unknown
</code>
</p>
</li>
</ul>
</div>
<p>
The error_classification column shows the error classification.
See
<a class="ulink" href="/doc/ndbapi/en/ndb-error-classifications.html" target="_top">
NDB Error Classifications
</a>
, for information
about classification codes and their meanings.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-semisync.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="replication-semisync">
</a>
19.4.10 Semisynchronous Replication
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="replication-semisync-installation.html">
19.4.10.1 Installing Semisynchronous Replication
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-semisync-interface.html">
19.4.10.2 Configuring Semisynchronous Replication
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-semisync-monitoring.html">
19.4.10.3 Semisynchronous Replication Monitoring
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045136272896">
</a>
<a class="indexterm" name="idm46045136271840">
</a>
<p>
In addition to the built-in asynchronous replication, MySQL
8.4 supports an interface to semisynchronous
replication that is implemented by plugins. This section discusses
what semisynchronous replication is and how it works. The
following sections cover the administrative interface to
semisynchronous replication and how to install, configure, and
monitor it.
</p>
<p>
MySQL replication by default is asynchronous. The source writes
events to its binary log and replicas request them when they are
ready. The source does not know whether or when a replica has
retrieved and processed the transactions, and there is no
guarantee that any event ever reaches any replica. With
asynchronous replication, if the source crashes, transactions that
it has committed might not have been transmitted to any replica.
Failover from source to replica in this case might result in
failover to a server that is missing transactions relative to the
source.
</p>
<p>
With fully synchronous replication, when a source commits a
transaction, all replicas have also committed the transaction
before the source returns to the session that performed the
transaction. Fully synchronous replication means failover from the
source to any replica is possible at any time. The drawback of
fully synchronous replication is that there might be a lot of
delay to complete a transaction.
</p>
<p>
Semisynchronous replication falls between asynchronous and fully
synchronous replication. The source waits until at least one
replica has received and logged the events (the required number of
replicas is configurable), and then commits the transaction. The
source does not wait for all replicas to acknowledge receipt, and
it requires only an acknowledgement from the replicas, not that
the events have been fully executed and committed on the replica
side. Semisynchronous replication therefore guarantees that if the
source crashes, all the transactions that it has committed have
been transmitted to at least one replica.
</p>
<p>
Compared to asynchronous replication, semisynchronous replication
provides improved data integrity, because when a commit returns
successfully, it is known that the data exists in at least two
places. Until a semisynchronous source receives acknowledgment
from the required number of replicas, the transaction is on hold
and not committed.
</p>
<p>
Compared to fully synchronous replication, semisynchronous
replication is faster, because it can be configured to balance
your requirements for data integrity (the number of replicas
acknowledging receipt of the transaction) with the speed of
commits, which are slower due to the need to wait for replicas.
</p>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Important
</div>
<p>
With semisynchronous replication, if the source crashes and a
failover to a replica is carried out, the failed source should
not be reused as the replication source, and should be
discarded. It could have transactions that were not acknowledged
by any replica, which were therefore not committed before the
failover.
</p>
<p>
If your goal is to implement a fault-tolerant replication
topology where all the servers receive the same transactions in
the same order, and a server that crashes can rejoin the group
and be brought up to date automatically, you can use Group
Replication to achieve this. For information, see
<a class="xref" href="group-replication.html" title="Chapter 20 Group Replication">
Chapter 20,
<i>
Group Replication
</i>
</a>
.
</p>
</div>
<p>
The performance impact of semisynchronous replication compared to
asynchronous replication is the tradeoff for increased data
integrity. The amount of slowdown is at least the TCP/IP roundtrip
time to send the commit to the replica and wait for the
acknowledgment of receipt by the replica. This means that
semisynchronous replication works best for close servers
communicating over fast networks, and worst for distant servers
communicating over slow networks. Semisynchronous replication also
places a rate limit on busy sessions by constraining the speed at
which binary log events can be sent from source to replica. When
one user is too busy, this slows it down, which can be useful in
some deployment situations.
</p>
<p>
Semisynchronous replication between a source and its replicas
operates as follows:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
A replica indicates whether it is semisynchronous-capable when
it connects to the source.
</p>
</li>
<li class="listitem">
<p>
If semisynchronous replication is enabled on the source side
and there is at least one semisynchronous replica, a thread
that performs a transaction commit on the source blocks and
waits until at least one semisynchronous replica acknowledges
that it has received all events for the transaction, or until
a timeout occurs.
</p>
</li>
<li class="listitem">
<p>
The replica acknowledges receipt of a transaction's events
only after the events have been written to its relay log and
flushed to disk.
</p>
</li>
<li class="listitem">
<p>
If a timeout occurs without any replica having acknowledged
the transaction, the source reverts to asynchronous
replication. When at least one semisynchronous replica catches
up, the source returns to semisynchronous replication.
</p>
</li>
<li class="listitem">
<p>
Semisynchronous replication must be enabled on both the source
and replica sides. If semisynchronous replication is disabled
on the source, or enabled on the source but on no replicas,
the source uses asynchronous replication.
</p>
</li>
</ul>
</div>
<p>
While the source is blocking (waiting for acknowledgment from a
replica), it does not return to the session that performed the
transaction. When the block ends, the source returns to the
session, which then can proceed to execute other statements. At
this point, the transaction has committed on the source side, and
receipt of its events has been acknowledged by at least one
replica. The number of replica acknowledgments the source must
receive per transaction before returning to the session is
configurable, and defaults to one acknowledgement (see
<a class="xref" href="replication-semisync-interface.html" title="19.4.10.2 Configuring Semisynchronous Replication">
Section 19.4.10.2, “Configuring Semisynchronous Replication”
</a>
).
</p>
<p>
Blocking also occurs after rollbacks that are written to the
binary log, which occurs when a transaction that modifies
nontransactional tables is rolled back. The rolled-back
transaction is logged even though it has no effect for
transactional tables because the modifications to the
nontransactional tables cannot be rolled back and must be sent to
replicas.
</p>
<p>
For statements that do not occur in transactional context (that
is, when no transaction has been started with
<a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
<code class="literal">
START
TRANSACTION
</code>
</a>
or
<a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
<code class="literal">
SET autocommit =
0
</code>
</a>
), autocommit is enabled and each statement commits
implicitly. With semisynchronous replication, the source blocks
for each such statement, just as it does for explicit transaction
commits.
</p>
<p>
By default, the source waits for replica acknowledgment of the
transaction receipt after syncing the binary log to disk, but
before committing the transaction to the storage engine. As an
alternative, you can configure the source so that the source waits
for replica acknowledgment after committing the transaction to the
storage engine, using the
<a class="link" href="replication-options-source.html#sysvar_rpl_semi_sync_source_wait_point">
<code class="literal">
rpl_semi_sync_source_wait_point
</code>
</a>
system variable. This setting affects the replication
characteristics and the data that clients can see on the source.
For more information, see
<a class="xref" href="replication-semisync-interface.html" title="19.4.10.2 Configuring Semisynchronous Replication">
Section 19.4.10.2, “Configuring Semisynchronous Replication”
</a>
.
</p>
<p>
You can improve the performance of semisynchronous replication by
enabling the system variables
<a class="link" href="replication-options-replica.html#sysvar_replication_sender_observe_commit_only">
<code class="literal">
replication_sender_observe_commit_only
</code>
</a>
,
which limits callbacks, and
<a class="link" href="replication-options-replica.html#sysvar_replication_optimize_for_static_plugin_config">
<code class="literal">
replication_optimize_for_static_plugin_config
</code>
</a>
,
which adds shared locks and avoids unnecessary lock acquisitions.
These settings help as the number of replicas increases, because
contention for locks can slow down performance. Semisynchronous
replication source servers can also get performance benefits from
enabling these system variables, because they use the same locking
mechanisms as the replicas.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/rewriter-query-rewrite-plugin-reference.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="rewriter-query-rewrite-plugin-reference">
</a>
7.6.4.3 Rewriter Query Rewrite Plugin Reference
</h4>
</div>
</div>
</div>
<p>
The following discussion serves as a reference to these elements
associated with the
<code class="literal">
Rewriter
</code>
query rewrite
plugin:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The
<code class="literal">
Rewriter
</code>
rules table in the
<code class="literal">
query_rewrite
</code>
database
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Rewriter
</code>
procedures and functions
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
Rewriter
</code>
system and status variables
</p>
</li>
</ul>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="rewriter-query-rewrite-plugin-table">
</a>
7.6.4.3.1 Rewriter Query Rewrite Plugin Rules Table
</h5>
</div>
</div>
</div>
<p>
The
<code class="literal">
rewrite_rules
</code>
table in the
<code class="literal">
query_rewrite
</code>
database provides persistent
storage for the rules that the
<code class="literal">
Rewriter
</code>
plugin uses to decide whether to rewrite statements.
</p>
<p>
Users communicate with the plugin by modifying the set of
rules stored in this table. The plugin communicates
information to users by setting the table's
<code class="literal">
message
</code>
column.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
The rules table is loaded into the plugin by the
<code class="literal">
flush_rewrite_rules
</code>
stored procedure.
Unless that procedure has been called following the most
recent table modification, the table contents do not
necessarily correspond to the set of rules the plugin is
using.
</p>
</div>
<p>
The
<code class="literal">
rewrite_rules
</code>
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 rule ID. This column is the table primary key. You can
use the ID to uniquely identify any rule.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
pattern
</code>
</p>
<p>
The template that indicates the pattern for statements
that the rule matches. Use
<code class="literal">
?
</code>
to
represent parameter markers that match data values.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
pattern_database
</code>
</p>
<p>
The database used to match unqualified table names in
statements. Qualified table names in statements match
qualified names in the pattern if corresponding database
and table names are identical. Unqualified table names in
statements match unqualified names in the pattern only if
the default database is the same as
<code class="literal">
pattern_database
</code>
and the table names
are identical.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
replacement
</code>
</p>
<p>
The template that indicates how to rewrite statements
matching the
<code class="literal">
pattern
</code>
column value. Use
<code class="literal">
?
</code>
to represent parameter markers that
match data values. In rewritten statements, the plugin
replaces
<code class="literal">
?
</code>
parameter markers in
<code class="literal">
replacement
</code>
using data values matched
by the corresponding markers in
<code class="literal">
pattern
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
enabled
</code>
</p>
<p>
Whether the rule is enabled. Load operations (performed by
invoking the
<code class="literal">
flush_rewrite_rules()
</code>
stored procedure) load the rule from the table into the
<code class="literal">
Rewriter
</code>
in-memory cache only if this
column is
<code class="literal">
YES
</code>
.
</p>
<p>
This column makes it possible to deactivate a rule without
removing it: Set the column to a value other than
<code class="literal">
YES
</code>
and reload the table into the
plugin.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
message
</code>
</p>
<p>
The plugin uses this column for communicating with users.
If no error occurs when the rules table is loaded into
memory, the plugin sets the
<code class="literal">
message
</code>
column to
<code class="literal">
NULL
</code>
. A
non-
<code class="literal">
NULL
</code>
value indicates an error and
the column contents are the error message. Errors can
occur under these circumstances:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
Either the pattern or the replacement is an incorrect
SQL statement that produces syntax errors.
</p>
</li>
<li class="listitem">
<p>
The replacement contains more
<code class="literal">
?
</code>
parameter markers than the pattern.
</p>
</li>
</ul>
</div>
<p>
If a load error occurs, the plugin also sets the
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_reload_error">
<code class="literal">
Rewriter_reload_error
</code>
</a>
status variable to
<code class="literal">
ON
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
pattern_digest
</code>
</p>
<p>
This column is used for debugging and diagnostics. If the
column exists when the rules table is loaded into memory,
the plugin updates it with the pattern digest. This column
may be useful if you are trying to determine why some
statement fails to be rewritten.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
normalized_pattern
</code>
</p>
<p>
This column is used for debugging and diagnostics. If the
column exists when the rules table is loaded into memory,
the plugin updates it with the normalized form of the
pattern. This column may be useful if you are trying to
determine why some statement fails to be rewritten.
</p>
</li>
</ul>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="rewriter-query-rewrite-plugin-routines">
</a>
7.6.4.3.2 Rewriter Query Rewrite Plugin Procedures and Functions
</h5>
</div>
</div>
</div>
<p>
<code class="literal">
Rewriter
</code>
plugin operation uses a stored
procedure that loads the rules table into its in-memory cache,
and a helper loadable function. Under normal operation, users
invoke only the stored procedure. The function is intended to
be invoked by the stored procedure, not directly by users.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="function_flush-rewrite-rules">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#function_flush-rewrite-rules">
<code class="literal">
flush_rewrite_rules()
</code>
</a>
</p>
<a class="indexterm" name="idm46045256368400">
</a>
<a class="indexterm" name="idm46045256367360">
</a>
<p>
This stored procedure uses the
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#function_load-rewrite-rules">
<code class="literal">
load_rewrite_rules()
</code>
</a>
function to load the contents of the
<code class="literal">
rewrite_rules
</code>
table into the
<code class="literal">
Rewriter
</code>
in-memory cache.
</p>
<p>
Calling
<code class="literal">
flush_rewrite_rules()
</code>
implies
<a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
<code class="literal">
COMMIT
</code>
</a>
.
</p>
<p>
Invoke this procedure after you modify the rules table to
cause the plugin to update its cache from the new table
contents. If any errors occur, the plugin sets the
<code class="literal">
message
</code>
column for the appropriate rule
rows in the table and sets the
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_reload_error">
<code class="literal">
Rewriter_reload_error
</code>
</a>
status variable to
<code class="literal">
ON
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="function_load-rewrite-rules">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#function_load-rewrite-rules">
<code class="literal">
load_rewrite_rules()
</code>
</a>
</p>
<a class="indexterm" name="idm46045256354352">
</a>
<a class="indexterm" name="idm46045256353312">
</a>
<p>
This function is a helper routine used by the
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#function_flush-rewrite-rules">
<code class="literal">
flush_rewrite_rules()
</code>
</a>
stored procedure.
</p>
</li>
</ul>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="rewriter-query-rewrite-plugin-system-variables">
</a>
7.6.4.3.3 Rewriter Query Rewrite Plugin System Variables
</h5>
</div>
</div>
</div>
<p>
The
<code class="literal">
Rewriter
</code>
query rewrite plugin supports
the following system variables. These variables are available
only if the plugin is installed (see
<a class="xref" href="rewriter-query-rewrite-plugin-installation.html" title="7.6.4.1 Installing or Uninstalling the Rewriter Query Rewrite Plugin">
Section 7.6.4.1, “Installing or Uninstalling the Rewriter Query Rewrite Plugin”
</a>
).
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="sysvar_rewriter_enabled">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled">
<code class="literal">
rewriter_enabled
</code>
</a>
</p>
<a class="indexterm" name="idm46045256343936">
</a>
<a class="indexterm" name="idm46045256342848">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for rewriter_enabled">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled">
rewriter_enabled
</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>
<tr>
<th>
Valid Values
</th>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Whether the
<code class="literal">
Rewriter
</code>
query rewrite
plugin is enabled.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_rewriter_enabled_for_threads_without_privilege_checks">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled_for_threads_without_privilege_checks">
<code class="literal">
rewriter_enabled_for_threads_without_privilege_checks
</code>
</a>
</p>
<a class="indexterm" name="idm46045256317392">
</a>
<a class="indexterm" name="idm46045256316288">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for rewriter_enabled_for_threads_without_privilege_checks">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled_for_threads_without_privilege_checks">
rewriter_enabled_for_threads_without_privilege_checks
</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>
<tr>
<th>
Valid Values
</th>
<td>
<code class="literal">
OFF
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Whether to apply rewrites for replication threads which
execute with privilege checks disabled. If set to
<code class="literal">
OFF
</code>
, such rewrites are skipped.
Requires the
<a class="link" href="privileges-provided.html#priv_system-variables-admin">
<code class="literal">
SYSTEM_VARIABLES_ADMIN
</code>
</a>
privilege or
<a class="link" href="privileges-provided.html#priv_super">
<code class="literal">
SUPER
</code>
</a>
privilege to set.
</p>
<p>
This variable has no effect if
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled">
<code class="literal">
rewriter_enabled
</code>
</a>
is
<code class="literal">
OFF
</code>
.
</p>
</li>
<li class="listitem">
<p>
<a name="sysvar_rewriter_verbose">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_verbose">
<code class="literal">
rewriter_verbose
</code>
</a>
</p>
<a class="indexterm" name="idm46045256286016">
</a>
<a class="indexterm" name="idm46045256284928">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for rewriter_verbose">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
System Variable
</th>
<td>
<code class="literal">
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_verbose">
rewriter_verbose
</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>
</tbody>
</table>
</div>
<p>
For internal use.
</p>
</li>
</ul>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h5 class="title">
<a name="rewriter-query-rewrite-plugin-status-variables">
</a>
7.6.4.3.4 Rewriter Query Rewrite Plugin Status Variables
</h5>
</div>
</div>
</div>
<p>
The
<code class="literal">
Rewriter
</code>
query rewrite plugin supports
the following status variables. These variables are available
only if the plugin is installed (see
<a class="xref" href="rewriter-query-rewrite-plugin-installation.html" title="7.6.4.1 Installing or Uninstalling the Rewriter Query Rewrite Plugin">
Section 7.6.4.1, “Installing or Uninstalling the Rewriter Query Rewrite Plugin”
</a>
).
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="statvar_Rewriter_number_loaded_rules">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_number_loaded_rules">
<code class="literal">
Rewriter_number_loaded_rules
</code>
</a>
</p>
<a class="indexterm" name="idm46045256261680">
</a>
<a class="indexterm" name="idm46045256260576">
</a>
<p>
The number of rewrite plugin rewrite rules successfully
loaded from the
<code class="literal">
rewrite_rules
</code>
table
into memory for use by the
<code class="literal">
Rewriter
</code>
plugin.
</p>
</li>
<li class="listitem">
<p>
<a name="statvar_Rewriter_number_reloads">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_number_reloads">
<code class="literal">
Rewriter_number_reloads
</code>
</a>
</p>
<a class="indexterm" name="idm46045256254576">
</a>
<a class="indexterm" name="idm46045256253536">
</a>
<p>
The number of times the
<code class="literal">
rewrite_rules
</code>
table has been loaded into the in-memory cache used by the
<code class="literal">
Rewriter
</code>
plugin.
</p>
</li>
<li class="listitem">
<p>
<a name="statvar_Rewriter_number_rewritten_queries">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_number_rewritten_queries">
<code class="literal">
Rewriter_number_rewritten_queries
</code>
</a>
</p>
<a class="indexterm" name="idm46045256247488">
</a>
<a class="indexterm" name="idm46045256246448">
</a>
<p>
The number of queries rewritten by the
<code class="literal">
Rewriter
</code>
query rewrite plugin since it
was loaded.
</p>
</li>
<li class="listitem">
<p>
<a name="statvar_Rewriter_reload_error">
</a>
<a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_reload_error">
<code class="literal">
Rewriter_reload_error
</code>
</a>
</p>
<a class="indexterm" name="idm46045256241200">
</a>
<a class="indexterm" name="idm46045256240160">
</a>
<p>
Whether an error occurred the most recent time that the
<code class="literal">
rewrite_rules
</code>
table was loaded into the
in-memory cache used by the
<code class="literal">
Rewriter
</code>
plugin. If the value is
<code class="literal">
OFF
</code>
, no error
occurred. If the value is
<code class="literal">
ON
</code>
, an error
occurred; check the
<code class="literal">
message
</code>
column of
the
<code class="literal">
rewriter_rules
</code>
table for error
messages.
</p>
</li>
</ul>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/group-replication-upgrade-with-mysqlbackup.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="group-replication-upgrade-with-mysqlbackup">
</a>
20.8.3.4 Group Replication Upgrade with mysqlbackup
</h4>
</div>
</div>
</div>
<p>
As part of a provisioning approach you can use MySQL Enterprise Backup to copy and
restore the data from a group member to new members. However you
cannot use this technique to directly restore a backup taken
from a member running an older version of MySQL to a member
running a newer version of MySQL. The solution is to restore the
backup to a new server instance which is running the same
version of MySQL as the member which the backup was taken from,
and then upgrade the instance. This process consists of:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Take a backup from a member of the older group using
<span class="command">
<strong>
mysqlbackup
</strong>
</span>
. See
<a class="xref" href="group-replication-enterprise-backup.html" title="20.5.6 Using MySQL Enterprise Backup with Group Replication">
Section 20.5.6, “Using MySQL Enterprise Backup with Group Replication”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Deploy a new server instance, which must be running the same
version of MySQL as the older member where the backup was
taken.
</p>
</li>
<li class="listitem">
<p>
Restore the backup from the older member to the new instance
using
<span class="command">
<strong>
mysqlbackup
</strong>
</span>
.
</p>
</li>
<li class="listitem">
<p>
Upgrade MySQL on the new instance, see
<a class="xref" href="upgrading.html" title="Chapter 3 Upgrading MySQL">
Chapter 3,
<i>
Upgrading MySQL
</i>
</a>
.
</p>
</li>
</ul>
</div>
<p>
Repeat this process to create a suitable number of new
instances, for example to be able to handle a failover. Then
join the instances to a group based on the
<a class="xref" href="group-replication-online-upgrade-methods.html" title="20.8.3.3 Group Replication Online Upgrade Methods">
Section 20.8.3.3, “Group Replication Online Upgrade Methods”
</a>
.`
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/server-configuration-validation.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="server-configuration-validation">
</a>
7.1.3 Server Configuration Validation
</h3>
</div>
</div>
</div>
<p>
MySQL supports a
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
option that enables the startup configuration to be checked for
problems without running the server in normal operational mode:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa69973757"><div class="copy-help left">Press ⌘+C to 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">mysqld <span class="token property">--validate-config</span></code></pre>
</div>
<p>
If no errors are found, the server terminates with an exit code of
0. If an error is found, the server displays a diagnostic message
and terminates with an exit code of 1. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa75799516"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysqld</span> <span class="token property">--validate-config</span> <span class="token property">--no-such-option</span>
2018-11-05T17<span class="token punctuation">:</span>50<span class="token punctuation">:</span>12<span class="token punctuation">.</span>738919Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-000068<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> unknown
option <span class="token atrule">'--no-such-option'</span><span class="token punctuation">.</span>
2018-11-05T17<span class="token punctuation">:</span>50<span class="token punctuation">:</span>12<span class="token punctuation">.</span>738962Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-010119<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> Aborting</code></pre>
</div>
<p>
The server terminates as soon as any error is found. For
additional checks to occur, correct the initial problem and run
the server with
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
again.
</p>
<p>
For the preceding example, where use of
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
results in
display of an error message, the server exit code is 1. Warning
and information messages may also be displayed, depending on the
<a class="link" href="server-system-variables.html#sysvar_log_error_verbosity">
<code class="literal">
log_error_verbosity
</code>
</a>
value, but do
not produce immediate validation termination or an exit code of 1.
For example, this command produces multiple warnings, both of
which are displayed. But no error occurs, so the exit code is 0:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa36147251"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysqld</span> <span class="token property">--validate-config</span> <span class="token constant">--log_error_verbosity</span><span class="token attr-value"><span class="token punctuation">=</span>2</span>
<span class="token constant">--read-only</span><span class="token attr-value"><span class="token punctuation">=</span>s</span> <span class="token constant">--transaction_read_only</span><span class="token attr-value"><span class="token punctuation">=</span>s</span>
2018-11-05T15<span class="token punctuation">:</span>43<span class="token punctuation">:</span>18<span class="token punctuation">.</span>445863Z 0 <span class="token punctuation">[</span>Warning<span class="token punctuation">]</span> <span class="token punctuation">[</span>MY-000076<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> option
<span class="token atrule">'read_only'</span><span class="token punctuation">:</span> boolean value <span class="token atrule">'s'</span> was not recognized<span class="token punctuation">.</span> Set to OFF<span class="token punctuation">.</span>
2018-11-05T15<span class="token punctuation">:</span>43<span class="token punctuation">:</span>18<span class="token punctuation">.</span>445882Z 0 <span class="token punctuation">[</span>Warning<span class="token punctuation">]</span> <span class="token punctuation">[</span>MY-000076<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> option
<span class="token atrule">'transaction-read-only'</span><span class="token punctuation">:</span> boolean value <span class="token atrule">'s'</span> was not recognized<span class="token punctuation">.</span> Set to OFF<span class="token punctuation">.</span></code></pre>
</div>
<p>
This command produces the same warnings, but also an error, so the
error message is displayed along with the warnings and the exit
code is 1:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa41032362"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysqld</span> <span class="token property">--validate-config</span> <span class="token constant">--log_error_verbosity</span><span class="token attr-value"><span class="token punctuation">=</span>2</span>
<span class="token property">--no-such-option</span> <span class="token constant">--read-only</span><span class="token attr-value"><span class="token punctuation">=</span>s</span> <span class="token constant">--transaction_read_only</span><span class="token attr-value"><span class="token punctuation">=</span>s</span>
2018-11-05T15<span class="token punctuation">:</span>43<span class="token punctuation">:</span>53<span class="token punctuation">.</span>152886Z 0 <span class="token punctuation">[</span>Warning<span class="token punctuation">]</span> <span class="token punctuation">[</span>MY-000076<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> option
<span class="token atrule">'read_only'</span><span class="token punctuation">:</span> boolean value <span class="token atrule">'s'</span> was not recognized<span class="token punctuation">.</span> Set to OFF<span class="token punctuation">.</span>
2018-11-05T15<span class="token punctuation">:</span>43<span class="token punctuation">:</span>53<span class="token punctuation">.</span>152913Z 0 <span class="token punctuation">[</span>Warning<span class="token punctuation">]</span> <span class="token punctuation">[</span>MY-000076<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> option
<span class="token atrule">'transaction-read-only'</span><span class="token punctuation">:</span> boolean value <span class="token atrule">'s'</span> was not recognized<span class="token punctuation">.</span> Set to OFF<span class="token punctuation">.</span>
2018-11-05T15<span class="token punctuation">:</span>43<span class="token punctuation">:</span>53<span class="token punctuation">.</span>164889Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-000068<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> unknown
option <span class="token atrule">'--no-such-option'</span><span class="token punctuation">.</span>
2018-11-05T15<span class="token punctuation">:</span>43<span class="token punctuation">:</span>53<span class="token punctuation">.</span>165053Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-010119<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> Aborting</code></pre>
</div>
<p>
The scope of the
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
option is limited to configuration checking that the server can
perform without undergoing its normal startup process. As such,
the configuration check does not initialize storage engines and
other plugins, components, and so forth, and does not validate
options associated with those uninitialized subsystems.
</p>
<p>
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
can be used any
time, but is particularly useful after an upgrade, to check
whether any options previously used with the older server are
considered by the upgraded server to be deprecated or obsolete.
For example, the
<code class="literal">
tx_read_only
</code>
system variable
was removed in 8.0. Suppose that a MySQL 5.7 server was run using
that system variable in its
<code class="filename">
my.cnf
</code>
file and
then upgraded to MySQL 8.4. Running the upgraded
server with
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
to
check the configuration produces this result:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa15889921"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysqld</span> <span class="token property">--validate-config</span>
2018-11-05T10<span class="token punctuation">:</span>40<span class="token punctuation">:</span>02<span class="token punctuation">.</span>712141Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-000067<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> unknown variable
<span class="token atrule">'tx_read_only=ON'</span><span class="token punctuation">.</span>
2018-11-05T10<span class="token punctuation">:</span>40<span class="token punctuation">:</span>02<span class="token punctuation">.</span>712178Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-010119<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> Aborting</code></pre>
</div>
<p>
<a class="link" href="server-options.html#option_mysqld_validate-config">
<code class="option">
--validate-config
</code>
</a>
can be used with
the
<a class="link" href="option-file-options.html#option_general_defaults-file">
<code class="option">
--defaults-file
</code>
</a>
option to
validate only the options in a specific file:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa14623707"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysqld</span> <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>./my.cnf-test</span> <span class="token property">--validate-config</span>
2018-11-05T10<span class="token punctuation">:</span>40<span class="token punctuation">:</span>02<span class="token punctuation">.</span>712141Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-000067<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> unknown variable
<span class="token atrule">'tx_read_only=ON'</span><span class="token punctuation">.</span>
2018-11-05T10<span class="token punctuation">:</span>40<span class="token punctuation">:</span>02<span class="token punctuation">.</span>712178Z 0 <span class="token property"><span class="token punctuation">[</span>ERROR<span class="token punctuation">]</span></span> <span class="token punctuation">[</span>MY-010119<span class="token punctuation">]</span> <span class="token punctuation">[</span>Server<span class="token punctuation">]</span> Aborting</code></pre>
</div>
<p>
Remember that
<a class="link" href="option-file-options.html#option_general_defaults-file">
<code class="option">
--defaults-file
</code>
</a>
, if
specified, must be the first option on the command line.
(Executing the preceding example with the option order reversed
produces a message that
<a class="link" href="option-file-options.html#option_general_defaults-file">
<code class="option">
--defaults-file
</code>
</a>
itself is
unknown.)
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/innodb-deadlock-example.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="innodb-deadlock-example">
</a>
17.7.5.1 An InnoDB Deadlock Example
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045163825408">
</a>
<a class="indexterm" name="idm46045163823952">
</a>
<p>
The following example illustrates how an error can occur when a
lock request causes a deadlock. The example involves two
clients, A and B.
</p>
<p>
InnoDB status contains details of the last deadlock. For
frequent deadlocks, enable global variable
<a class="link" href="innodb-parameters.html#sysvar_innodb_print_all_deadlocks">
<code class="literal">
innodb_print_all_deadlocks
</code>
</a>
.
This adds deadlock information to the error log.
</p>
<p>
Client A enables
<a class="link" href="innodb-parameters.html#sysvar_innodb_print_all_deadlocks">
<code class="literal">
innodb_print_all_deadlocks
</code>
</a>
,
creates two tables, 'Animals' and 'Birds', and inserts data into
each. Client A begins a transaction, and selects a row in
Animals in share mode:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa77079206"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> innodb_print_all_deadlocks <span class="token operator">=</span> <span class="token keyword">ON</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> Animals <span class="token punctuation">(</span><span class="token keyword">name</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">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">,</span> <span class="token keyword">value</span> <span class="token datatype">INT</span><span class="token punctuation">)</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> InnoDB<span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.01 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> Birds <span class="token punctuation">(</span><span class="token keyword">name</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">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">,</span> <span class="token keyword">value</span> <span class="token datatype">INT</span><span class="token punctuation">)</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> InnoDB<span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.01 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> Animals <span class="token punctuation">(</span><span class="token keyword">name</span><span class="token punctuation">,</span><span class="token keyword">value</span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">"Aardvark"</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 1 row affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> Birds <span class="token punctuation">(</span><span class="token keyword">name</span><span class="token punctuation">,</span><span class="token keyword">value</span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token string">"Buzzard"</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 1 row affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">START</span> <span class="token keyword">TRANSACTION</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token keyword">value</span> <span class="token keyword">FROM</span> Animals <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Aardvark'</span> <span class="token keyword">FOR</span> <span class="token keyword">SHARE</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>
<span class="token output"><span class="token punctuation">|</span> value <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>
<span class="token output"><span class="token punctuation">|</span> 10 <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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
Next, client B begins a transaction, and selects a row in Birds
in share mode:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa94758810"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">START</span> <span class="token keyword">TRANSACTION</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token keyword">value</span> <span class="token keyword">FROM</span> Birds <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Buzzard'</span> <span class="token keyword">FOR</span> <span class="token keyword">SHARE</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>
<span class="token output"><span class="token punctuation">|</span> value <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>
<span class="token output"><span class="token punctuation">|</span> 20 <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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
The Performance Schema shows the locks after the two select
statements:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53599641"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> ENGINE_TRANSACTION_ID <span class="token keyword">as</span> Trx_Id<span class="token punctuation">,</span>
<span class="token prompt"> -></span> OBJECT_NAME <span class="token keyword">as</span> <span class="token punctuation">`</span><span class="token keyword">Table</span><span class="token punctuation">`</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> INDEX_NAME <span class="token keyword">as</span> <span class="token punctuation">`</span><span class="token keyword">Index</span><span class="token punctuation">`</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_DATA <span class="token keyword">as</span> <span class="token keyword">Data</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_MODE <span class="token keyword">as</span> <span class="token keyword">Mode</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_STATUS <span class="token keyword">as</span> <span class="token keyword">Status</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_TYPE <span class="token keyword">as</span> <span class="token keyword">Type</span>
<span class="token prompt"> -></span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>data_locks<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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> Trx_Id <span class="token punctuation">|</span> Table <span class="token punctuation">|</span> Index <span class="token punctuation">|</span> Data <span class="token punctuation">|</span> Mode <span class="token punctuation">|</span> Status <span class="token punctuation">|</span> Type <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 421291106147544 <span class="token punctuation">|</span> Animals <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> IS <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> TABLE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 421291106147544 <span class="token punctuation">|</span> Animals <span class="token punctuation">|</span> PRIMARY <span class="token punctuation">|</span> 'Aardvark' <span class="token punctuation">|</span> S,REC_NOT_GAP <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> RECORD <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 421291106148352 <span class="token punctuation">|</span> Birds <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> IS <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> TABLE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 421291106148352 <span class="token punctuation">|</span> Birds <span class="token punctuation">|</span> PRIMARY <span class="token punctuation">|</span> 'Buzzard' <span class="token punctuation">|</span> S,REC_NOT_GAP <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> RECORD <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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">4 rows in set (0.00 sec)</span></code></pre>
</div>
<p>
Client B then updates a row in Animals:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa6443280"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">UPDATE</span> Animals <span class="token keyword">SET</span> <span class="token keyword">value</span><span class="token operator">=</span><span class="token number">30</span> <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Aardvark'</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Client B has to wait. The Performance Schema shows the wait for
a lock:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa77296941"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> REQUESTING_ENGINE_LOCK_ID <span class="token keyword">as</span> Req_Lock_Id<span class="token punctuation">,</span>
<span class="token prompt"> -></span> REQUESTING_ENGINE_TRANSACTION_ID <span class="token keyword">as</span> Req_Trx_Id<span class="token punctuation">,</span>
<span class="token prompt"> -></span> BLOCKING_ENGINE_LOCK_ID <span class="token keyword">as</span> Blk_Lock_Id<span class="token punctuation">,</span>
<span class="token prompt"> -></span> BLOCKING_ENGINE_TRANSACTION_ID <span class="token keyword">as</span> Blk_Trx_Id
<span class="token prompt"> -></span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>data_lock_waits<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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> Req_Lock_Id <span class="token punctuation">|</span> Req_Trx_Id <span class="token punctuation">|</span> Blk_Lock_Id <span class="token punctuation">|</span> Blk_Trx_Id <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 139816129437696:27:4:2:139816016601240 <span class="token punctuation">|</span> 43260 <span class="token punctuation">|</span> 139816129436888:27:4:2:139816016594720 <span class="token punctuation">|</span> 421291106147544 <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 class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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></span> <span class="token keyword">SELECT</span> ENGINE_LOCK_ID <span class="token keyword">as</span> Lock_Id<span class="token punctuation">,</span>
<span class="token prompt"> -></span> ENGINE_TRANSACTION_ID <span class="token keyword">as</span> Trx_id<span class="token punctuation">,</span>
<span class="token prompt"> -></span> OBJECT_NAME <span class="token keyword">as</span> <span class="token punctuation">`</span><span class="token keyword">Table</span><span class="token punctuation">`</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> INDEX_NAME <span class="token keyword">as</span> <span class="token punctuation">`</span><span class="token keyword">Index</span><span class="token punctuation">`</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_DATA <span class="token keyword">as</span> <span class="token keyword">Data</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_MODE <span class="token keyword">as</span> <span class="token keyword">Mode</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_STATUS <span class="token keyword">as</span> <span class="token keyword">Status</span><span class="token punctuation">,</span>
<span class="token prompt"> -></span> LOCK_TYPE <span class="token keyword">as</span> <span class="token keyword">Type</span>
<span class="token prompt"> -></span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>data_locks<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 class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> Lock_Id <span class="token punctuation">|</span> Trx_Id <span class="token punctuation">|</span> Table <span class="token punctuation">|</span> Index <span class="token punctuation">|</span> Data <span class="token punctuation">|</span> Mode <span class="token punctuation">|</span> Status <span class="token punctuation">|</span> Type <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 class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> 139816129437696:1187:139816016603896 <span class="token punctuation">|</span> 43260 <span class="token punctuation">|</span> Animals <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> IX <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> TABLE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 139816129437696:1188:139816016603808 <span class="token punctuation">|</span> 43260 <span class="token punctuation">|</span> Birds <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> IS <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> TABLE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 139816129437696:28:4:2:139816016600896 <span class="token punctuation">|</span> 43260 <span class="token punctuation">|</span> Birds <span class="token punctuation">|</span> PRIMARY <span class="token punctuation">|</span> 'Buzzard' <span class="token punctuation">|</span> S,REC_NOT_GAP <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> RECORD <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 139816129437696:27:4:2:139816016601240 <span class="token punctuation">|</span> 43260 <span class="token punctuation">|</span> Animals <span class="token punctuation">|</span> PRIMARY <span class="token punctuation">|</span> 'Aardvark' <span class="token punctuation">|</span> X,REC_NOT_GAP <span class="token punctuation">|</span> WAITING <span class="token punctuation">|</span> RECORD <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 139816129436888:1187:139816016597712 <span class="token punctuation">|</span> 421291106147544 <span class="token punctuation">|</span> Animals <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> NULL <span class="token punctuation">|</span> IS <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> TABLE <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 139816129436888:27:4:2:139816016594720 <span class="token punctuation">|</span> 421291106147544 <span class="token punctuation">|</span> Animals <span class="token punctuation">|</span> PRIMARY <span class="token punctuation">|</span> 'Aardvark' <span class="token punctuation">|</span> S,REC_NOT_GAP <span class="token punctuation">|</span> GRANTED <span class="token punctuation">|</span> RECORD <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 class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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">6 rows in set (0.00 sec)</span></code></pre>
</div>
<p>
InnoDB only uses sequential transaction ids when a transaction
attempts to modify the database. Thererfore, the previous
read-only transaction id changes from 421291106148352 to 43260.
</p>
<p>
If client A attempts to update a row in Birds at the same time,
this will lead to a deadlock:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa27811988"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">UPDATE</span> Birds <span class="token keyword">SET</span> <span class="token keyword">value</span><span class="token operator">=</span><span class="token number">40</span> <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Buzzard'</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1213 (40001)<span class="token punctuation">:</span> Deadlock found when trying to get lock; try restarting transaction</span></code></pre>
</div>
<p>
InnoDB rolls back the transaction that caused the deadlock. The
first update, from Client B, can now proceed.
</p>
<p>
The Information Schema contains the number of deadlocks:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa64799645"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token punctuation">`</span>count<span class="token punctuation">`</span> <span class="token keyword">FROM</span> INFORMATION_SCHEMA<span class="token punctuation">.</span>INNODB_METRICS
<span class="token keyword">WHERE</span> <span class="token keyword">NAME</span><span class="token operator">=</span><span class="token string">"lock_deadlocks"</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>
<span class="token output"><span class="token punctuation">|</span> count <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>
<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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
The InnoDB status contains the following information about the
deadlock and transactions. It also shows that the read-only
transaction id 421291106147544 changes to sequential transaction
id 43261.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68710737"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SHOW</span> <span class="token keyword">ENGINE</span> INNODB <span class="token keyword">STATUS</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">------------------------</span>
LATEST DETECTED DEADLOCK
<span class="token comment" spellcheck="true">------------------------</span>
<span class="token number">2022</span><span class="token operator">-</span><span class="token number">11</span><span class="token operator">-</span><span class="token number">25</span> <span class="token number">15</span>:<span class="token number">58</span>:<span class="token number">22</span> <span class="token number">139815661168384</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">TRANSACTION</span>:
<span class="token keyword">TRANSACTION</span> <span class="token number">43260</span><span class="token punctuation">,</span> <span class="token keyword">ACTIVE</span> <span class="token number">186</span> sec <span class="token keyword">starting</span> <span class="token keyword">index</span> <span class="token keyword">read</span>
mysql <span class="token keyword">tables</span> <span class="token keyword">in</span> <span class="token keyword">use</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token keyword">locked</span> <span class="token number">1</span>
<span class="token keyword">LOCK</span> <span class="token keyword">WAIT</span> <span class="token number">4</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
MySQL thread id <span class="token number">19</span><span class="token punctuation">,</span> OS thread handle <span class="token number">139815619204864</span><span class="token punctuation">,</span> <span class="token keyword">query</span> id <span class="token number">143</span> localhost u2 updating
<span class="token keyword">UPDATE</span> Animals <span class="token keyword">SET</span> <span class="token keyword">value</span><span class="token operator">=</span><span class="token number">30</span> <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Aardvark'</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> HOLDS THE <span class="token keyword">LOCK</span><span class="token punctuation">(</span>S<span class="token punctuation">)</span>:
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">28</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Birds<span class="token punctuation">`</span> trx id <span class="token number">43260</span> <span class="token keyword">lock</span> <span class="token keyword">mode</span> S <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">42757a7a617264</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Buzzard<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8fb</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e40110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">80000014</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> WAITING <span class="token keyword">FOR</span> THIS <span class="token keyword">LOCK</span> <span class="token keyword">TO</span> BE GRANTED:
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">27</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Animals<span class="token punctuation">`</span> trx id <span class="token number">43260</span> lock_mode X <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap waiting
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">8</span><span class="token punctuation">;</span> hex <span class="token number">416172647661726b</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Aardvark<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8f9</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e20110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">8000000a</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token keyword">TRANSACTION</span>:
<span class="token keyword">TRANSACTION</span> <span class="token number">43261</span><span class="token punctuation">,</span> <span class="token keyword">ACTIVE</span> <span class="token number">209</span> sec <span class="token keyword">starting</span> <span class="token keyword">index</span> <span class="token keyword">read</span>
mysql <span class="token keyword">tables</span> <span class="token keyword">in</span> <span class="token keyword">use</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token keyword">locked</span> <span class="token number">1</span>
<span class="token keyword">LOCK</span> <span class="token keyword">WAIT</span> <span class="token number">4</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
MySQL thread id <span class="token number">18</span><span class="token punctuation">,</span> OS thread handle <span class="token number">139815618148096</span><span class="token punctuation">,</span> <span class="token keyword">query</span> id <span class="token number">146</span> localhost u1 updating
<span class="token keyword">UPDATE</span> Birds <span class="token keyword">SET</span> <span class="token keyword">value</span><span class="token operator">=</span><span class="token number">40</span> <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Buzzard'</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> HOLDS THE <span class="token keyword">LOCK</span><span class="token punctuation">(</span>S<span class="token punctuation">)</span>:
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">27</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Animals<span class="token punctuation">`</span> trx id <span class="token number">43261</span> <span class="token keyword">lock</span> <span class="token keyword">mode</span> S <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">8</span><span class="token punctuation">;</span> hex <span class="token number">416172647661726b</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Aardvark<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8f9</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e20110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">8000000a</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> WAITING <span class="token keyword">FOR</span> THIS <span class="token keyword">LOCK</span> <span class="token keyword">TO</span> BE GRANTED:
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">28</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Birds<span class="token punctuation">`</span> trx id <span class="token number">43261</span> lock_mode X <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap waiting
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">42757a7a617264</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Buzzard<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8fb</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e40110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">80000014</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> WE ROLL BACK <span class="token keyword">TRANSACTION</span> <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">------------</span>
TRANSACTIONS
<span class="token comment" spellcheck="true">------------</span>
Trx id counter <span class="token number">43262</span>
<span class="token keyword">Purge</span> done <span class="token keyword">for</span> trx's n:o <span class="token operator"><</span> <span class="token number">43256</span> <span class="token keyword">undo</span> n:o <span class="token operator"><</span> <span class="token number">0</span> state: running but idle
<span class="token keyword">History</span> <span class="token keyword">list</span> length <span class="token number">0</span>
<span class="token keyword">LIST</span> <span class="token keyword">OF</span> TRANSACTIONS <span class="token keyword">FOR</span> <span class="token keyword">EACH</span> <span class="token keyword">SESSION</span>:
<span class="token comment" spellcheck="true">---TRANSACTION 421291106147544, not started</span>
<span class="token number">0</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">---TRANSACTION 421291106146736, not started</span>
<span class="token number">0</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">---TRANSACTION 421291106145928, not started</span>
<span class="token number">0</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">---TRANSACTION 43260, ACTIVE 219 sec</span>
<span class="token number">4</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">undo</span> log entries <span class="token number">1</span>
MySQL thread id <span class="token number">19</span><span class="token punctuation">,</span> OS thread handle <span class="token number">139815619204864</span><span class="token punctuation">,</span> <span class="token keyword">query</span> id <span class="token number">143</span> localhost u2</code></pre>
</div>
<p>
The error log contains this information about transactions and
locks:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa10622455"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SELECT</span> <span class="token variable">@@log_error</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> @@log_error <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> /var/log/mysqld.log <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">1 row in set (0.00 sec)</span>
<span class="token keyword">TRANSACTION</span> <span class="token number">43260</span><span class="token punctuation">,</span> <span class="token keyword">ACTIVE</span> <span class="token number">186</span> sec <span class="token keyword">starting</span> <span class="token keyword">index</span> <span class="token keyword">read</span>
mysql <span class="token keyword">tables</span> <span class="token keyword">in</span> <span class="token keyword">use</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token keyword">locked</span> <span class="token number">1</span>
<span class="token keyword">LOCK</span> <span class="token keyword">WAIT</span> <span class="token number">4</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
MySQL thread id <span class="token number">19</span><span class="token punctuation">,</span> OS thread handle <span class="token number">139815619204864</span><span class="token punctuation">,</span> <span class="token keyword">query</span> id <span class="token number">143</span> localhost u2 updating
<span class="token keyword">UPDATE</span> Animals <span class="token keyword">SET</span> <span class="token keyword">value</span><span class="token operator">=</span><span class="token number">30</span> <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Aardvark'</span>
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">28</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Birds<span class="token punctuation">`</span> trx id <span class="token number">43260</span> <span class="token keyword">lock</span> <span class="token keyword">mode</span> S <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">42757a7a617264</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Buzzard<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8fb</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e40110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">80000014</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">27</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Animals<span class="token punctuation">`</span> trx id <span class="token number">43260</span> lock_mode X <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap waiting
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">8</span><span class="token punctuation">;</span> hex <span class="token number">416172647661726b</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Aardvark<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8f9</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e20110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">8000000a</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token keyword">TRANSACTION</span> <span class="token number">43261</span><span class="token punctuation">,</span> <span class="token keyword">ACTIVE</span> <span class="token number">209</span> sec <span class="token keyword">starting</span> <span class="token keyword">index</span> <span class="token keyword">read</span>
mysql <span class="token keyword">tables</span> <span class="token keyword">in</span> <span class="token keyword">use</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token keyword">locked</span> <span class="token number">1</span>
<span class="token keyword">LOCK</span> <span class="token keyword">WAIT</span> <span class="token number">4</span> <span class="token keyword">lock</span> struct<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">,</span> heap size <span class="token number">1128</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token keyword">row</span> <span class="token keyword">lock</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span>
MySQL thread id <span class="token number">18</span><span class="token punctuation">,</span> OS thread handle <span class="token number">139815618148096</span><span class="token punctuation">,</span> <span class="token keyword">query</span> id <span class="token number">146</span> localhost u1 updating
<span class="token keyword">UPDATE</span> Birds <span class="token keyword">SET</span> <span class="token keyword">value</span><span class="token operator">=</span><span class="token number">40</span> <span class="token keyword">WHERE</span> <span class="token keyword">name</span><span class="token operator">=</span><span class="token string">'Buzzard'</span>
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">27</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Animals<span class="token punctuation">`</span> trx id <span class="token number">43261</span> <span class="token keyword">lock</span> <span class="token keyword">mode</span> S <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">8</span><span class="token punctuation">;</span> hex <span class="token number">416172647661726b</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Aardvark<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8f9</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e20110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">8000000a</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
RECORD <span class="token keyword">LOCKS</span> space id <span class="token number">28</span> <span class="token keyword">page</span> <span class="token keyword">no</span> <span class="token number">4</span> n bits <span class="token number">72</span> <span class="token keyword">index</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">of</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>test<span class="token punctuation">`</span><span class="token punctuation">.</span><span class="token punctuation">`</span>Birds<span class="token punctuation">`</span> trx id <span class="token number">43261</span> lock_mode X <span class="token keyword">locks</span> rec but <span class="token operator">not</span> gap waiting
Record <span class="token keyword">lock</span><span class="token punctuation">,</span> heap <span class="token keyword">no</span> <span class="token number">2</span> PHYSICAL RECORD: n_fields <span class="token number">4</span><span class="token punctuation">;</span> <span class="token keyword">compact</span> <span class="token keyword">format</span><span class="token punctuation">;</span> info bits <span class="token number">0</span>
<span class="token number">0</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">42757a7a617264</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> Buzzard<span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">1</span>: len <span class="token number">6</span><span class="token punctuation">;</span> hex <span class="token number">00000000a8fb</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">2</span>: len <span class="token number">7</span><span class="token punctuation">;</span> hex <span class="token number">82000000e40110</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token number">3</span>: len <span class="token number">4</span><span class="token punctuation">;</span> hex <span class="token number">80000014</span><span class="token punctuation">;</span> <span class="token keyword">asc</span> <span class="token punctuation">;</span><span class="token punctuation">;</span></code></pre>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-functions.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title">
<a name="replication-functions">
</a>
14.18 Replication Functions
</h2>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="group-replication-functions.html">
14.18.1 Group Replication Functions
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="gtid-functions.html">
14.18.2 Functions Used with Global Transaction Identifiers (GTIDs)
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-functions-async-failover.html">
14.18.3 Asynchronous Replication Channel Failover Functions
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-functions-synchronization.html">
14.18.4 Position-Based Synchronization Functions
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045194116896">
</a>
<a class="indexterm" name="idm46045194115824">
</a>
<p>
The functions described in the following sections are used with
MySQL Replication.
</p>
<div class="table">
<a name="idm46045194113840">
</a>
<p class="title">
<b>
Table 14.24 Replication Functions
</b>
</p>
<div class="table-contents">
<table frame="box" rules="all" summary="A reference that lists functions used with MySQL Replication.">
<colgroup>
<col style="width: 25%"/>
<col style="width: 62%"/>
<col style="width: 12%"/>
</colgroup>
<thead>
<tr>
<th>
Name
</th>
<th>
Description
</th>
<th>
Deprecated
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
<a class="link" href="replication-functions-async-failover.html#function_asynchronous-connection-failover-add-managed">
<code class="literal">
asynchronous_connection_failover_add_managed()
</code>
</a>
</th>
<td>
Add group member source server configuration information to a
replication channel source list
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="replication-functions-async-failover.html#function_asynchronous-connection-failover-add-source">
<code class="literal">
asynchronous_connection_failover_add_source()
</code>
</a>
</th>
<td>
Add source server configuration information server to a
replication channel source list
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="replication-functions-async-failover.html#function_asynchronous-connection-failover-delete-managed">
<code class="literal">
asynchronous_connection_failover_delete_managed()
</code>
</a>
</th>
<td>
Remove a managed group from a replication channel source list
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="replication-functions-async-failover.html#function_asynchronous-connection-failover-delete-source">
<code class="literal">
asynchronous_connection_failover_delete_source()
</code>
</a>
</th>
<td>
Remove a source server from a replication channel source list
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="replication-functions-async-failover.html#function_asynchronous-connection-failover-reset">
<code class="literal">
asynchronous_connection_failover_reset()
</code>
</a>
</th>
<td>
Remove all settings relating to group replication asynchronous
failover
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-member-actions.html#function_group-replication-disable-member-action">
<code class="literal">
group_replication_disable_member_action()
</code>
</a>
</th>
<td>
Disable member action for event specified
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-member-actions.html#function_group-replication-enable-member-action">
<code class="literal">
group_replication_enable_member_action()
</code>
</a>
</th>
<td>
Enable member action for event specified
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-communication-protocol.html#function_group-replication-get-communication-protocol">
<code class="literal">
group_replication_get_communication_protocol()
</code>
</a>
</th>
<td>
Get version of group replication communication protocol currently
in use
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-maximum-consensus.html#function_group-replication-get-write-concurrency">
<code class="literal">
group_replication_get_write_concurrency()
</code>
</a>
</th>
<td>
Get maximum number of consensus instances currently set for group
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-member-actions.html#function_group-replication-reset-member-actions">
<code class="literal">
group_replication_reset_member_actions()
</code>
</a>
</th>
<td>
Reset all member actions to defaults and configuration version
number to 1
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-new-primary.html#function_group-replication-set-as-primary">
<code class="literal">
group_replication_set_as_primary()
</code>
</a>
</th>
<td>
Make a specific group member the primary
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-communication-protocol.html#function_group-replication-set-communication-protocol">
<code class="literal">
group_replication_set_communication_protocol()
</code>
</a>
</th>
<td>
Set version for group replication communication protocol to use
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="group-replication-functions-for-maximum-consensus.html#function_group-replication-set-write-concurrency">
<code class="literal">
group_replication_set_write_concurrency()
</code>
</a>
</th>
<td>
Set maximum number of consensus instances that can be executed in
parallel
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<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>
</th>
<td>
Changes the mode of a group running in single-primary mode to
multi-primary mode
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<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>
</th>
<td>
Changes the mode of a group running in multi-primary mode to
single-primary mode
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="replication-functions-synchronization.html#function_master-pos-wait">
<code class="literal">
MASTER_POS_WAIT()
</code>
</a>
</th>
<td>
Block until the replica has read and applied all updates up to the
specified position
</td>
<td>
Yes
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="replication-functions-synchronization.html#function_source-pos-wait">
<code class="literal">
SOURCE_POS_WAIT()
</code>
</a>
</th>
<td>
Block until the replica has read and applied all updates up to the
specified position
</td>
<td>
</td>
</tr>
<tr>
<th scope="row">
<a class="link" href="gtid-functions.html#function_wait-for-executed-gtid-set">
<code class="literal">
WAIT_FOR_EXECUTED_GTID_SET()
</code>
</a>
</th>
<td>
Wait until the given GTIDs have executed on the replica.
</td>
<td>
</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: 405.156px;">
Name
</th>
<th style="width: 243.688px;">
Description
</th>
<th style="width: 89.1562px;">
Deprecated
</th>
</tr>
</thead>
</table>
</div>
</div>
<br class="table-break"/>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/information-schema-mysql-firewall-users-table.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="information-schema-mysql-firewall-users-table">
</a>
28.7.2 The INFORMATION_SCHEMA MYSQL_FIREWALL_USERS Table
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045075954624">
</a>
<p>
The
<a class="link" href="information-schema-mysql-firewall-users-table.html" title="28.7.2 The INFORMATION_SCHEMA MYSQL_FIREWALL_USERS Table">
<code class="literal">
MYSQL_FIREWALL_USERS
</code>
</a>
table
provides a view into the in-memory data cache for MySQL Enterprise Firewall. It lists
names and operational modes of registered firewall account
profiles. It is used in conjunction with the
<code class="literal">
mysql.firewall_users
</code>
system table that provides
persistent storage of firewall data; see
<a class="xref" href="firewall-reference.html#firewall-tables" title="MySQL Enterprise Firewall Tables">
MySQL Enterprise Firewall Tables
</a>
.
</p>
<p>
The
<a class="link" href="information-schema-mysql-firewall-users-table.html" title="28.7.2 The INFORMATION_SCHEMA MYSQL_FIREWALL_USERS Table">
<code class="literal">
MYSQL_FIREWALL_USERS
</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">
USERHOST
</code>
</p>
<p>
The account profile name. Each account name has the format
<code class="literal">
<em class="replaceable">
<code>
user_name
</code>
</em>
@
<em class="replaceable">
<code>
host_name
</code>
</em>
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
MODE
</code>
</p>
<p>
The current operational mode for the profile. Permitted mode
values are
<code class="literal">
OFF
</code>
,
<code class="literal">
DETECTING
</code>
,
<code class="literal">
PROTECTING
</code>
,
<code class="literal">
RECORDING
</code>
, and
<code class="literal">
RESET
</code>
.
For details about their meanings, see
<a class="xref" href="firewall-usage.html#firewall-concepts" title="Firewall Concepts">
Firewall Concepts
</a>
.
</p>
</li>
</ul>
</div>
<p>
This table is deprecated and subject to removal in a future MySQL
version. See
<a class="xref" href="firewall-usage.html#firewall-account-profile-migration" title="Migrating Account Profiles to Group Profiles">
Migrating Account Profiles to Group Profiles
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/innodb-checkpoints.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="innodb-checkpoints">
</a>
17.11.3 InnoDB Checkpoints
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045160628320">
</a>
<p>
Making your
<a class="link" href="glossary.html#glos_log_file" title="log file">
log files
</a>
very
large may reduce disk I/O during
<a class="link" href="glossary.html#glos_checkpoint" title="checkpoint">
checkpointing
</a>
. It often
makes sense to set the total size of the log files as large as the
buffer pool or even larger.
</p>
<h4>
<a name="idm46045160624608">
</a>
How Checkpoint Processing Works
</h4>
<p>
<code class="literal">
InnoDB
</code>
implements a
<a class="link" href="glossary.html#glos_checkpoint" title="checkpoint">
checkpoint
</a>
mechanism known
as
<a class="link" href="glossary.html#glos_fuzzy_checkpointing" title="fuzzy checkpointing">
fuzzy
checkpointing
</a>
.
<code class="literal">
InnoDB
</code>
flushes modified
database pages from the buffer pool in small batches. There is no
need to flush the buffer pool in one single batch, which would
disrupt processing of user SQL statements during the checkpointing
process.
</p>
<p>
During
<a class="link" href="glossary.html#glos_crash_recovery" title="crash recovery">
crash recovery
</a>
,
<code class="literal">
InnoDB
</code>
looks for a checkpoint label written to
the log files. It knows that all modifications to the database
before the label are present in the disk image of the database.
Then
<code class="literal">
InnoDB
</code>
scans the log files forward from
the checkpoint, applying the logged modifications to the database.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-install-example-data.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="mysql-cluster-install-example-data">
</a>
25.3.5 NDB Cluster Example with Tables and Data
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045122186176">
</a>
<a class="indexterm" name="idm46045122184688">
</a>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
The information in this section applies to NDB Cluster running
on both Unix and Windows platforms.
</p>
</div>
<p>
Working with database tables and data in NDB Cluster is not much
different from doing so in standard MySQL. There are two key
points to keep in mind:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For a table to be replicated in the cluster, it must use the
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDBCLUSTER
</code>
</a>
storage engine. To
specify this, use the
<code class="literal">
ENGINE=NDBCLUSTER
</code>
or
<code class="literal">
ENGINE=NDB
</code>
option when creating the table:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa17073312"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> <em class="replaceable">tbl_name</em> <span class="token punctuation">(</span><em class="replaceable">col_name</em> <em class="replaceable">column_definitions</em><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 punctuation">;</span></code></pre>
</div>
<p>
Alternatively, for an existing table that uses a different
storage engine, use
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
to change the table to use
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDBCLUSTER
</code>
</a>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa18539263"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
Every
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDBCLUSTER
</code>
</a>
table has a
primary key. If no primary key is defined by the user when a
table is created, the
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDBCLUSTER
</code>
</a>
storage engine automatically generates a hidden one. Such a
key takes up space just as does any other table index. (It is
not uncommon to encounter problems due to insufficient memory
for accommodating these automatically created indexes.)
</p>
</li>
</ul>
</div>
<p>
If you are importing tables from an existing database using the
output of
<a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
<span class="command">
<strong>
mysqldump
</strong>
</span>
</a>
, you can open the SQL
script in a text editor and add the
<code class="literal">
ENGINE
</code>
option to any table creation statements, or replace any existing
<code class="literal">
ENGINE
</code>
options. Suppose that you have the
<code class="literal">
world
</code>
sample database on another MySQL server
that does not support NDB Cluster, and you want to export the
<code class="literal">
City
</code>
table:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa5597580"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysqldump</span> <span class="token property">--add-drop-table</span> world City > city_table<span class="token punctuation">.</span>sql</code></pre>
</div>
<p>
The resulting
<code class="filename">
city_table.sql
</code>
file contains
this table creation statement (and the
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
statements necessary to
import the table data):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa15697349"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>ID<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 operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">auto_increment</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span><span class="token keyword">Name</span><span class="token punctuation">`</span> <span class="token datatype">char</span><span class="token punctuation">(</span><span class="token number">35</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">''</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>CountryCode<span class="token punctuation">`</span> <span class="token datatype">char</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">''</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>District<span class="token punctuation">`</span> <span class="token datatype">char</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">''</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>Population<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 operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">'0'</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>ID<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>MyISAM<span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <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">'Kabul'</span><span class="token punctuation">,</span><span class="token string">'AFG'</span><span class="token punctuation">,</span><span class="token string">'Kabol'</span><span class="token punctuation">,</span><span class="token number">1780000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <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">'Qandahar'</span><span class="token punctuation">,</span><span class="token string">'AFG'</span><span class="token punctuation">,</span><span class="token string">'Qandahar'</span><span class="token punctuation">,</span><span class="token number">237500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token string">'Herat'</span><span class="token punctuation">,</span><span class="token string">'AFG'</span><span class="token punctuation">,</span><span class="token string">'Herat'</span><span class="token punctuation">,</span><span class="token number">186800</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation"></span><em class="replaceable"><span class="token punctuation">(</span>remaining <span class="token keyword">INSERT</span> statements omitted<span class="token punctuation">)</span></em><span class="token punctuation"></span></code></pre>
</div>
<p>
You need to make sure that MySQL uses the
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDBCLUSTER
</code>
</a>
storage engine for this
table. There are two ways that this can be accomplished. One of
these is to modify the table definition
<span class="emphasis">
<em>
before
</em>
</span>
importing it into the Cluster
database. Using the
<code class="literal">
City
</code>
table as an example,
modify the
<code class="literal">
ENGINE
</code>
option of the definition as
follows:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32089454"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <span class="token punctuation">(</span>
<span class="token punctuation">`</span>ID<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 operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">auto_increment</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span><span class="token keyword">Name</span><span class="token punctuation">`</span> <span class="token datatype">char</span><span class="token punctuation">(</span><span class="token number">35</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">''</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>CountryCode<span class="token punctuation">`</span> <span class="token datatype">char</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">''</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>District<span class="token punctuation">`</span> <span class="token datatype">char</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">''</span><span class="token punctuation">,</span>
<span class="token punctuation">`</span>Population<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 operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token string">'0'</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>ID<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><span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <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">'Kabul'</span><span class="token punctuation">,</span><span class="token string">'AFG'</span><span class="token punctuation">,</span><span class="token string">'Kabol'</span><span class="token punctuation">,</span><span class="token number">1780000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <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">'Qandahar'</span><span class="token punctuation">,</span><span class="token string">'AFG'</span><span class="token punctuation">,</span><span class="token string">'Qandahar'</span><span class="token punctuation">,</span><span class="token number">237500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>City<span class="token punctuation">`</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token string">'Herat'</span><span class="token punctuation">,</span><span class="token string">'AFG'</span><span class="token punctuation">,</span><span class="token string">'Herat'</span><span class="token punctuation">,</span><span class="token number">186800</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation"></span><em class="replaceable"><span class="token punctuation">(</span>remaining <span class="token keyword">INSERT</span> statements omitted<span class="token punctuation">)</span></em><span class="token punctuation"></span></code></pre>
</div>
<p>
This must be done for the definition of each table that is to be
part of the clustered database. The easiest way to accomplish this
is to do a search-and-replace on the file that contains the
definitions and replace all instances of
<code class="literal">
ENGINE=
<em class="replaceable">
<code>
engine_name
</code>
</em>
</code>
with
<code class="literal">
ENGINE=NDBCLUSTER
</code>
. If you do not want to
modify the file, you can use the unmodified file to create the
tables, and then use
<a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
<code class="literal">
ALTER TABLE
</code>
</a>
to
change their storage engine. The particulars are given later in
this section.
</p>
<p>
Assuming that you have already created a database named
<code class="literal">
world
</code>
on the SQL node of the cluster, you can
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>
command-line client to read
<code class="filename">
city_table.sql
</code>
, and create and populate the
corresponding table in the usual manner:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa22482387"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysql</span> world < city_table<span class="token punctuation">.</span>sql</code></pre>
</div>
<p>
It is very important to keep in mind that the preceding command
must be executed on the host where the SQL node is running (in
this case, on the machine with the IP address
<code class="literal">
198.51.100.20
</code>
).
</p>
<p>
To create a copy of the entire
<code class="literal">
world
</code>
database
on the SQL node, use
<a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
<span class="command">
<strong>
mysqldump
</strong>
</span>
</a>
on the
noncluster server to export the database to a file named
<code class="filename">
world.sql
</code>
(for example, in the
<code class="filename">
/tmp
</code>
directory). Then modify the table
definitions as just described and import the file into the SQL
node of the cluster like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa72228990"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysql</span> world < /tmp/world<span class="token punctuation">.</span>sql</code></pre>
</div>
<p>
If you save the file to a different location, adjust the preceding
instructions accordingly.
</p>
<p>
Running
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
queries on the SQL
node is no different from running them on any other instance of a
MySQL server. To run queries from the command line, you first need
to log in to the MySQL Monitor in the usual way (specify the
<code class="literal">
root
</code>
password at the
<code class="literal">
Enter
password:
</code>
prompt):
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34357439"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">$<span class="token operator">></span> mysql <span class="token operator">-</span>u root <span class="token operator">-</span>p
Enter <span class="token keyword">password</span>:
Welcome <span class="token keyword">to</span> the MySQL monitor<span class="token punctuation">.</span> Commands <span class="token keyword">end</span> <span class="token keyword">with</span> <span class="token punctuation">;</span> <span class="token operator">or</span> \g<span class="token punctuation">.</span>
Your MySQL <span class="token keyword">connection</span> id <span class="token operator">is</span> <span class="token number">1</span> <span class="token keyword">to</span> <span class="token keyword">server</span> version: <span class="token number">8.4</span><span class="token punctuation">.</span><span class="token number">0</span><span class="token operator">-</span><span class="token keyword">ndb</span><span class="token operator">-</span><span class="token number">8.4</span><span class="token punctuation">.</span><span class="token number">0</span>
<span class="token keyword">Type</span> <span class="token string">'help;'</span> <span class="token operator">or</span> <span class="token string">'\h'</span> <span class="token keyword">for</span> <span class="token keyword">help</span><span class="token punctuation">.</span> <span class="token keyword">Type</span> <span class="token string">'\c'</span> <span class="token keyword">to</span> clear the buffer<span class="token punctuation">.</span>
<span class="token prompt">mysql></span></code></pre>
</div>
<p>
We simply use the MySQL server's
<code class="literal">
root
</code>
account and assume that you have followed the standard security
precautions for installing a MySQL server, including setting a
strong
<code class="literal">
root
</code>
password. For more information, see
<a class="xref" href="default-privileges.html" title="2.9.4 Securing the Initial MySQL Account">
Section 2.9.4, “Securing the Initial MySQL Account”
</a>
.
</p>
<p>
It is worth taking into account that NDB Cluster nodes do
<span class="emphasis">
<em>
not
</em>
</span>
make use of the MySQL privilege system
when accessing one another. Setting or changing MySQL user
accounts (including the
<code class="literal">
root
</code>
account) effects
only applications that access the SQL node, not interaction
between nodes. See
<a class="xref" href="mysql-cluster-security-mysql-privileges.html" title="25.6.21.2 NDB Cluster and MySQL Privileges">
Section 25.6.21.2, “NDB Cluster and MySQL Privileges”
</a>
, for
more information.
</p>
<p>
If you did not modify the
<code class="literal">
ENGINE
</code>
clauses in the
table definitions prior to importing the SQL script, you should
run the following statements at this point:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa3427803"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">USE</span> world<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> City <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> Country <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> CountryLanguage <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDBCLUSTER</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Selecting a database and running a
<span class="command">
<strong>
SELECT
</strong>
</span>
query
against a table in that database is also accomplished in the usual
manner, as is exiting the MySQL Monitor:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68041014"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">USE</span> world<span class="token punctuation">;</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token keyword">Name</span><span class="token punctuation">,</span> Population <span class="token keyword">FROM</span> City <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> Population <span class="token keyword">DESC</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>
<span class="token output"><span class="token punctuation">|</span> Name <span class="token punctuation">|</span> Population <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> Bombay <span class="token punctuation">|</span> 10500000 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Seoul <span class="token punctuation">|</span> 9981619 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> São Paulo <span class="token punctuation">|</span> 9968485 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Shanghai <span class="token punctuation">|</span> 9696300 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Jakarta <span class="token punctuation">|</span> 9604900 <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">5 rows in set (0.34 sec)</span>
<span class="token prompt">mysql></span> \q
Bye
$<span class="token operator">></span></code></pre>
</div>
<p>
Applications that use MySQL can employ standard APIs to access
<a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
<code class="literal">
NDB
</code>
</a>
tables. It is important to
remember that your application must access the SQL node, and not
the management or data nodes. This brief example shows how we
might execute the
<a class="link" href="select.html" title="15.2.13 SELECT Statement">
<code class="literal">
SELECT
</code>
</a>
statement
just shown by using the PHP 5.X
<code class="literal">
mysqli
</code>
extension running on a Web server elsewhere on the network:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-php"><div class="docs-select-all right" id="sa83023363"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-php"><span class="token doctype"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>html</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>head</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>meta</span> <span class="token attr-name">http-equiv</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Content-Type<span class="token punctuation">"</span></span>
<span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/html; charset<span class="token punctuation">=</span>iso-8859-1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>title</span><span class="token punctuation">></span></span>SIMPLE mysqli SELECT<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>title</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>head</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>body</span><span class="token punctuation">></span></span>
<span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token shell-comment comment"># connect to SQL node:</span>
<span class="token variable">$link</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">mysqli</span><span class="token punctuation">(</span><span class="token string">'198.51.100.20'</span><span class="token punctuation">,</span> <span class="token string">'root'</span><span class="token punctuation">,</span> <span class="token string">'<em class="replaceable">root_password</em>'</span><span class="token punctuation">,</span> <span class="token string">'world'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token shell-comment comment"># parameters for mysqli constructor are:</span>
<span class="token shell-comment comment"># host, user, password, database</span>
<span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token function">mysqli_connect_errno</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token keyword">die</span><span class="token punctuation">(</span><span class="token string">"Connect failed: "</span> <span class="token punctuation">.</span> <span class="token function">mysqli_connect_error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$query</span> <span class="token operator">=</span> "<span class="token constant">SELECT</span> Name<span class="token punctuation">,</span> Population
<span class="token constant">FROM</span> City
<span class="token constant">ORDER</span> <span class="token constant">BY</span> Population <span class="token constant">DESC</span>
<span class="token constant">LIMIT</span> <span class="token number">5</span>"<span class="token punctuation">;</span>
<span class="token shell-comment comment"># if no errors...</span>
<span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token variable">$result</span> <span class="token operator">=</span> <span class="token variable">$link</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">query</span><span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token delimiter important">?></span></span>
<table border="1" width="40%" cellpadding="4" cellspacing ="1">
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>tbody</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>th</span> <span class="token attr-name">width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>10%<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>City<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>th</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>th</span><span class="token punctuation">></span></span>Population<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>th</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>tr</span><span class="token punctuation">></span></span>
<span class="token php language-php"><span class="token delimiter important"><?</span>
<span class="token shell-comment comment"># then display the results...</span>
<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token variable">$row</span> <span class="token operator">=</span> <span class="token variable">$result</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">fetch_object</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"<tr>\n <td align=\"center\">%s</td><td>%d</td>\n</tr>\n"</span><span class="token punctuation">,</span>
<span class="token variable">$row</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">Name</span><span class="token punctuation">,</span> <span class="token variable">$row</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">Population</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>
</tbody
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>table</span><span class="token punctuation">></span></span>
<span class="token php language-php"><span class="token delimiter important"><?</span>
<span class="token shell-comment comment"># ...and verify the number of rows that were retrieved</span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"<p>Affected rows: %d</p>\n"</span><span class="token punctuation">,</span> <span class="token variable">$link</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">affected_rows</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">else</span>
<span class="token shell-comment comment"># otherwise, tell us what went wrong</span>
<span class="token keyword">echo</span> <span class="token function">mysqli_error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token shell-comment comment"># free the result set and the mysqli connection object</span>
<span class="token variable">$result</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token variable">$link</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>body</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>html</span><span class="token punctuation">></span></span></code></pre>
</div>
<p>
We assume that the process running on the Web server can reach the
IP address of the SQL node.
</p>
<p>
In a similar fashion, you can use the MySQL C API, Perl-DBI,
Python-mysql, or MySQL Connectors to perform the tasks of data
definition and manipulation just as you would normally with MySQL.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/sys-waits-by-user-by-latency.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="sys-waits-by-user-by-latency">
</a>
30.4.3.51 The waits_by_user_by_latency and x$waits_by_user_by_latency Views
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045061720176">
</a>
<a class="indexterm" name="idm46045061718720">
</a>
<a class="indexterm" name="idm46045061717216">
</a>
<a class="indexterm" name="idm46045061715712">
</a>
<p>
These views summarize wait events, grouped by user and event.
By default, rows are sorted by user and descending total
latency. Idle events are ignored.
</p>
<p>
The
<a class="link" href="sys-waits-by-user-by-latency.html" title="30.4.3.51 The waits_by_user_by_latency and x$waits_by_user_by_latency Views">
<code class="literal">
waits_by_user_by_latency
</code>
</a>
and
<a class="link" href="sys-waits-by-user-by-latency.html" title="30.4.3.51 The waits_by_user_by_latency and x$waits_by_user_by_latency Views">
<code class="literal">
x$waits_by_user_by_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">
user
</code>
</p>
<p>
The user associated with the connection.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
event
</code>
</p>
<p>
The event name.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
total
</code>
</p>
<p>
The total number of occurrences of the event for the user.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
total_latency
</code>
</p>
<p>
The total wait time of timed occurrences of the event for
the user.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
avg_latency
</code>
</p>
<p>
The average wait time per timed occurrence of the event
for the user.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
max_latency
</code>
</p>
<p>
The maximum single wait time of timed occurrences of the
event for the user.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/memory-use.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="memory-use">
</a>
10.12.3.1 How MySQL Uses Memory
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045222344288">
</a>
<p>
MySQL allocates buffers and caches to improve performance of
database operations. The default configuration is designed to
permit a MySQL server to start on a virtual machine that has
approximately 512MB of RAM. You can improve MySQL performance
by increasing the values of certain cache and buffer-related
system variables. You can also modify the default
configuration to run MySQL on systems with limited memory.
</p>
<p>
The following list describes some of the ways that MySQL uses
memory. Where applicable, relevant system variables are
referenced. Some items are storage engine or feature specific.
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The
<code class="literal">
InnoDB
</code>
buffer pool is a memory area
that holds cached
<code class="literal">
InnoDB
</code>
data for
tables, indexes, and other auxiliary buffers. For
efficiency of high-volume read operations, the buffer pool
is divided into
<a class="link" href="glossary.html#glos_page" title="page">
pages
</a>
that can potentially hold multiple rows. For efficiency of
cache management, the buffer pool is implemented as a
linked list of pages; data that is rarely used is aged out
of the cache, using a variation of the
<a class="link" href="glossary.html#glos_lru" title="LRU">
LRU
</a>
algorithm. For more
information, see
<a class="xref" href="innodb-buffer-pool.html" title="17.5.1 Buffer Pool">
Section 17.5.1, “Buffer Pool”
</a>
.
</p>
<p>
The size of the buffer pool is important for system
performance:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
<code class="literal">
InnoDB
</code>
allocates memory for the
entire buffer pool at server startup, using
<code class="literal">
malloc()
</code>
operations. The
<a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_size">
<code class="literal">
innodb_buffer_pool_size
</code>
</a>
system variable defines the buffer pool size.
Typically, a recommended
<a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_size">
<code class="literal">
innodb_buffer_pool_size
</code>
</a>
value is 50 to 75 percent of system memory.
<a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_size">
<code class="literal">
innodb_buffer_pool_size
</code>
</a>
can be configured dynamically, while the server is
running. For more information, see
<a class="xref" href="innodb-buffer-pool-resize.html" title="17.8.3.1 Configuring InnoDB Buffer Pool Size">
Section 17.8.3.1, “Configuring InnoDB Buffer Pool Size”
</a>
.
</p>
</li>
<li class="listitem">
<p>
On systems with a large amount of memory, you can
improve concurrency by dividing the buffer pool into
multiple
<a class="link" href="glossary.html#glos_buffer_pool_instance" title="buffer pool instance">
buffer pool
instances
</a>
. The
<a class="link" href="innodb-parameters.html#sysvar_innodb_buffer_pool_instances">
<code class="literal">
innodb_buffer_pool_instances
</code>
</a>
system variable defines the number of buffer pool
instances.
</p>
</li>
<li class="listitem">
<p>
A buffer pool that is too small may cause excessive
churning as pages are flushed from the buffer pool
only to be required again a short time later.
</p>
</li>
<li class="listitem">
<p>
A buffer pool that is too large may cause swapping due
to competition for memory.
</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>
The storage engine interface enables the optimizer to
provide information about the size of the record buffer to
be used for scans that the optimizer estimates are likely
to read multiple rows. The buffer size can vary based on
the size of the estimate.
<code class="literal">
InnoDB
</code>
uses
this variable-size buffering capability to take advantage
of row prefetching, and to reduce the overhead of latching
and B-tree navigation.
</p>
</li>
<li class="listitem">
<p>
All threads share the
<a class="link" href="myisam-storage-engine.html" title="18.2 The MyISAM Storage Engine">
<code class="literal">
MyISAM
</code>
</a>
key buffer. The
<a class="link" href="server-system-variables.html#sysvar_key_buffer_size">
<code class="literal">
key_buffer_size
</code>
</a>
system
variable determines its size.
</p>
<p>
For each
<code class="literal">
MyISAM
</code>
table the server opens,
the index file is opened once; the data file is opened
once for each concurrently running thread that accesses
the table. For each concurrent thread, a table structure,
column structures for each column, and a buffer of size
<code class="literal">
3 *
<em class="replaceable">
<code>
N
</code>
</em>
</code>
are
allocated (where
<em class="replaceable">
<code>
N
</code>
</em>
is the
maximum row length, not counting
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
columns). A
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
column requires five
to eight bytes plus the length of the
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
data. The
<code class="literal">
MyISAM
</code>
storage engine maintains one
extra row buffer for internal use.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="server-system-variables.html#sysvar_myisam_use_mmap">
<code class="literal">
myisam_use_mmap
</code>
</a>
system variable can be set to 1 to enable memory-mapping
for all
<code class="literal">
MyISAM
</code>
tables.
</p>
</li>
<li class="listitem">
<p>
If an internal in-memory temporary table becomes too large
(as determined by
<a class="link" href="server-system-variables.html#sysvar_tmp_table_size">
<code class="literal">
tmp_table_size
</code>
</a>
and
<a class="link" href="server-system-variables.html#sysvar_max_heap_table_size">
<code class="literal">
max_heap_table_size
</code>
</a>
),
MySQL automatically converts the table from in-memory to
on-disk format, which uses the
<code class="literal">
InnoDB
</code>
storage engine. You can increase the permissible temporary
table size as described in
<a class="xref" href="internal-temporary-tables.html" title="10.4.4 Internal Temporary Table Use in MySQL">
Section 10.4.4, “Internal Temporary Table Use in MySQL”
</a>
.
</p>
<p>
For
<a class="link" href="memory-storage-engine.html" title="18.3 The MEMORY Storage Engine">
<code class="literal">
MEMORY
</code>
</a>
tables explicitly
created with
<a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
<code class="literal">
CREATE TABLE
</code>
</a>
,
only 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 determines how large a table can grow, and
there is no conversion to on-disk format.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="performance-schema.html" title="Chapter 29 MySQL Performance Schema">
MySQL Performance
Schema
</a>
is a feature for monitoring MySQL server
execution at a low level. The Performance Schema
dynamically allocates memory incrementally, scaling its
memory use to actual server load, instead of allocating
required memory during server startup. Once memory is
allocated, it is not freed until the server is restarted.
For more information, see
<a class="xref" href="performance-schema-memory-model.html" title="29.17 The Performance Schema Memory-Allocation Model">
Section 29.17, “The Performance Schema Memory-Allocation Model”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Each thread that the server uses to manage client
connections requires some thread-specific space. The
following list indicates these and which system variables
control their size:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
A stack
(
<a class="link" href="server-system-variables.html#sysvar_thread_stack">
<code class="literal">
thread_stack
</code>
</a>
)
</p>
</li>
<li class="listitem">
<p>
A connection buffer
(
<a class="link" href="server-system-variables.html#sysvar_net_buffer_length">
<code class="literal">
net_buffer_length
</code>
</a>
)
</p>
</li>
<li class="listitem">
<p>
A result buffer
(
<a class="link" href="server-system-variables.html#sysvar_net_buffer_length">
<code class="literal">
net_buffer_length
</code>
</a>
)
</p>
</li>
</ul>
</div>
<p>
The connection buffer and result buffer each begin with a
size equal to
<a class="link" href="server-system-variables.html#sysvar_net_buffer_length">
<code class="literal">
net_buffer_length
</code>
</a>
bytes,
but are dynamically enlarged up to
<a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
<code class="literal">
max_allowed_packet
</code>
</a>
bytes
as needed. The result buffer shrinks to
<a class="link" href="server-system-variables.html#sysvar_net_buffer_length">
<code class="literal">
net_buffer_length
</code>
</a>
bytes
after each SQL statement. While a statement is running, a
copy of the current statement string is also allocated.
</p>
<p>
Each connection thread uses memory for computing statement
digests. The server allocates
<a class="link" href="server-system-variables.html#sysvar_max_digest_length">
<code class="literal">
max_digest_length
</code>
</a>
bytes
per session. 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>
</li>
<li class="listitem">
<p>
All threads share the same base memory.
</p>
</li>
<li class="listitem">
<p>
When a thread is no longer needed, the memory allocated to
it is released and returned to the system unless the
thread goes back into the thread cache. In that case, the
memory remains allocated.
</p>
</li>
<li class="listitem">
<p>
Each request that performs a sequential scan of a table
allocates a
<span class="firstterm">
read
buffer
</span>
. The
<a class="link" href="server-system-variables.html#sysvar_read_buffer_size">
<code class="literal">
read_buffer_size
</code>
</a>
system
variable determines the buffer size.
</p>
</li>
<li class="listitem">
<p>
When reading rows in an arbitrary sequence (for example,
following a sort), a
<span class="firstterm">
random-read buffer
</span>
may be allocated to avoid disk seeks. The
<a class="link" href="server-system-variables.html#sysvar_read_rnd_buffer_size">
<code class="literal">
read_rnd_buffer_size
</code>
</a>
system variable determines the buffer size.
</p>
</li>
<li class="listitem">
<p>
All joins are executed in a single pass, and most joins
can be done without even using a temporary table. Most
temporary tables are memory-based hash tables. Temporary
tables with a large row length (calculated as the sum of
all column lengths) or that contain
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
columns are stored on
disk.
</p>
</li>
<li class="listitem">
<p>
Most requests that perform a sort allocate a sort buffer
and zero to two temporary files depending on the result
set size. See
<a class="xref" href="temporary-files.html" title="B.3.3.5 Where MySQL Stores Temporary Files">
Section B.3.3.5, “Where MySQL Stores Temporary Files”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Almost all parsing and calculating is done in thread-local
and reusable memory pools. No memory overhead is needed
for small items, thus avoiding the normal slow memory
allocation and freeing. Memory is allocated only for
unexpectedly large strings.
</p>
</li>
<li class="listitem">
<p>
For each table having
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
columns, a buffer is enlarged dynamically to read in
larger
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
values. If you
scan a table, the buffer grows as large as the largest
<a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
<code class="literal">
BLOB
</code>
</a>
value.
</p>
</li>
<li class="listitem">
<p>
MySQL requires memory and descriptors for the table cache.
Handler structures for all in-use tables are saved in the
table cache and managed as
<span class="quote">
“
<span class="quote">
First In, First
Out
</span>
”
</span>
(FIFO). The
<a class="link" href="server-system-variables.html#sysvar_table_open_cache">
<code class="literal">
table_open_cache
</code>
</a>
system
variable defines the initial table cache size; see
<a class="xref" href="table-cache.html" title="10.4.3.1 How MySQL Opens and Closes Tables">
Section 10.4.3.1, “How MySQL Opens and Closes Tables”
</a>
.
</p>
<p>
MySQL also requires memory for the table definition cache.
The
<a class="link" href="server-system-variables.html#sysvar_table_definition_cache">
<code class="literal">
table_definition_cache
</code>
</a>
system variable defines the number of table definitions
that can be stored in the table definition cache. If you
use a large number of tables, you can create a large table
definition cache to speed up the opening of tables. The
table definition cache takes less space and does not use
file descriptors, unlike the table cache.
</p>
</li>
<li class="listitem">
<p>
A
<a class="link" href="flush.html#flush-tables">
<code class="literal">
FLUSH TABLES
</code>
</a>
statement or
<a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
<span class="command">
<strong>
mysqladmin flush-tables
</strong>
</span>
</a>
command closes
all tables that are not in use at once and marks all
in-use tables to be closed when the currently executing
thread finishes. This effectively frees most in-use
memory.
<a class="link" href="flush.html#flush-tables">
<code class="literal">
FLUSH TABLES
</code>
</a>
does
not return until all tables have been closed.
</p>
</li>
<li class="listitem">
<p>
The server caches information in memory as a result of
<a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
<code class="literal">
GRANT
</code>
</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="create-server.html" title="15.1.18 CREATE SERVER Statement">
<code class="literal">
CREATE SERVER
</code>
</a>
, and
<a class="link" href="install-plugin.html" title="15.7.4.4 INSTALL PLUGIN Statement">
<code class="literal">
INSTALL PLUGIN
</code>
</a>
statements.
This memory is not released by the corresponding
<a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
<code class="literal">
REVOKE
</code>
</a>
,
<a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
<code class="literal">
DROP USER
</code>
</a>
,
<a class="link" href="drop-server.html" title="15.1.30 DROP SERVER Statement">
<code class="literal">
DROP SERVER
</code>
</a>
, and
<a class="link" href="uninstall-plugin.html" title="15.7.4.6 UNINSTALL PLUGIN Statement">
<code class="literal">
UNINSTALL PLUGIN
</code>
</a>
statements, so for a server that executes many instances
of the statements that cause caching, there is an increase
in cached memory use unless it is freed with
<a class="link" href="flush.html#flush-privileges">
<code class="literal">
FLUSH PRIVILEGES
</code>
</a>
.
</p>
</li>
<li class="listitem">
<p>
In a replication topology, the following settings affect
memory usage, and can be adjusted as required:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
The
<a class="link" href="server-system-variables.html#sysvar_max_allowed_packet">
<code class="literal">
max_allowed_packet
</code>
</a>
system variable on a replication source limits the
maximum message size that the source sends to its
replicas for processing. This setting defaults to 64M.
</p>
</li>
<li class="listitem">
<p>
The system variable
<a class="link" href="replication-options-replica.html#sysvar_replica_pending_jobs_size_max">
<code class="literal">
replica_pending_jobs_size_max
</code>
</a>
on a multithreaded replica sets the maximum amount of
memory that is made available for holding messages
awaiting processing. This setting defaults to 128M.
The memory is only allocated when needed, but it might
be used if your replication topology handles large
transactions sometimes. It is a soft limit, and larger
transactions can be processed.
</p>
</li>
<li class="listitem">
<p>
The
<a class="link" href="replication-options-replica.html#sysvar_rpl_read_size">
<code class="literal">
rpl_read_size
</code>
</a>
system variable on a replication source or replica
controls the minimum amount of data in bytes that is
read from the binary log files and relay log files.
The default is 8192 bytes. A buffer the size of this
value is allocated for each thread that reads from the
binary log and relay log files, including dump threads
on sources and coordinator threads on replicas.
</p>
</li>
<li class="listitem">
<p>
The
<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>
system variable limits the number of row hashes held
as an in-memory history.
</p>
</li>
<li class="listitem">
<p>
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 specifies the upper limit of memory
usage by an individual transaction.
</p>
</li>
<li class="listitem">
<p>
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 specifies the upper limit of memory
usage by the statement cache.
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>
<span class="command">
<strong>
ps
</strong>
</span>
and other system status programs may
report that
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
uses a lot of memory.
This may be caused by thread stacks on different memory
addresses. For example, the Solaris version of
<span class="command">
<strong>
ps
</strong>
</span>
counts the unused memory between stacks
as used memory. To verify this, check available swap with
<code class="literal">
swap -s
</code>
. We test
<a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
<span class="command">
<strong>
mysqld
</strong>
</span>
</a>
with several memory-leakage detectors (both commercial and
Open Source), so there should be no memory leaks.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/xa-restrictions.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="xa-restrictions">
</a>
15.3.8.3 Restrictions on XA Transactions
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045177966560">
</a>
<a class="indexterm" name="idm46045177965104">
</a>
<p>
XA transaction support is limited to the
<code class="literal">
InnoDB
</code>
storage engine.
</p>
<p>
For
<span class="quote">
“
<span class="quote">
external XA,
</span>
”
</span>
a MySQL server acts as a
Resource Manager and client programs act as Transaction
Managers. For
<span class="quote">
“
<span class="quote">
Internal XA
</span>
”
</span>
, storage engines within
a MySQL server act as RMs, and the server itself acts as a TM.
Internal XA support is limited by the capabilities of individual
storage engines. Internal XA is required for handling XA
transactions that involve more than one storage engine. The
implementation of internal XA requires that a storage engine
support two-phase commit at the table handler level, and
currently this is true only for
<code class="literal">
InnoDB
</code>
.
</p>
<p>
For
<a class="link" href="xa-statements.html" title="15.3.8.1 XA Transaction SQL Statements">
<code class="literal">
XA
START
</code>
</a>
, the
<code class="literal">
JOIN
</code>
and
<code class="literal">
RESUME
</code>
clauses are recognized but have no
effect.
</p>
<p>
For
<a class="link" href="xa-statements.html" title="15.3.8.1 XA Transaction SQL Statements">
<code class="literal">
XA
END
</code>
</a>
the
<code class="literal">
SUSPEND [FOR MIGRATE]
</code>
clause is recognized but has no effect.
</p>
<p>
The requirement that the
<em class="replaceable">
<code>
bqual
</code>
</em>
part
of the
<em class="replaceable">
<code>
xid
</code>
</em>
value be different for
each XA transaction within a global transaction is a limitation
of the current MySQL XA implementation. It is not part of the XA
specification.
</p>
<p>
An XA transaction is written to the binary log in two parts.
When
<code class="literal">
XA PREPARE
</code>
is issued, the first part of
the transaction up to
<code class="literal">
XA PREPARE
</code>
is written
using an initial GTID. A
<code class="literal">
XA_prepare_log_event
</code>
is used to identify such transactions in the binary log. When
<code class="literal">
XA COMMIT
</code>
or
<code class="literal">
XA ROLLBACK
</code>
is issued, a second part of the transaction containing only the
<code class="literal">
XA COMMIT
</code>
or
<code class="literal">
XA ROLLBACK
</code>
statement is written using a second GTID. Note that the initial
part of the transaction, identified by
<code class="literal">
XA_prepare_log_event
</code>
, is not necessarily
followed by its
<code class="literal">
XA COMMIT
</code>
or
<code class="literal">
XA
ROLLBACK
</code>
, which can cause interleaved binary logging
of any two XA transactions. The two parts of the XA transaction
can even appear in different binary log files. This means that
an XA transaction in
<code class="literal">
PREPARED
</code>
state is now
persistent until an explicit
<code class="literal">
XA COMMIT
</code>
or
<code class="literal">
XA ROLLBACK
</code>
statement is issued, ensuring
that XA transactions are compatible with replication.
</p>
<p>
On a replica, immediately after the XA transaction is prepared,
it is detached from the replication applier thread, and can be
committed or rolled back by any thread on the replica. This
means that the same XA transaction can appear in the
<a class="link" href="performance-schema-events-transactions-current-table.html" title="29.12.7.1 The events_transactions_current Table">
<code class="literal">
events_transactions_current
</code>
</a>
table
with different states on different threads. The
<a class="link" href="performance-schema-events-transactions-current-table.html" title="29.12.7.1 The events_transactions_current Table">
<code class="literal">
events_transactions_current
</code>
</a>
table
displays the current status of the most recent monitored
transaction event on the thread, and does not update this status
when the thread is idle. So the XA transaction can still be
displayed in the
<code class="literal">
PREPARED
</code>
state for the
original applier thread, after it has been processed by another
thread. To positively identify XA transactions that are still in
the
<code class="literal">
PREPARED
</code>
state and need to be recovered,
use the
<a class="link" href="xa-statements.html" title="15.3.8.1 XA Transaction SQL Statements">
<code class="literal">
XA
RECOVER
</code>
</a>
statement rather than the Performance Schema
transaction tables.
</p>
<p>
The following restrictions exist for using XA transactions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
The use of replication filters or binary log filters in
combination with XA transactions is not supported. Filtering
of tables could cause an XA transaction to be empty on a
replica, and empty XA transactions are not supported. Also,
with the replica's connection metadata repository and
applier metadata repository stored in
<a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
<code class="literal">
InnoDB
</code>
</a>
tables (the default),
the internal state of the data engine transaction is changed
following a filtered XA transaction, and can become
inconsistent with the replication transaction context state.
</p>
<p>
The error
<a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_xa_replication_filters" target="_top">
<code class="literal">
ER_XA_REPLICATION_FILTERS
</code>
</a>
is
logged whenever an XA transaction is impacted by a
replication filter, whether or not the transaction was empty
as a result. If the transaction is not empty, the replica is
able to continue running, but you should take steps to
discontinue the use of replication filters with XA
transactions in order to avoid potential issues. If the
transaction is empty, the replica stops. In that event, the
replica might be in an undetermined state in which the
consistency of the replication process might be compromised.
In particular, the
<code class="literal">
gtid_executed
</code>
set on a
replica of the replica might be inconsistent with that on
the source. To resolve this situation, isolate the source
and stop all replication, then check GTID consistency across
the replication topology. Undo the XA transaction that
generated the error message, then restart replication.
</p>
</li>
<li class="listitem">
<p>
XA transactions are considered unsafe for statement-based
replication. If two XA transactions committed in parallel on
the source are being prepared on the replica in the inverse
order, locking dependencies can occur that cannot be safely
resolved, and it is possible for replication to fail with
deadlock on the replica. This situation can occur for a
single-threaded or multithreaded replica. When
<a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
<code class="literal">
binlog_format=STATEMENT
</code>
</a>
is
set, a warning is issued for DML statements inside XA
transactions. 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>
You should be aware that, when the same transaction XID is
used to execute XA transactions sequentially and a break
occurs during the processing of
<a class="link" href="xa-statements.html" title="15.3.8.1 XA Transaction SQL Statements">
<code class="literal">
XA COMMIT ...
ONE PHASE
</code>
</a>
, it may no longer be possible to
synchronize the state between the binary log and the storage
engine. This can occur if the series of events just
described takes place after this transaction has been
prepared in the storage engine, while the
<code class="literal">
XA
COMMIT
</code>
statement is still executing. This is a
known issue.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/declare-handler.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="declare-handler">
</a>
15.6.7.2 DECLARE ... HANDLER Statement
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045176040896">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32147597"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <em class="replaceable">handler_action</em> <span class="token keyword">HANDLER</span>
<span class="token keyword">FOR</span> <em class="replaceable">condition_value</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">condition_value</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<em class="replaceable">statement</em>
<em class="replaceable">handler_action</em>: {
<span class="token keyword">CONTINUE</span>
<span class="token operator">|</span> <span class="token keyword">EXIT</span>
<span class="token operator">|</span> <span class="token keyword">UNDO</span>
}
<em class="replaceable">condition_value</em>: {
<em class="replaceable">mysql_error_code</em>
<span class="token operator">|</span> <span class="token keyword">SQLSTATE</span> <span class="token punctuation">[</span><span class="token keyword">VALUE</span><span class="token punctuation">]</span> <em class="replaceable">sqlstate_value</em>
<span class="token operator">|</span> <em class="replaceable">condition_name</em>
<span class="token operator">|</span> <span class="token keyword">SQLWARNING</span>
<span class="token operator">|</span> <span class="token operator">NOT</span> <span class="token keyword">FOUND</span>
<span class="token operator">|</span> <span class="token keyword">SQLEXCEPTION</span>
}</code></pre>
</div>
<p>
The
<a class="link" href="declare-handler.html" title="15.6.7.2 DECLARE ... HANDLER Statement">
<code class="literal">
DECLARE ...
HANDLER
</code>
</a>
statement specifies a handler that deals with
one or more conditions. If one of these conditions occurs, the
specified
<em class="replaceable">
<code>
statement
</code>
</em>
executes.
<em class="replaceable">
<code>
statement
</code>
</em>
can be a simple statement
such as
<code class="literal">
SET
<em class="replaceable">
<code>
var_name
</code>
</em>
=
<em class="replaceable">
<code>
value
</code>
</em>
</code>
, or a compound
statement written using
<code class="literal">
BEGIN
</code>
and
<code class="literal">
END
</code>
(see
<a class="xref" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
Section 15.6.1, “BEGIN ... END Compound Statement”
</a>
).
</p>
<p>
Handler declarations must appear after variable or condition
declarations.
</p>
<p>
The
<em class="replaceable">
<code>
handler_action
</code>
</em>
value indicates
what action the handler takes after execution of the handler
statement:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<code class="literal">
CONTINUE
</code>
: Execution of the current
program continues.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
EXIT
</code>
: Execution terminates for the
<a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
<code class="literal">
BEGIN ...
END
</code>
</a>
compound statement in which the handler is
declared. This is true even if the condition occurs in an
inner block.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
UNDO
</code>
: Not supported.
</p>
</li>
</ul>
</div>
<p>
The
<em class="replaceable">
<code>
condition_value
</code>
</em>
for
<a class="link" href="declare-handler.html" title="15.6.7.2 DECLARE ... HANDLER Statement">
<code class="literal">
DECLARE ...
HANDLER
</code>
</a>
indicates the specific condition or class of
conditions that activates the handler. It can take the following
forms:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<em class="replaceable">
<code>
mysql_error_code
</code>
</em>
: An integer
literal indicating a MySQL error code, such as 1051 to
specify
<span class="quote">
“
<span class="quote">
unknown table
</span>
”
</span>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa78756762"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token number">1051</span>
<span class="token keyword">BEGIN</span>
<span class="token comment" spellcheck="true">-- body of handler</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Do not use MySQL error code 0 because that indicates success
rather than an error condition. For a list of MySQL error
codes, see
<a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html" target="_top">
Server Error Message Reference
</a>
.
</p>
</li>
<li class="listitem">
<p>
SQLSTATE [VALUE]
<em class="replaceable">
<code>
sqlstate_value
</code>
</em>
:
A 5-character string literal indicating an SQLSTATE value,
such as
<code class="literal">
'42S01'
</code>
to specify
<span class="quote">
“
<span class="quote">
unknown
table
</span>
”
</span>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99446362"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'42S02'</span>
<span class="token keyword">BEGIN</span>
<span class="token comment" spellcheck="true">-- body of handler</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Do not use SQLSTATE values that begin with
<code class="literal">
'00'
</code>
because those indicate success
rather than an error condition. For a list of SQLSTATE
values, see
<a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html" target="_top">
Server Error Message Reference
</a>
.
</p>
</li>
<li class="listitem">
<p>
<em class="replaceable">
<code>
condition_name
</code>
</em>
: A condition name
previously specified with
<a class="link" href="declare-condition.html" title="15.6.7.1 DECLARE ... CONDITION Statement">
<code class="literal">
DECLARE
... CONDITION
</code>
</a>
. A condition name can be associated
with a MySQL error code or SQLSTATE value. See
<a class="xref" href="declare-condition.html" title="15.6.7.1 DECLARE ... CONDITION Statement">
Section 15.6.7.1, “DECLARE ... CONDITION Statement”
</a>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SQLWARNING
</code>
: Shorthand for the class of
SQLSTATE values that begin with
<code class="literal">
'01'
</code>
.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa77822029"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLWARNING</span>
<span class="token keyword">BEGIN</span>
<span class="token comment" spellcheck="true">-- body of handler</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
<code class="literal">
NOT FOUND
</code>
: Shorthand for the class of
SQLSTATE values that begin with
<code class="literal">
'02'
</code>
.
This is relevant within the context of cursors and is used
to control what happens when a cursor reaches the end of a
data set. If no more rows are available, a No Data condition
occurs with SQLSTATE value
<code class="literal">
'02000'
</code>
. To
detect this condition, you can set up a handler for it or
for a
<code class="literal">
NOT FOUND
</code>
condition.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa44015137"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token operator">NOT</span> <span class="token keyword">FOUND</span>
<span class="token keyword">BEGIN</span>
<span class="token comment" spellcheck="true">-- body of handler</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
For another example, see
<a class="xref" href="cursors.html" title="15.6.6 Cursors">
Section 15.6.6, “Cursors”
</a>
. The
<code class="literal">
NOT FOUND
</code>
condition also occurs for
<code class="literal">
SELECT ... INTO
<em class="replaceable">
<code>
var_list
</code>
</em>
</code>
statements
that retrieve no rows.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
SQLEXCEPTION
</code>
: Shorthand for the class of
SQLSTATE values that do not begin with
<code class="literal">
'00'
</code>
,
<code class="literal">
'01'
</code>
, or
<code class="literal">
'02'
</code>
.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32256674"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLEXCEPTION</span>
<span class="token keyword">BEGIN</span>
<span class="token comment" spellcheck="true">-- body of handler</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
</ul>
</div>
<p>
For information about how the server chooses handlers when a
condition occurs, see
<a class="xref" href="handler-scope.html" title="15.6.7.6 Scope Rules for Handlers">
Section 15.6.7.6, “Scope Rules for Handlers”
</a>
.
</p>
<p>
If a condition occurs for which no handler has been declared,
the action taken depends on the condition class:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
For
<code class="literal">
SQLEXCEPTION
</code>
conditions, the stored
program terminates at the statement that raised the
condition, as if there were an
<code class="literal">
EXIT
</code>
handler. If the program was called by another stored
program, the calling program handles the condition using the
handler selection rules applied to its own handlers.
</p>
</li>
<li class="listitem">
<p>
For
<code class="literal">
SQLWARNING
</code>
conditions, the program
continues executing, as if there were a
<code class="literal">
CONTINUE
</code>
handler.
</p>
</li>
<li class="listitem">
<p>
For
<code class="literal">
NOT FOUND
</code>
conditions, if the
condition was raised normally, the action is
<code class="literal">
CONTINUE
</code>
. If it was raised by
<a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
<code class="literal">
SIGNAL
</code>
</a>
or
<a class="link" href="resignal.html" title="15.6.7.4 RESIGNAL Statement">
<code class="literal">
RESIGNAL
</code>
</a>
, the action is
<code class="literal">
EXIT
</code>
.
</p>
</li>
</ul>
</div>
<p>
The following example uses a handler for
<code class="literal">
SQLSTATE
'23000'
</code>
, which occurs for a duplicate-key error:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86090267"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> test<span class="token punctuation">.</span>t <span class="token punctuation">(</span>s1 <span class="token datatype">INT</span><span class="token punctuation">,</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span>s1<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">delimiter</span> <span class="token comment" spellcheck="true">//</span>
<span class="token prompt">mysql></span> <span class="token keyword">CREATE</span> <span class="token keyword">PROCEDURE</span> handlerdemo <span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLSTATE</span> <span class="token string">'23000'</span> <span class="token keyword">SET</span> <span class="token variable">@x2</span> <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 variable">@x</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> test<span class="token punctuation">.</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 punctuation">;</span>
<span class="token keyword">SET</span> <span class="token variable">@x</span> <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> test<span class="token punctuation">.</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 punctuation">;</span>
<span class="token keyword">SET</span> <span class="token variable">@x</span> <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">CALL</span> handlerdemo<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token comment" spellcheck="true">//</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">SELECT</span> <span class="token variable">@x</span><span class="token comment" spellcheck="true">//</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> @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>
<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>
<span class="token number">1</span> <span class="token keyword">row</span> <span class="token keyword">in</span> <span class="token datatype">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span></code></pre>
</div>
<p>
Notice that
<code class="literal">
@x
</code>
is
<code class="literal">
3
</code>
after
the procedure executes, which shows that execution continued to
the end of the procedure after the error occurred. If the
<a class="link" href="declare-handler.html" title="15.6.7.2 DECLARE ... HANDLER Statement">
<code class="literal">
DECLARE ...
HANDLER
</code>
</a>
statement had not been present, MySQL would
have taken the default action (
<code class="literal">
EXIT
</code>
) after
the second
<a class="link" href="insert.html" title="15.2.7 INSERT Statement">
<code class="literal">
INSERT
</code>
</a>
failed due to
the
<code class="literal">
PRIMARY KEY
</code>
constraint, and
<code class="literal">
SELECT @x
</code>
would have returned
<code class="literal">
2
</code>
.
</p>
<p>
To ignore a condition, declare a
<code class="literal">
CONTINUE
</code>
handler for it and associate it with an empty block. For
example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa77692191"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLWARNING</span> <span class="token keyword">BEGIN</span> <span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The scope of a block label does not include the code for
handlers declared within the block. Therefore, the statement
associated with a handler cannot use
<a class="link" href="iterate.html" title="15.6.5.3 ITERATE Statement">
<code class="literal">
ITERATE
</code>
</a>
or
<a class="link" href="leave.html" title="15.6.5.4 LEAVE Statement">
<code class="literal">
LEAVE
</code>
</a>
to refer to labels for
blocks that enclose the handler declaration. Consider the
following example, where the
<a class="link" href="repeat.html" title="15.6.5.6 REPEAT Statement">
<code class="literal">
REPEAT
</code>
</a>
block has a label of
<code class="literal">
retry
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24358799"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">PROCEDURE</span> p <span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">DECLARE</span> i <span class="token datatype">INT</span> <span class="token keyword">DEFAULT</span> <span class="token number">3</span><span class="token punctuation">;</span>
retry:
<span class="token keyword">REPEAT</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLWARNING</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">ITERATE</span> retry<span class="token punctuation">;</span> <span class="token comment" spellcheck="true"># illegal</span>
<span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token keyword">IF</span> i <span class="token operator"><</span> <span class="token number">0</span> <span class="token keyword">THEN</span>
<span class="token keyword">LEAVE</span> retry<span class="token punctuation">;</span> <span class="token comment" spellcheck="true"># legal</span>
<span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> i <span class="token operator">=</span> i <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token keyword">UNTIL</span> <span class="token boolean">FALSE</span> <span class="token keyword">END</span> <span class="token keyword">REPEAT</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The
<code class="literal">
retry
</code>
label is in scope for the
<a class="link" href="if.html" title="15.6.5.2 IF Statement">
<code class="literal">
IF
</code>
</a>
statement within the block. It
is not in scope for the
<code class="literal">
CONTINUE
</code>
handler, so
the reference there is invalid and results in an error:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa84965207"><div class="copy-help left">Press ⌘+C to 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 1308 (42000): LEAVE with no matching label: retry</code></pre>
</div>
<p>
To avoid references to outer labels in handlers, use one of
these strategies:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
To leave the block, use an
<code class="literal">
EXIT
</code>
handler.
If no block cleanup is required, the
<a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
<code class="literal">
BEGIN ...
END
</code>
</a>
handler body can be empty:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa64915816"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">EXIT</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLWARNING</span> <span class="token keyword">BEGIN</span> <span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
Otherwise, put the cleanup statements in the handler body:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35703363"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">DECLARE</span> <span class="token keyword">EXIT</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLWARNING</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword"></span><em class="replaceable"><span class="token keyword">block</span> cleanup statements</em>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
To continue execution, set a status variable in a
<code class="literal">
CONTINUE
</code>
handler that can be checked in
the enclosing block to determine whether the handler was
invoked. The following example uses the variable
<code class="literal">
done
</code>
for this purpose:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24963853"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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">PROCEDURE</span> p <span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">DECLARE</span> i <span class="token datatype">INT</span> <span class="token keyword">DEFAULT</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token keyword">DECLARE</span> done <span class="token datatype">INT</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">FALSE</span><span class="token punctuation">;</span>
retry:
<span class="token keyword">REPEAT</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">DECLARE</span> <span class="token keyword">CONTINUE</span> <span class="token keyword">HANDLER</span> <span class="token keyword">FOR</span> <span class="token keyword">SQLWARNING</span>
<span class="token keyword">BEGIN</span>
<span class="token keyword">SET</span> done <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token keyword">IF</span> done <span class="token operator">OR</span> i <span class="token operator"><</span> <span class="token number">0</span> <span class="token keyword">THEN</span>
<span class="token keyword">LEAVE</span> retry<span class="token punctuation">;</span>
<span class="token keyword">END</span> <span class="token keyword">IF</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> i <span class="token operator">=</span> i <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span>
<span class="token keyword">UNTIL</span> <span class="token boolean">FALSE</span> <span class="token keyword">END</span> <span class="token keyword">REPEAT</span><span class="token punctuation">;</span>
<span class="token keyword">END</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/replication-rules.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="replication-rules">
</a>
19.2.5 How Servers Evaluate Replication Filtering Rules
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="replication-rules-db-options.html">
19.2.5.1 Evaluation of Database-Level Replication and Binary Logging Options
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-rules-table-options.html">
19.2.5.2 Evaluation of Table-Level Replication Options
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-rules-examples.html">
19.2.5.3 Interactions Between Replication Filtering Options
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="replication-rules-channel-based-filters.html">
19.2.5.4 Replication Channel Based Filters
</a>
</span>
</dt>
</dl>
</div>
<p>
If a replication source server does not write a statement to its
binary log, the statement is not replicated. If the server does
log the statement, the statement is sent to all replicas and each
replica determines whether to execute it or ignore it.
</p>
<p>
On the source, you can control which databases to log changes for
by using the
<a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db">
<code class="option">
--binlog-do-db
</code>
</a>
and
<a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db">
<code class="option">
--binlog-ignore-db
</code>
</a>
options to
control binary logging. For a description of the rules that
servers use in evaluating these options, see
<a class="xref" href="replication-rules-db-options.html" title="19.2.5.1 Evaluation of Database-Level Replication and Binary Logging Options">
Section 19.2.5.1, “Evaluation of Database-Level Replication and Binary Logging Options”
</a>
. You should not use
these options to control which databases and tables are
replicated. Instead, use filtering on the replica to control the
events that are executed on the replica.
</p>
<p>
On the replica side, decisions about whether to execute or ignore
statements received from the source are made according to the
<code class="option">
--replicate-*
</code>
options that the replica was
started with. (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>
.) The
filters governed by these options can also be set dynamically
using the
<code class="literal">
CHANGE REPLICATION FILTER
</code>
statement.
The rules governing such filters are the same whether they are
created on startup using
<code class="option">
--replicate-*
</code>
options or
while the replica server is running by
<code class="literal">
CHANGE REPLICATION
FILTER
</code>
. Note that replication filters cannot be used on
Group Replication-specific channels on a MySQL server instance
that is configured for Group Replication, because filtering
transactions on some servers would make the group unable to reach
agreement on a consistent state.
</p>
<p>
In the simplest case, when there are no
<code class="option">
--replicate-*
</code>
options, the replica executes all
statements that it receives from the source. Otherwise, the result
depends on the particular options given.
</p>
<p>
Database-level options
(
<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-ignore-db">
<code class="option">
--replicate-ignore-db
</code>
</a>
) are checked
first; see
<a class="xref" href="replication-rules-db-options.html" title="19.2.5.1 Evaluation of Database-Level Replication and Binary Logging Options">
Section 19.2.5.1, “Evaluation of Database-Level Replication and Binary Logging Options”
</a>
, for a
description of this process. If no database-level options are
used, option checking proceeds to any table-level options that may
be in use (see
<a class="xref" href="replication-rules-table-options.html" title="19.2.5.2 Evaluation of Table-Level Replication Options">
Section 19.2.5.2, “Evaluation of Table-Level Replication Options”
</a>
,
for a discussion of these). If one or more database-level options
are used but none are matched, the statement is not replicated.
</p>
<p>
For statements affecting databases only (that is,
<a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
<code class="literal">
CREATE DATABASE
</code>
</a>
,
<a class="link" href="drop-database.html" title="15.1.24 DROP DATABASE Statement">
<code class="literal">
DROP DATABASE
</code>
</a>
, and
<a class="link" href="alter-database.html" title="15.1.2 ALTER DATABASE Statement">
<code class="literal">
ALTER DATABASE
</code>
</a>
), database-level
options always take precedence over any
<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 other words, for such statements,
<a class="link" href="replication-options-replica.html#option_mysqld_replicate-wild-do-table">
<code class="option">
--replicate-wild-do-table
</code>
</a>
options
are checked if and only if there are no database-level options
that apply.
</p>
<p>
To make it easier to determine what effect a given set of options
has, it is recommended that you avoid mixing
<code class="option">
do-*
</code>
and
<code class="option">
ignore-*
</code>
options, or options containing
wildcards with options which do not.
</p>
<p>
If any
<a class="link" href="replication-options-replica.html#option_mysqld_replicate-rewrite-db">
<code class="option">
--replicate-rewrite-db
</code>
</a>
options were specified, they are applied before the
<code class="option">
--replicate-*
</code>
filtering rules are tested.
</p>
<a class="indexterm" name="idm46045137558608">
</a>
<a class="indexterm" name="idm46045137557104">
</a>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
All replication filtering options follow the same rules for case
sensitivity that apply to names of databases and tables
elsewhere in the MySQL server, including the effects of the
<a class="link" href="server-system-variables.html#sysvar_lower_case_table_names">
<code class="literal">
lower_case_table_names
</code>
</a>
system
variable.
</p>
</div>
<p>
Filtering rules are applied before performing any privilege
checks; if a transaction is filtered out, no privilege check is
performed for that transaction, and thus no error can be raised by
it. See
<a class="xref" href="replication-features-errors.html" title="19.5.1.29 Replica Errors During Replication">
Section 19.5.1.29, “Replica Errors During Replication”
</a>
, for more
information.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/sys-ps-setup-show-enabled-instruments.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="sys-ps-setup-show-enabled-instruments">
</a>
30.4.4.20 The ps_setup_show_enabled_instruments() Procedure
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045061317296">
</a>
<a class="indexterm" name="idm46045061315776">
</a>
<p>
Displays all currently enabled Performance Schema instruments.
This might be a long list.
</p>
<div class="simplesect">
<div class="titlepage">
<div>
<div class="simple">
<h5 class="title">
<a name="sys-ps-setup-show-enabled-instruments-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-enabled-instruments-example">
</a>
Example
</h5>
</div>
</div>
</div>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa89231167"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">CALL</span> sys<span class="token punctuation">.</span>ps_setup_show_enabled_instruments<span class="token punctuation">(</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>
enabled_instruments<span class="token punctuation">:</span> wait/io/file/sql/map
timed<span class="token punctuation">:</span> YES
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span 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>
enabled_instruments<span class="token punctuation">:</span> wait/io/file/sql/binlog
timed<span class="token punctuation">:</span> YES
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span 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>
enabled_instruments<span class="token punctuation">:</span> wait/io/file/sql/binlog_cache
timed<span class="token punctuation">:</span> YES
...</span></code></pre>
</div>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/intersect.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="intersect">
</a>
15.2.8 INTERSECT Clause
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045182031952">
</a>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25071348"><div class="copy-help left">Press ⌘+C to copy</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">query_expression_body</em> <span class="token keyword">INTERSECT</span> <span class="token punctuation">[</span><span class="token keyword">ALL</span> <span class="token operator">|</span> <span class="token keyword">DISTINCT</span><span class="token punctuation">]</span> <em class="replaceable">query_expression_body</em>
<span class="token punctuation">[</span><span class="token keyword">INTERSECT</span> <span class="token punctuation">[</span><span class="token keyword">ALL</span> <span class="token operator">|</span> <span class="token keyword">DISTINCT</span><span class="token punctuation">]</span> <em class="replaceable">query_expression_body</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">query_expression_body</em>:
<em>See Section <span class="token number">15.2</span><span class="token punctuation">.</span><span class="token number">14</span><span class="token punctuation">,</span> “<span class="token keyword">Set</span> Operations <span class="token keyword">with</span> <span class="token keyword">UNION</span><span class="token punctuation">,</span> <span class="token keyword">INTERSECT</span><span class="token punctuation">,</span> <span class="token operator">and</span> <span class="token keyword">EXCEPT</span>”</em></code></pre>
</div>
<p>
<code class="literal">
INTERSECT
</code>
limits the result from multiple query
blocks to those rows which are common to all. Example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa95283319"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">TABLE</span> a<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> m <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>
<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> 2 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span></span>
<span class="token output"><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>
<span class="token output">3 rows in set (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">TABLE</span> b<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> m <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>
<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> 1 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span></span>
<span class="token output"><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>
<span class="token output">3 rows in set (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">TABLE</span> c<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> m <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>
<span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 3 <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></span>
<span class="token output"><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>
<span class="token output">3 rows in set (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">TABLE</span> a <span class="token keyword">INTERSECT</span> <span class="token keyword">TABLE</span> b<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> m <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>
<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> 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>
<span class="token output">2 rows in set (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">TABLE</span> a <span class="token keyword">INTERSECT</span> <span class="token keyword">TABLE</span> c<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> m <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>
<span class="token output"><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>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
</div>
<p>
As with
<a class="link" href="union.html" title="15.2.18 UNION Clause">
<code class="literal">
UNION
</code>
</a>
and
<a class="link" href="except.html" title="15.2.4 EXCEPT Clause">
<code class="literal">
EXCEPT
</code>
</a>
, if neither
<code class="literal">
DISTINCT
</code>
nor
<code class="literal">
ALL
</code>
is
specified, the default is
<code class="literal">
DISTINCT
</code>
.
</p>
<p>
<code class="literal">
DISTINCT
</code>
can remove duplicates from either side
of the intersection, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa1594278"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">TABLE</span> c <span class="token keyword">INTERSECT</span> <span class="token keyword">DISTINCT</span> <span class="token keyword">TABLE</span> c<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> m <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>
<span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 3 <span class="token punctuation">|</span></span>
<span class="token output"><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>
<span class="token output">2 rows in set (0.00 sec)</span>
<span class="token prompt">mysql></span> <span class="token keyword">TABLE</span> c <span class="token keyword">INTERSECT</span> <span class="token keyword">ALL</span> <span class="token keyword">TABLE</span> c<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> m <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>
<span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> 3 <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></span>
<span class="token output"><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>
<span class="token output">3 rows in set (0.00 sec)</span></code></pre>
</div>
<p>
(
<code class="literal">
TABLE c INTERSECT TABLE c
</code>
is the equivalent of
the first of the two statements just shown.)
</p>
<p>
As with
<code class="literal">
UNION
</code>
, the operands must have the same
number of columns. Result set column types are also determined as
for
<code class="literal">
UNION
</code>
.
</p>
<p>
<code class="literal">
INTERSECT
</code>
has greater precedence than and is
evaluated before
<code class="literal">
UNION
</code>
and
<code class="literal">
EXCEPT
</code>
, so that the two statements shown here
are equivalent:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-simple"><div class="docs-select-all right" id="sa66069763"><div class="copy-help left">Press ⌘+C to 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">TABLE r EXCEPT TABLE s INTERSECT TABLE t<span class="token punctuation">;</span>
TABLE r EXCEPT <span class="token punctuation">(</span>TABLE s INTERSECT TABLE t<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
For
<code class="literal">
INTERSECT ALL
</code>
, the maximum supported number
of duplicates of any unique row in the left hand table is
<code class="literal">
4294967295
</code>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-programs-ndb-secretsfile-reader.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="mysql-cluster-programs-ndb-secretsfile-reader">
</a>
25.5.24 ndb_secretsfile_reader — Obtain Key Information from an Encrypted NDB
Data File
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045098103632">
</a>
<p>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html" title="25.5.24 ndb_secretsfile_reader — Obtain Key Information from an Encrypted NDB Data File">
<span class="command">
<strong>
ndb_secretsfile_reader
</strong>
</span>
</a>
gets the encryption
key from an
<code class="literal">
NDB
</code>
encryption secrets file,
given the password.
</p>
<h4>
<a name="idm46045098100048">
</a>
Usage
</h4>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa83093847"><div class="copy-help left">Press ⌘+C to 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">ndb_secretsfile_reader <em class="replaceable">options</em> <em class="replaceable">file</em></code></pre>
</div>
<p>
The
<em class="replaceable">
<code>
options
</code>
</em>
must include one of
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_filesystem-password">
<code class="option">
--filesystem-password
</code>
</a>
or
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_filesystem-password-from-stdin">
<code class="option">
--filesystem-password-from-stdin
</code>
</a>
,
and the encryption password must be supplied, as shown here:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa44922636"><div class="copy-help left">Press ⌘+C to 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">> ndb_secretsfile_reader <span class="token constant">--filesystem-password</span><span class="token attr-value"><span class="token punctuation">=</span>54kl14</span> ndb_5_fs/D1/NDBCNTR/S0<span class="token punctuation">.</span>sysfile
ndb_secretsfile_reader<span class="token punctuation">:</span> <span class="token punctuation">[</span>Warning<span class="token punctuation">]</span> Using a password on the command line interface can be insecure<span class="token punctuation">.</span>
cac256e18b2ddf6b5ef82d99a72f18e864b78453cc7fa40bfaf0c40b91122d18</code></pre>
</div>
<p>
These and other options that can be used with
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html" title="25.5.24 ndb_secretsfile_reader — Obtain Key Information from an Encrypted NDB Data File">
<span class="command">
<strong>
ndb_secretsfile_reader
</strong>
</span>
</a>
are shown in the
following table. Additional descriptions follow the table.
</p>
<p>
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_defaults-extra-file">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_defaults-extra-file">
<code class="option">
--defaults-extra-file
</code>
</a>
</p>
<a class="indexterm" name="idm46045098087520">
</a>
<a class="indexterm" name="idm46045098086016">
</a>
<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=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>
<p>
Read given file after global files are read.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_defaults-file">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_defaults-file">
<code class="option">
--defaults-file
</code>
</a>
</p>
<a class="indexterm" name="idm46045098071648">
</a>
<a class="indexterm" name="idm46045098070160">
</a>
<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=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>
<p>
Read default options from given file only.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_defaults-group-suffix">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_defaults-group-suffix">
<code class="option">
--defaults-group-suffix
</code>
</a>
</p>
<a class="indexterm" name="idm46045098055888">
</a>
<a class="indexterm" name="idm46045098054384">
</a>
<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=string
</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>
<p>
Also read groups with concat(group, suffix).
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_filesystem-password">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_filesystem-password">
<code class="option">
--filesystem-password
</code>
</a>
</p>
<a class="indexterm" name="idm46045098040128">
</a>
<a class="indexterm" name="idm46045098038624">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for filesystem-password">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--filesystem-password=password
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Pass the filesystem encryption and decryption password to
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html" title="25.5.24 ndb_secretsfile_reader — Obtain Key Information from an Encrypted NDB Data File">
<span class="command">
<strong>
ndb_secretsfile_reader
</strong>
</span>
</a>
using
<code class="literal">
stdin
</code>
,
<code class="literal">
tty
</code>
, or the
<code class="filename">
my.cnf
</code>
file.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_filesystem-password-from-stdin">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_filesystem-password-from-stdin">
<code class="option">
--filesystem-password-from-stdin
</code>
</a>
</p>
<a class="indexterm" name="idm46045098025424">
</a>
<a class="indexterm" name="idm46045098023920">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for filesystem-password-from-stdin">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--filesystem-password-from-stdin={TRUE|FALSE}
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Pass the filesystem encryption and decryption password to
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html" title="25.5.24 ndb_secretsfile_reader — Obtain Key Information from an Encrypted NDB Data File">
<span class="command">
<strong>
ndb_secretsfile_reader
</strong>
</span>
</a>
from
<code class="literal">
stdin
</code>
(only).
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_help">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_help">
<code class="option">
--help
</code>
</a>
</p>
<a class="indexterm" name="idm46045098012064">
</a>
<a class="indexterm" name="idm46045098010576">
</a>
<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>
<p>
Display help text and exit.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_login-path">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_login-path">
<code class="option">
--login-path
</code>
</a>
</p>
<a class="indexterm" name="idm46045098000752">
</a>
<a class="indexterm" name="idm46045097999264">
</a>
<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=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>
<p>
Read given path from login file.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_no-login-paths">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_no-login-paths">
<code class="option">
--no-login-paths
</code>
</a>
</p>
<a class="indexterm" name="idm46045097985072">
</a>
<a class="indexterm" name="idm46045097983584">
</a>
<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>
<p>
Skips reading options from the login path file.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_no-defaults">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_no-defaults">
<code class="option">
--no-defaults
</code>
</a>
</p>
<a class="indexterm" name="idm46045097973744">
</a>
<a class="indexterm" name="idm46045097972256">
</a>
<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>
<p>
Do not read default options from any option file other than
login file.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_print-defaults">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_print-defaults">
<code class="option">
--print-defaults
</code>
</a>
</p>
<a class="indexterm" name="idm46045097962368">
</a>
<a class="indexterm" name="idm46045097960880">
</a>
<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>
<p>
Print program argument list and exit.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_usage">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_usage">
<code class="option">
--usage
</code>
</a>
</p>
<a class="indexterm" name="idm46045097951120">
</a>
<a class="indexterm" name="idm46045097949632">
</a>
<div class="informaltable">
<table frame="box" rules="all" summary="Properties for usage">
<colgroup>
<col style="width: 30%"/>
<col style="width: 70%"/>
</colgroup>
<tbody>
<tr>
<th>
Command-Line Format
</th>
<td>
<code class="literal">
--usage
</code>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Display help text and exit; same as --help.
</p>
</li>
<li class="listitem">
<p>
<a name="option_ndb_secretsfile_reader_version">
</a>
<a class="link" href="mysql-cluster-programs-ndb-secretsfile-reader.html#option_ndb_secretsfile_reader_version">
<code class="option">
--version
</code>
</a>
</p>
<a class="indexterm" name="idm46045097939936">
</a>
<a class="indexterm" name="idm46045097938448">
</a>
<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>
<p>
Display version information and exit.
</p>
</li>
</ul>
</div>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/timestamp-initialization.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="timestamp-initialization">
</a>
13.2.5 Automatic Initialization and Updating for TIMESTAMP and DATETIME
</h3>
</div>
</div>
</div>
<a class="indexterm" name="idm46045213469520">
</a>
<p>
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
and
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
columns can be
automatically initialized and updated to the current date and
time (that is, the current timestamp).
</p>
<p>
For any
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
column in a table, you
can assign the current timestamp as the default value, the
auto-update value, or both:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
An auto-initialized column is set to the current timestamp
for inserted rows that specify no value for the column.
</p>
</li>
<li class="listitem">
<p>
An auto-updated column is automatically updated to the
current timestamp when the value of any other column in the
row is changed from its current value. An auto-updated
column remains unchanged if all other columns are set to
their current values. To prevent an auto-updated column from
updating when other columns change, explicitly set it to its
current value. To update an auto-updated column even when
other columns do not change, explicitly set it to the value
it should have (for example, set it to
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
).
</p>
</li>
</ul>
</div>
<p>
In addition, if the
<a class="link" href="server-system-variables.html#sysvar_explicit_defaults_for_timestamp">
<code class="literal">
explicit_defaults_for_timestamp
</code>
</a>
system variable is disabled, you can initialize or update any
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
(but not
<code class="literal">
DATETIME
</code>
) column to the current date and time
by assigning it a
<code class="literal">
NULL
</code>
value, unless it has
been defined with the
<code class="literal">
NULL
</code>
attribute to
permit
<code class="literal">
NULL
</code>
values.
</p>
<p>
To specify automatic properties, use the
<code class="literal">
DEFAULT
CURRENT_TIMESTAMP
</code>
and
<code class="literal">
ON UPDATE
CURRENT_TIMESTAMP
</code>
clauses in column definitions. The
order of the clauses does not matter. If both are present in a
column definition, either can occur first. Any of the synonyms
for
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
have the
same meaning as
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
. These are
<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_now">
<code class="literal">
NOW()
</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_localtime">
<code class="literal">
LOCALTIME()
</code>
</a>
,
<a class="link" href="date-and-time-functions.html#function_localtimestamp">
<code class="literal">
LOCALTIMESTAMP
</code>
</a>
, and
<a class="link" href="date-and-time-functions.html#function_localtimestamp">
<code class="literal">
LOCALTIMESTAMP()
</code>
</a>
.
</p>
<p>
Use of
<code class="literal">
DEFAULT CURRENT_TIMESTAMP
</code>
and
<code class="literal">
ON UPDATE CURRENT_TIMESTAMP
</code>
is specific to
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
and
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
. The
<code class="literal">
DEFAULT
</code>
clause also can be used to specify a
constant (nonautomatic) default value (for example,
<code class="literal">
DEFAULT 0
</code>
or
<code class="literal">
DEFAULT '2000-01-01
00:00:00'
</code>
).
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<div class="admon-title">
Note
</div>
<p>
The following examples use
<code class="literal">
DEFAULT 0
</code>
, a
default that can produce warnings or errors depending on
whether strict SQL mode or the
<a class="link" href="sql-mode.html#sqlmode_no_zero_date">
<code class="literal">
NO_ZERO_DATE
</code>
</a>
SQL mode is
enabled. Be aware that the
<a class="link" href="sql-mode.html#sqlmode_traditional">
<code class="literal">
TRADITIONAL
</code>
</a>
SQL mode
includes strict mode and
<a class="link" href="sql-mode.html#sqlmode_no_zero_date">
<code class="literal">
NO_ZERO_DATE
</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>
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
column definitions can
specify the current timestamp for both the default and
auto-update values, for one but not the other, or for neither.
Different columns can have different combinations of automatic
properties. The following rules describe the possibilities:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
With both
<code class="literal">
DEFAULT CURRENT_TIMESTAMP
</code>
and
<code class="literal">
ON UPDATE CURRENT_TIMESTAMP
</code>
, the column
has the current timestamp for its default value and is
automatically updated to the current timestamp.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14260386"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">,</span>
dt <span class="token datatype">DATETIME</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
With a
<code class="literal">
DEFAULT
</code>
clause but no
<code class="literal">
ON
UPDATE CURRENT_TIMESTAMP
</code>
clause, the column has
the given default value and is not automatically updated to
the current timestamp.
</p>
<p>
The default depends on whether the
<code class="literal">
DEFAULT
</code>
clause specifies
<code class="literal">
CURRENT_TIMESTAMP
</code>
or a constant value.
With
<code class="literal">
CURRENT_TIMESTAMP
</code>
, the default is
the current timestamp.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68622769"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">,</span>
dt <span class="token datatype">DATETIME</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
With a constant, the default is the given value. In this
case, the column has no automatic properties at all.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17415115"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
dt <span class="token datatype">DATETIME</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
With an
<code class="literal">
ON UPDATE CURRENT_TIMESTAMP
</code>
clause and a constant
<code class="literal">
DEFAULT
</code>
clause, the
column is automatically updated to the current timestamp and
has the given constant default value.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46358967"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">,</span>
dt <span class="token datatype">DATETIME</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
<li class="listitem">
<p>
With an
<code class="literal">
ON UPDATE CURRENT_TIMESTAMP
</code>
clause but no
<code class="literal">
DEFAULT
</code>
clause, the column
is automatically updated to the current timestamp but does
not have the current timestamp for its default value.
</p>
<p>
The default in this case is type dependent.
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
has a default of 0
unless defined with the
<code class="literal">
NULL
</code>
attribute,
in which case the default is
<code class="literal">
NULL
</code>
.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa97584137"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts1 <span class="token datatype">TIMESTAMP</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">,</span> <span class="token comment" spellcheck="true">-- default 0</span>
ts2 <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token comment" spellcheck="true">-- default NULL</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
has a default of
<code class="literal">
NULL
</code>
unless defined with the
<code class="literal">
NOT
NULL
</code>
attribute, in which case the default is 0.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70115128"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
dt1 <span class="token datatype">DATETIME</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">,</span> <span class="token comment" spellcheck="true">-- default NULL</span>
dt2 <span class="token datatype">DATETIME</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token comment" spellcheck="true">-- default 0</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
</li>
</ul>
</div>
<p>
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
and
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
columns have no
automatic properties unless they are specified explicitly, with
this exception: If the
<a class="link" href="server-system-variables.html#sysvar_explicit_defaults_for_timestamp">
<code class="literal">
explicit_defaults_for_timestamp
</code>
</a>
system variable is disabled, the
<span class="emphasis">
<em>
first
</em>
</span>
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column has both
<code class="literal">
DEFAULT CURRENT_TIMESTAMP
</code>
and
<code class="literal">
ON
UPDATE CURRENT_TIMESTAMP
</code>
if neither is specified
explicitly. To suppress automatic properties for the first
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column, use one of
these strategies:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Enable the
<a class="link" href="server-system-variables.html#sysvar_explicit_defaults_for_timestamp">
<code class="literal">
explicit_defaults_for_timestamp
</code>
</a>
system variable. In this case, the
<code class="literal">
DEFAULT
CURRENT_TIMESTAMP
</code>
and
<code class="literal">
ON UPDATE
CURRENT_TIMESTAMP
</code>
clauses that specify automatic
initialization and updating are available, but are not
assigned to any
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column unless explicitly included in the column definition.
</p>
</li>
<li class="listitem">
<p>
Alternatively, if
<a class="link" href="server-system-variables.html#sysvar_explicit_defaults_for_timestamp">
<code class="literal">
explicit_defaults_for_timestamp
</code>
</a>
is disabled, do either of the following:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
<p>
Define the column with a
<code class="literal">
DEFAULT
</code>
clause that specifies a constant default value.
</p>
</li>
<li class="listitem">
<p>
Specify the
<code class="literal">
NULL
</code>
attribute. This also
causes the column to permit
<code class="literal">
NULL
</code>
values, which means that you cannot assign the current
timestamp by setting the column to
<code class="literal">
NULL
</code>
. Assigning
<code class="literal">
NULL
</code>
sets the column to
<code class="literal">
NULL
</code>
, not the current timestamp. To
assign the current timestamp, set the column to
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
or a
synonym such as
<a class="link" href="date-and-time-functions.html#function_now">
<code class="literal">
NOW()
</code>
</a>
.
</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<p>
Consider these table definitions:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33944871"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts1 <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
ts2 <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</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>
ts1 <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
ts2 <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t3 <span class="token punctuation">(</span>
ts1 <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
ts2 <span class="token datatype">TIMESTAMP</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
The tables have these properties:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
In each table definition, the first
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column has no
automatic initialization or updating.
</p>
</li>
<li class="listitem">
<p>
The tables differ in how the
<code class="literal">
ts1
</code>
column
handles
<code class="literal">
NULL
</code>
values. For
<code class="literal">
t1
</code>
,
<code class="literal">
ts1
</code>
is
<code class="literal">
NOT NULL
</code>
and assigning it a value of
<code class="literal">
NULL
</code>
sets it to the current timestamp.
For
<code class="literal">
t2
</code>
and
<code class="literal">
t3
</code>
,
<code class="literal">
ts1
</code>
permits
<code class="literal">
NULL
</code>
and
assigning it a value of
<code class="literal">
NULL
</code>
sets it to
<code class="literal">
NULL
</code>
.
</p>
</li>
<li class="listitem">
<p>
<code class="literal">
t2
</code>
and
<code class="literal">
t3
</code>
differ in
the default value for
<code class="literal">
ts1
</code>
. For
<code class="literal">
t2
</code>
,
<code class="literal">
ts1
</code>
is defined to
permit
<code class="literal">
NULL
</code>
, so the default is also
<code class="literal">
NULL
</code>
in the absence of an explicit
<code class="literal">
DEFAULT
</code>
clause. For
<code class="literal">
t3
</code>
,
<code class="literal">
ts1
</code>
permits
<code class="literal">
NULL
</code>
but has an explicit default of 0.
</p>
</li>
</ul>
</div>
<p>
If a
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
or
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
DATETIME
</code>
</a>
column definition
includes an explicit fractional seconds precision value
anywhere, the same value must be used throughout the column
definition. This is permitted:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84244707"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts <span class="token function">TIMESTAMP</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token function">CURRENT_TIMESTAMP</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token function">CURRENT_TIMESTAMP</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
This is not permitted:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa56110514"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts <span class="token function">TIMESTAMP</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span> <span class="token keyword">ON</span> <span class="token keyword">UPDATE</span> <span class="token function">CURRENT_TIMESTAMP</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 punctuation">;</span></code></pre>
</div>
<h4>
<a name="idm46045213344320">
</a>
TIMESTAMP Initialization and the NULL Attribute
</h4>
<p>
If the
<a class="link" href="server-system-variables.html#sysvar_explicit_defaults_for_timestamp">
<code class="literal">
explicit_defaults_for_timestamp
</code>
</a>
system variable is disabled,
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
columns by default are
<code class="literal">
NOT NULL
</code>
, cannot contain
<code class="literal">
NULL
</code>
values, and assigning
<code class="literal">
NULL
</code>
assigns the current timestamp. To permit
a
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column to contain
<code class="literal">
NULL
</code>
, explicitly declare it with the
<code class="literal">
NULL
</code>
attribute. In this case, the default
value also becomes
<code class="literal">
NULL
</code>
unless overridden
with a
<code class="literal">
DEFAULT
</code>
clause that specifies a
different default value.
<code class="literal">
DEFAULT NULL
</code>
can be
used to explicitly specify
<code class="literal">
NULL
</code>
as the
default value. (For a
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column not declared with the
<code class="literal">
NULL
</code>
attribute,
<code class="literal">
DEFAULT NULL
</code>
is invalid.) If a
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column permits
<code class="literal">
NULL
</code>
values, assigning
<code class="literal">
NULL
</code>
sets it to
<code class="literal">
NULL
</code>
, not
to the current timestamp.
</p>
<p>
The following table contains several
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
columns that permit
<code class="literal">
NULL
</code>
values:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa66195118"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>
ts1 <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
ts2 <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token number">0</span><span class="token punctuation">,</span>
ts3 <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
A
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column that permits
<code class="literal">
NULL
</code>
values does
<span class="emphasis">
<em>
not
</em>
</span>
take on the current timestamp at insert time except under one of
the following conditions:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Its default value is defined as
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
and no
value is specified for the column
</p>
</li>
<li class="listitem">
<p>
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
or any of
its synonyms such as
<a class="link" href="date-and-time-functions.html#function_now">
<code class="literal">
NOW()
</code>
</a>
is
explicitly inserted into the column
</p>
</li>
</ul>
</div>
<p>
In other words, a
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column defined to permit
<code class="literal">
NULL
</code>
values
auto-initializes only if its definition includes
<code class="literal">
DEFAULT CURRENT_TIMESTAMP
</code>
:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa42803089"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>ts <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CURRENT_TIMESTAMP</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
If the
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column permits
<code class="literal">
NULL
</code>
values but its definition does not
include
<code class="literal">
DEFAULT CURRENT_TIMESTAMP
</code>
, you must
explicitly insert a value corresponding to the current date and
time. Suppose that tables
<code class="literal">
t1
</code>
and
<code class="literal">
t2
</code>
have these definitions:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88277116"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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>ts <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0000-00-00 00:00:00'</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>ts <span class="token datatype">TIMESTAMP</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
</div>
<p>
To set the
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
column in
either table to the current timestamp at insert time, explicitly
assign it that value. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa50028337"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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> t2 <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token keyword">CURRENT_TIMESTAMP</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 function">NOW</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 the
<a class="link" href="server-system-variables.html#sysvar_explicit_defaults_for_timestamp">
<code class="literal">
explicit_defaults_for_timestamp
</code>
</a>
system variable is enabled,
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
columns permit
<code class="literal">
NULL
</code>
values only if declared with the
<code class="literal">
NULL
</code>
attribute. Also,
<a class="link" href="datetime.html" title="13.2.2 The DATE, DATETIME, and TIMESTAMP Types">
<code class="literal">
TIMESTAMP
</code>
</a>
columns do not permit
assigning
<code class="literal">
NULL
</code>
to assign the current
timestamp, whether declared with the
<code class="literal">
NULL
</code>
or
<code class="literal">
NOT NULL
</code>
attribute. To assign the current
timestamp, set the column to
<a class="link" href="date-and-time-functions.html#function_current-timestamp">
<code class="literal">
CURRENT_TIMESTAMP
</code>
</a>
or a synonym
such as
<a class="link" href="date-and-time-functions.html#function_now">
<code class="literal">
NOW()
</code>
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-install-linux.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="mysql-cluster-install-linux">
</a>
25.3.1 Installation of NDB Cluster on Linux
</h3>
</div>
</div>
</div>
<div class="toc">
<dl class="toc">
<dt>
<span class="section">
<a href="mysql-cluster-install-linux-binary.html">
25.3.1.1 Installing an NDB Cluster Binary Release on Linux
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-cluster-install-linux-rpm.html">
25.3.1.2 Installing NDB Cluster from RPM
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-cluster-install-debian.html">
25.3.1.3 Installing NDB Cluster Using .deb Files
</a>
</span>
</dt>
<dt>
<span class="section">
<a href="mysql-cluster-install-linux-source.html">
25.3.1.4 Building NDB Cluster from Source on Linux
</a>
</span>
</dt>
</dl>
</div>
<a class="indexterm" name="idm46045123025056">
</a>
<a class="indexterm" name="idm46045123023568">
</a>
<p>
This section covers installation methods for NDB Cluster on Linux
and other Unix-like operating systems. While the next few sections
refer to a Linux operating system, the instructions and procedures
given there should be easily adaptable to other supported
Unix-like platforms. For manual installation and setup
instructions specific to Windows systems, see
<a class="xref" href="mysql-cluster-install-windows.html" title="25.3.2 Installing NDB Cluster on Windows">
Section 25.3.2, “Installing NDB Cluster on Windows”
</a>
.
</p>
<p>
Each NDB Cluster host computer must have the correct executable
programs installed. A host 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
</strong>
</span>
</a>
).
Management nodes require 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
</strong>
</span>
</a>
); data nodes require 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
</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
</strong>
</span>
</a>
). It
is not necessary to install the MySQL Server binary on management
node hosts and data node hosts. It is recommended that you 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
</strong>
</span>
</a>
) on the
management server host.
</p>
<p>
Installation of NDB Cluster on Linux can be done using precompiled
binaries from Oracle (downloaded as a .tar.gz archive), with RPM
packages (also available from Oracle), or from source code. All
three of these installation methods are described in the section
that follow.
</p>
<p>
Regardless of the method used, it is still necessary following
installation of the NDB Cluster binaries to create configuration
files for all cluster nodes, before you can start the cluster. See
<a class="xref" href="mysql-cluster-install-configuration.html" title="25.3.3 Initial Configuration of NDB Cluster">
Section 25.3.3, “Initial Configuration of NDB Cluster”
</a>
.
</p>
</div>
<br/>
</div>
|
https://dev.mysql.com/doc/refman/8.4/en/nonpersistible-system-variables.html | <div id="docs-body">
<div class="section">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="nonpersistible-system-variables">
</a>
7.1.9.4 Nonpersistible and Persist-Restricted System Variables
</h4>
</div>
</div>
</div>
<a class="indexterm" name="idm46045263737632">
</a>
<a class="indexterm" name="idm46045263736144">
</a>
<a class="indexterm" name="idm46045263734656">
</a>
<a class="indexterm" name="idm46045263733616">
</a>
<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>
and
<a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
<code class="literal">
SET
PERSIST_ONLY
</code>
</a>
enable global system variables to be
persisted to the
<code class="filename">
mysqld-auto.cnf
</code>
option
file in the data directory (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>
).
However, not all system variables can be persisted, or can be
persisted only under certain restrictive conditions. Here are
some reasons why a system variable might be nonpersistible or
persist-restricted:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>
Session system variables cannot be persisted. Session
variables cannot be set at server startup, so there is no
reason to persist them.
</p>
</li>
<li class="listitem">
<p>
A global system variable might involve sensitive data such
that it should be settable only by a user with direct access
to the server host.
</p>
</li>
<li class="listitem">
<p>
A global system variable might be read only (that is, set
only by the server). In this case, it cannot be set by users
at all, whether at server startup or at runtime.
</p>
</li>
<li class="listitem">
<p>
A global system variable might be intended only for internal
use.
</p>
</li>
</ul>
</div>
<p>
Nonpersistible system variables cannot be persisted under any
circumstances. Persist-restricted system variables can be
persisted with
<a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
<code class="literal">
SET
PERSIST_ONLY
</code>
</a>
, but only by users for which the
following conditions are satisfied:
</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_persist_only_admin_x509_subject">
<code class="literal">
persist_only_admin_x509_subject
</code>
</a>
system variable is set to an SSL certificate X.509 Subject
value.
</p>
</li>
<li class="listitem">
<p>
The user connects to the server using an encrypted
connection and supplies an SSL certificate with the
designated Subject value.
</p>
</li>
<li class="listitem">
<p>
The user has sufficient privileges to use
<a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
<code class="literal">
SET
PERSIST_ONLY
</code>
</a>
(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>
</li>
</ul>
</div>
<p>
For example,
<a class="link" href="server-system-variables.html#sysvar_protocol_version">
<code class="literal">
protocol_version
</code>
</a>
is read only and set only by the server, so it cannot be
persisted under any circumstances. On the other hand,
<a class="link" href="server-system-variables.html#sysvar_bind_address">
<code class="literal">
bind_address
</code>
</a>
is
persist-restricted, so it can be set by users who satisfy the
preceding conditions.
</p>
<p>
The following system variables are nonpersistible. This list may
change with ongoing development.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-none"><div class="docs-select-all right" id="sa37206850"><div class="copy-help left">Press ⌘+C to 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">audit_log_current_session
audit_log_filter_id
caching_sha2_password_digest_rounds
character_set_system
core_file
have_statement_timeout
have_symlink
hostname
innodb_version
keyring_hashicorp_auth_path
keyring_hashicorp_ca_path
keyring_hashicorp_caching
keyring_hashicorp_commit_auth_path
keyring_hashicorp_commit_ca_path
keyring_hashicorp_commit_caching
keyring_hashicorp_commit_role_id
keyring_hashicorp_commit_server_url
keyring_hashicorp_commit_store_path
keyring_hashicorp_role_id
keyring_hashicorp_secret_id
keyring_hashicorp_server_url
keyring_hashicorp_store_path
large_files_support
large_page_size
license
locked_in_memory
log_bin
log_bin_basename
log_bin_index
lower_case_file_system
ndb_version
ndb_version_string
persist_only_admin_x509_subject
persisted_globals_load
protocol_version
relay_log_basename
relay_log_index
server_uuid
skip_external_locking
system_time_zone
version_comment
version_compile_machine
version_compile_os
version_compile_zlib</code></pre>
</div>
<p>
Persist-restricted system variables are those that are read only
and can be set on the command line or in an option file, other
than
<a class="link" href="server-system-variables.html#sysvar_persist_only_admin_x509_subject">
<code class="literal">
persist_only_admin_x509_subject
</code>
</a>
and
<a class="link" href="server-system-variables.html#sysvar_persisted_globals_load">
<code class="literal">
persisted_globals_load
</code>
</a>
.
This list may change with ongoing development.
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-none"><div class="docs-select-all right" id="sa64829189"><div class="copy-help left">Press ⌘+C to 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">audit_log_file
audit_log_format
auto_generate_certs
basedir
bind_address
caching_sha2_password_auto_generate_rsa_keys
caching_sha2_password_private_key_path
caching_sha2_password_public_key_path
character_sets_dir
datadir
ft_stopword_file
init_file
innodb_buffer_pool_load_at_startup
innodb_data_file_path
innodb_data_home_dir
innodb_dedicated_server
innodb_directories
innodb_force_load_corrupted
innodb_log_group_home_dir
innodb_page_size
innodb_read_only
innodb_temp_data_file_path
innodb_temp_tablespaces_dir
innodb_undo_directory
innodb_undo_tablespaces
lc_messages_dir
log_error
mecab_rc_file
named_pipe
pid_file
plugin_dir
port
relay_log
replica_load_tmpdir
secure_file_priv
sha256_password_auto_generate_rsa_keys
sha256_password_private_key_path
sha256_password_public_key_path
shared_memory
shared_memory_base_name
skip_networking
slave_load_tmpdir
socket
ssl_ca
ssl_capath
ssl_cert
ssl_crl
ssl_crlpath
ssl_key
tmpdir
version_tokens_session_number</code></pre>
</div>
<p>
To configure the server to enable persisting persist-restricted
system variables, use this procedure:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>
Ensure that MySQL is configured to support encrypted
connections. See
<a class="xref" href="using-encrypted-connections.html" title="8.3.1 Configuring MySQL to Use Encrypted Connections">
Section 8.3.1, “Configuring MySQL to Use Encrypted Connections”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Designate an SSL certificate X.509 Subject value that
signifies the ability to persist persist-restricted system
variables, and generate a certificate that has that Subject.
See
<a class="xref" href="creating-ssl-rsa-files.html" title="8.3.3 Creating SSL and RSA Certificates and Keys">
Section 8.3.3, “Creating SSL and RSA Certificates and Keys”
</a>
.
</p>
</li>
<li class="listitem">
<p>
Start the server with
<a class="link" href="server-system-variables.html#sysvar_persist_only_admin_x509_subject">
<code class="literal">
persist_only_admin_x509_subject
</code>
</a>
set to the designated Subject value. For example, put these
lines in your 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="sa11948215"><div class="copy-help left">Press ⌘+C to 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">persist_only_admin_x509_subject</span><span class="token attr-value"><span class="token punctuation">=</span>"<em class="replaceable">subject-value</em>"</span></code></pre>
</div>
<p>
The format of the Subject value is the same as used for
<a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
<code class="literal">
CREATE USER ...
REQUIRE SUBJECT
</code>
</a>
. 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>
.
</p>
<p>
You must perform this step directly on the MySQL server host
because
<a class="link" href="server-system-variables.html#sysvar_persist_only_admin_x509_subject">
<code class="literal">
persist_only_admin_x509_subject
</code>
</a>
itself cannot be persisted at runtime.
</p>
</li>
<li class="listitem">
<p>
Restart the server.
</p>
</li>
<li class="listitem">
<p>
Distribute the SSL certificate that has the designated
Subject value to users who are to be permitted to persist
persist-restricted system variables.
</p>
</li>
</ol>
</div>
<p>
Suppose that
<code class="filename">
myclient-cert.pem
</code>
is the SSL
certificate to be used by clients who can persist
persist-restricted system variables. Display the certificate
contents using the
<span class="command">
<strong>
openssl
</strong>
</span>
command:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa53201499"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">openssl</span> x509 <span class="token property">-text</span> <span class="token property">-in</span> myclient-cert<span class="token punctuation">.</span>pem
Certificate<span class="token punctuation">:</span>
Data<span class="token punctuation">:</span>
Version<span class="token punctuation">:</span> 3 <span class="token punctuation">(</span>0x2<span class="token punctuation">)</span>
Serial Number<span class="token punctuation">:</span> 2 <span class="token punctuation">(</span>0x2<span class="token punctuation">)</span>
Signature Algorithm<span class="token punctuation">:</span> md5WithRSAEncryption
Issuer<span class="token punctuation">:</span> C<span class="token attr-value"><span class="token punctuation">=</span>US,</span> ST<span class="token attr-value"><span class="token punctuation">=</span>IL,</span> L<span class="token attr-value"><span class="token punctuation">=</span>Chicago,</span> O<span class="token attr-value"><span class="token punctuation">=</span>MyOrg,</span> OU<span class="token attr-value"><span class="token punctuation">=</span>CA,</span> CN<span class="token attr-value"><span class="token punctuation">=</span>MyCN</span>
Validity
Not Before<span class="token punctuation">:</span> Oct 18 17<span class="token punctuation">:</span>03<span class="token punctuation">:</span>03 2018 GMT
Not After <span class="token punctuation">:</span> Oct 15 17<span class="token punctuation">:</span>03<span class="token punctuation">:</span>03 2028 GMT
Subject<span class="token punctuation">:</span> C<span class="token attr-value"><span class="token punctuation">=</span>US,</span> ST<span class="token attr-value"><span class="token punctuation">=</span>IL,</span> L<span class="token attr-value"><span class="token punctuation">=</span>Chicago,</span> O<span class="token attr-value"><span class="token punctuation">=</span>MyOrg,</span> OU<span class="token attr-value"><span class="token punctuation">=</span>client,</span> CN<span class="token attr-value"><span class="token punctuation">=</span>MyCN</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
</div>
<p>
The
<span class="command">
<strong>
openssl
</strong>
</span>
output shows that the certificate
Subject value is:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa89486080"><div class="copy-help left">Press ⌘+C to 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">C=US, ST=IL, L=Chicago, O=MyOrg, OU=client, CN=MyCN</code></pre>
</div>
<p>
To specify the Subject for MySQL, use this format:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa95332428"><div class="copy-help left">Press ⌘+C to 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">/C=US/ST=IL/L=Chicago/O=MyOrg/OU=client/CN=MyCN</code></pre>
</div>
<p>
Configure the server
<code class="filename">
my.cnf
</code>
file with the
Subject value:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-ini"><div class="docs-select-all right" id="sa31022196"><div class="copy-help left">Press ⌘+C to 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">persist_only_admin_x509_subject</span><span class="token attr-value"><span class="token punctuation">=</span>"/C=US/ST=IL/L=Chicago/O=MyOrg/OU=client/CN=MyCN"</span></code></pre>
</div>
<p>
Restart the server so that the new configuration takes effect.
</p>
<p>
Distribute the SSL certificate (and any other associated SSL
files) to the appropriate users. Such a user then connects to
the server with the certificate and any other SSL options
required to establish an encrypted connection.
</p>
<p>
To use X.509, 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. For example:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa32908749"><div class="copy-help left">Press ⌘+C to 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">$> </span><span class="token command">mysql</span> <span class="token constant">--ssl-key</span><span class="token attr-value"><span class="token punctuation">=</span>myclient-key.pem</span> <span class="token constant">--ssl-cert</span><span class="token attr-value"><span class="token punctuation">=</span>myclient-cert.pem</span> <span class="token constant">--ssl-ca</span><span class="token attr-value"><span class="token punctuation">=</span>mycacert.pem</span></code></pre>
</div>
<p>
Assuming that the user has sufficient privileges to use
<a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
<code class="literal">
SET
PERSIST_ONLY
</code>
</a>
, persist-restricted system variables can
be persisted like this:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa92871296"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token keyword">PERSIST_ONLY</span> <span class="token keyword">socket</span> <span class="token operator">=</span> <span class="token string">'/tmp/mysql.sock'</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span></code></pre>
</div>
<p>
If the server is not configured to enable persisting
persist-restricted system variables, or the user does not
satisfy the required conditions for that capability, an error
occurs:
</p>
<div class="copytoclipboard-wrapper">
<pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34162008"><div class="copy-help left">Press ⌘+C to copy</div> <div class="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></span> <span class="token keyword">SET</span> <span class="token keyword">PERSIST_ONLY</span> <span class="token keyword">socket</span> <span class="token operator">=</span> <span class="token string">'/tmp/mysql.sock'</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1238 (HY000)<span class="token punctuation">:</span> Variable 'socket' is a non persistent read only variable</span></code></pre>
</div>
</div>
<br/>
</div>
|