mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-17 20:51:21 +08:00
doc: update docs/mysql.md (#941)
Co-authored-by: null <shanhai1204@gmail.com> 0c618e1c01
This commit is contained in:
234
CONTRIBUTORS.svg
234
CONTRIBUTORS.svg
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 11 MiB After Width: | Height: | Size: 11 MiB |
@ -39,7 +39,7 @@
|
|||||||
<p>本备忘单旨在快速理解 <a href="https://mysql.com">MySQL</a> 所涉及的主要概念,提供了最常用的SQL语句,供您参考。</p>
|
<p>本备忘单旨在快速理解 <a href="https://mysql.com">MySQL</a> 所涉及的主要概念,提供了最常用的SQL语句,供您参考。</p>
|
||||||
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
|
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
|
||||||
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
|
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
|
||||||
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#介绍">介绍</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#登录mysql">登录MySQL</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#常用的">常用的</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#数据库-database">数据库 Database</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#表-table">表 Table</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#proccess">Proccess</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#查看-mysql-信息">查看 MySQL 信息</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#退出mysql会话">退出MySQL会话</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#备份">备份</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#mysql-示例">MySQL 示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理表格">管理表格</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从表中查询数据">从表中查询数据</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从多个表查询">从多个表查询</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用-sql-约束">使用 SQL 约束</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#修改数据">修改数据</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理视图">管理视图</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理触发器">管理触发器</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#when">WHEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#event">EVENT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#trigger_type">TRIGGER_TYPE</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理索引">管理索引</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#mysql-数据类型">MySQL 数据类型</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#strings">Strings</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#date--time">Date & time</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#numeric">Numeric</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#函数">函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#聚合函数">聚合函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数学函数">数学函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#日期和时间函数">日期和时间函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#字符串函数">字符串函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#高级函数">高级函数</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
|
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#介绍">介绍</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#登录mysql">登录MySQL</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#常用的">常用的</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#数据库-database">数据库 Database</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#表-table">表 Table</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#proccess">Proccess</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#查看-mysql-信息">查看 MySQL 信息</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#退出mysql会话">退出MySQL会话</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#备份">备份</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#错误处理-error-handling">错误处理 Error Handling</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#mysql-示例">MySQL 示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理表格">管理表格</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从表中查询数据">从表中查询数据</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从多个表查询">从多个表查询</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用-sql-约束">使用 SQL 约束</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#修改数据">修改数据</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理视图">管理视图</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理触发器">管理触发器</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#when">WHEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#event">EVENT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#trigger_type">TRIGGER_TYPE</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理索引">管理索引</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#mysql-数据类型">MySQL 数据类型</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#strings">Strings</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#date--time">Date & time</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#numeric">Numeric</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#函数">函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#聚合函数">聚合函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数学函数">数学函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#日期和时间函数">日期和时间函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#字符串函数">字符串函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#高级函数">高级函数</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
|
||||||
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="介绍"><a aria-hidden="true" tabindex="-1" href="#介绍"><span class="icon icon-link"></span></a>介绍</h3><div class="wrap-body">
|
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="介绍"><a aria-hidden="true" tabindex="-1" href="#介绍"><span class="icon icon-link"></span></a>介绍</h3><div class="wrap-body">
|
||||||
<!--rehype:wrap-class=row-span-3-->
|
<!--rehype:wrap-class=row-span-3-->
|
||||||
<p>MySQL 为关系型数据库(Relational Database Management System),一个关系型数据库由一个或数个表格组成,如下所示的一个表格</p>
|
<p>MySQL 为关系型数据库(Relational Database Management System),一个关系型数据库由一个或数个表格组成,如下所示的一个表格</p>
|
||||||
@ -180,6 +180,41 @@
|
|||||||
<p>恢复备份</p>
|
<p>恢复备份</p>
|
||||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">mysql <span class="token parameter variable">-u</span> user <span class="token parameter variable">-p</span> db_name <span class="token operator"><</span> db.sql
|
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">mysql <span class="token parameter variable">-u</span> user <span class="token parameter variable">-p</span> db_name <span class="token operator"><</span> db.sql
|
||||||
</span></code></pre>
|
</span></code></pre>
|
||||||
|
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="错误处理-error-handling"><a aria-hidden="true" tabindex="-1" href="#错误处理-error-handling"><span class="icon icon-link"></span></a>错误处理 Error Handling</h3><div class="wrap-body">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<table><thead><tr><th align="left">语句</th><th align="left">描述</th></tr></thead><tbody><tr><td align="left"><code>SHOW ERRORS;</code></td><td align="left">显示最近的错误信息</td></tr><tr><td align="left"><code>SHOW WARNINGS;</code></td><td align="left">显示最近的警告信息</td></tr><tr><td align="left"><code>SHOW COUNT(*) ERRORS;</code></td><td align="left">返回最近语句的错误数量</td></tr><tr><td align="left"><code>SHOW COUNT(*) WARNINGS;</code></td><td align="left">返回最近语句的警告数量</td></tr><tr><td align="left"><code>EXPLAIN</code></td><td align="left">分析 SQL 查询的执行计划,排查问题</td></tr><tr><td align="left"><code>SHOW ENGINE INNODB STATUS;</code></td><td align="left">显示 InnoDB 引擎状态,包括死锁等错误信息</td></tr></tbody></table>
|
||||||
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="mysql-示例"><a aria-hidden="true" tabindex="-1" href="#mysql-示例"><span class="icon icon-link"></span></a>MySQL 示例</h2><div class="wrap-body">
|
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="mysql-示例"><a aria-hidden="true" tabindex="-1" href="#mysql-示例"><span class="icon icon-link"></span></a>MySQL 示例</h2><div class="wrap-body">
|
||||||
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="管理表格"><a aria-hidden="true" tabindex="-1" href="#管理表格"><span class="icon icon-link"></span></a>管理表格</h3><div class="wrap-body">
|
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="管理表格"><a aria-hidden="true" tabindex="-1" href="#管理表格"><span class="icon icon-link"></span></a>管理表格</h3><div class="wrap-body">
|
||||||
<p>创建一个包含三列的新表</p>
|
<p>创建一个包含三列的新表</p>
|
||||||
@ -656,7 +691,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<table><thead><tr><th align="left">函数</th><th align="left">解释</th></tr></thead><tbody><tr><td align="left"><code>SUM()</code></td><td align="left">计算一列值的总和</td></tr><tr><td align="left"><code>AVG()</code></td><td align="left">计算一列值的平均值</td></tr><tr><td align="left"><code>COUNT()</code></td><td align="left">计算行数,可选择性地忽略NULL值</td></tr><tr><td align="left"><code>MAX()</code></td><td align="left">找出一列的最大值</td></tr><tr><td align="left"><code>MIN()</code></td><td align="left">找出一列的最小值</td></tr></tbody></table>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<table><thead><tr><th align="left">函数</th><th align="left">解释</th></tr></thead><tbody><tr><td align="left"><code>SUM()</code></td><td align="left">计算一列值的总和</td></tr><tr><td align="left"><code>AVG()</code></td><td align="left">计算一列值的平均值</td></tr><tr><td align="left"><code>COUNT()</code></td><td align="left">计算行数,可选择性地忽略NULL值</td></tr><tr><td align="left"><code>MAX()</code></td><td align="left">找出一列的最大值</td></tr><tr><td align="left"><code>MIN()</code></td><td align="left">找出一列的最小值</td></tr><tr><td align="left"><code>GROUP_CONCAT()</code></td><td align="left">将一组值连接成单一字符串,可指定分隔符,常用于分组。</td></tr></tbody></table>
|
||||||
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="数学函数"><a aria-hidden="true" tabindex="-1" href="#数学函数"><span class="icon icon-link"></span></a>数学函数</h3><div class="wrap-body">
|
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="数学函数"><a aria-hidden="true" tabindex="-1" href="#数学函数"><span class="icon icon-link"></span></a>数学函数</h3><div class="wrap-body">
|
||||||
<!--rehype:wrap-class=col-span-2 -->
|
<!--rehype:wrap-class=col-span-2 -->
|
||||||
|
|
||||||
|
@ -1642,7 +1642,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<!--rehype:style=padding-top:1rem;max-width: 520px;margin: 0 auto;-->
|
<!--rehype:style=padding-top:1rem;max-width: 520px;margin: 0 auto;-->
|
||||||
|
|
||||||
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 <a href="https://wangchujiang.com/#/app" target="_blank">Kenny Wang</a>. Updated on 2025/03/11 23:45:10</footer></footer><script src="data.js?v=1.8.1" defer></script><script src="js/fuse.min.js?v=1.8.1" defer></script><script src="js/main.js?v=1.8.1" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
|
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 <a href="https://wangchujiang.com/#/app" target="_blank">Kenny Wang</a>. Updated on 2025/03/13 12:09:48</footer></footer><script src="data.js?v=1.8.1" defer></script><script src="js/fuse.min.js?v=1.8.1" defer></script><script src="js/main.js?v=1.8.1" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
|
||||||
<path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
|
<path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
|
||||||
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
|
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user