MySQL中help命令怎么用

发布时间:2021-11-02 17:01:05 作者:小新
来源:亿速云 阅读:311

小编给大家分享一下MySQL中help命令怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

01

help 语句信息从哪里取的

MySQL Server提供4张表用于保存服务端的帮助信息(使用help语法查看的帮助信息),这些表位于mysql 系统字典库下。help 语句就是从这些表中获取数据并返回给客户端,如下:

02

help 语句信息何时产生的

这些表在数据库初始化时通过加载share/fill_help_tables.sql文件创建,如果是在Unix上使用二进制或源代码发行版安装MySQL,则在初始化数据目录时会直接导入该文件对帮助表内容进行初始化。对于在Linux上的RPM分发版或Windows上的二进制发行版,帮助表的内容初始化是作为MySQL安装过程的一部分执行。

03

help 帮助信息存储表详解

help 语法支持3种模式的匹配查询:查看所有主题顶层类别或子类别、查看帮助主题下的关键字、使用给定主题下的唯一关键字查看帮助信息,这些信息分表保存在 help_category、help_topic、help_keyword表,help_relation表存放help_topic与help_keyword表中信息的映射信息。下面将针对这几张表的基础知识进行简单的科普。

(1)help_category

该表提供查询帮助主题的类别信息,每一个类别分别对应着N个帮助主题名或者主题子类别名,通过查询表中的信息我们也可以看出来,如下:

root@localhost : mysql 01:10:59> select * from help_category;
+------------------+-----------------------------------------------+--------------------+-----+
| help_category_id | name                                          | parent_category_id | url |
+------------------+-----------------------------------------------+--------------------+-----+
|                1 | Geographic                                    |                  0 |     |
|                2 | Polygon properties                            |                 35 |     |
......
|               39 | Functions                                     |                 36 |     |
|               40 | Data Definition                               |                 36 |     |
+------------------+-----------------------------------------------+--------------------+-----+
40 rows in set (0.00 sec)

表字段含义

(2)help_keyword

该表提供查询与帮助主题相关的关键字字符串信息,如下:

root@localhost : mysql 01:12:07> select * from help_keyword limit 5;
+-----------------+---------+
| help_keyword_id | name    |
+-----------------+---------+
|             681 | (JSON   |
|             486 | ->      |
|             205 | ->>     |
|             669 | <>      |
|             521 | ACCOUNT |
+-----------------+---------+
5 rows in set (0.00 sec)

表字段含义

(3)help_relation

该表提供查询帮助关键字信息和主题详细信息之间的映射,用于关联查询help_keyword与help_topic表,如下:

root@localhost : mysql 01:13:09> select * from help_relation limit 5;
+---------------+-----------------+
| help_topic_id | help_keyword_id |
+---------------+-----------------+
|             0 |               0 |
|           535 |               0 |
|           294 |               1 |
|           277 |               2 |
|             2 |               3 |
+---------------+-----------------+
5 rows in set (0.00 sec)

表字段含义

(4)help_topic

该表提供查询帮助主题给定关键字的详细内容(详细帮助信息),如下:

root@localhost : mysql 01:13:31> select * from help_topic limit 1\G;
*************************** 1. row ***************************
help_topic_id: 0
        name: JOIN
help_category_id: 28
 description: MySQL supports the following JOIN syntaxes for the table_references
part of SELECT statements and multiple-table DELETE and UPDATE
statements:
table_references:
escaped_table_reference [, escaped_table_reference] ...
escaped_table_reference:
table_reference
| { OJ table_reference }
......
         url: http://dev.mysql.com/doc/refman/5.7/en/join.html
1 row in set (0.00 sec)

表字段含义

04

help 语句用法示例

前面我们提到过,help 语法支持3种模式的匹配查询。那么,回到文章开头我们抛出的问题,记不清某个语句的具体拼写了,只能模糊的记得几个字母,或者说很清楚知道想要查什么帮助信息,但是却不知道用什么关键字来查询帮助信息(例如:想要查看解析relaylog的SQL语句)。这个时候怎么办呢?

(1)我只记得某几个字母怎么办

MySQL 提供的帮助信息实际上可以直接给定一个主题关键字进行查询,不需要指定主题名称,如果你记录某个SQL子句关键字的其中的几个字母,那么可以使用这些字母多尝试几次,如下:

root@localhost : performance_schema 10:43:40> help relay  # 尝试第一次
Nothing found
Please try to run 'help contents' for a list of all accessible topics
root@localhost : performance_schema 10:44:00> help relay logs  # 尝试第二次
Nothing found
Please try to run 'help contents' for a list of all accessible topics
root@localhost : performance_schema 10:44:06> help relaylogs  # 尝试第三次
Nothing found
Please try to run 'help contents' for a list of all accessible topics
root@localhost : performance_schema 10:44:09> help relaylog  # 尝试第四次,oy,成功了
Name: 'SHOW RELAYLOG EVENTS'
Description:
Syntax:
SHOW RELAYLOG EVENTS
[IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]  # 原来是这样用的
Shows the events in the relay log of a replication slave. If you do not
specify 'log_name', the first relay log is displayed. This statement
has no effect on the master.
URL: http://dev.mysql.com/doc/refman/5.7/en/show-relaylog-events.html

PS:这里实际上就相当于那help 语句给定的关键字去匹配help_keyword表的name字段,如果有记录返回,则使用help_category、help_keyword、help_relation、help_topic四表做复杂的关联查询,右联结help_topic表中的name字段,如果返回唯一记录就返回帮助信息,如果返回多行,则返回一个关键字列表,使用这些具体的关键字可查询到具体的帮助信息,例如:

root@localhost : performance_schema 11:05:06> help where
.....
where <item> is one of the following
topics:  # 使用where作为关键字返回了一个关键字列表,表示where还会与这三个关键字组合使用,where的详细用法从列表中随便挑选一个关键字即可看到
DELETE
HANDLER
UPDATE
root@localhost : performance_schema 11:09:05> help delete
Name: 'DELETE'
Description:
Syntax:
DELETE is a DML statement that removes rows from a table.
Single-Table Syntax
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
[PARTITION (partition_name,...)]
[WHERE where_condition]  # where关键字的用法在这里
[ORDER BY ...]
[LIMIT row_count]
......
(2)我啥都不记得怎么办

如果你啥都不记得,那就只能使用最笨的方法,地毯式查找

首先,我们就随便敲几个字母给help语句好了,例如:help xxx

root@localhost : performance_schema 10:09:49> help xxx;
Nothing found  # 这句告诉你帮助信息没找到
# 不要紧,下面这句告诉你,用help contents语句来列出所有的可能的帮助主题信息
Please try to run 'help contents' for a list of all accessible topics

然后,查看所有的主题类别

root@localhost : performance_schema 10:31:47> help contents
You asked for help about help category: "Contents"
For more information, type 'help <item>', where <item> is one of the following
categories:
Account Management
Administration  # 通过主题或主题类别名称,大致判定一下,查看relaylog事件内容的语句应该是属于管理语句
Compound Statements
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Help Metadata
Language Structure
Plugins
Procedures
Storage Engines
Table Maintenance
Transactions
User-Defined Functions
Utility

使用help Administration 查看该帮助主题下的所有关键字

root@localhost : performance_schema 10:37:27> help Administration
......
SHOW PROCEDURE CODE
SHOW PROCEDURE STATUS
SHOW PROCESSLIST
SHOW PROFILE
SHOW PROFILES
SHOW RELAYLOG EVENTS  # 找到了,在这里
......

使用SHOW RELAYLOG EVENTS语句来查看具体的帮助信息

root@localhost : performance_schema 10:41:53> help SHOW RELAYLOG EVENTS
Name: 'SHOW RELAYLOG EVENTS'
Description:
Syntax:
SHOW RELAYLOG EVENTS
[IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]  # 原来是这样用的
Shows the events in the relay log of a replication slave. If you do not
specify 'log_name', the first relay log is displayed. This statement
has no effect on the master.
URL: http://dev.mysql.com/doc/refman/5.7/en/show-relaylog-events.html

OK,现在相信你已经比较清晰地了解了MySQL 帮助系统的组成以及help 到底能给我们提供一些什么帮助信息了,下面给大家再补充点小知识:

05

帮助信息表相关的注意事项

对于参与复制的数据库实例,帮助表更新有一些注意事项。帮助表默认情况下会写入到binlog中(因为这些帮助表是跟版本匹配的,升级一个实例的版本,其他实例也有同步更新的必要),所以,你需要考虑是否需要在升级主库帮助表的时候同时把这些更新通过主库binlog同步更新到从库中。

以上是“MySQL中help命令怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. MySQL内置help解析
  2. 怎么在python用help函数

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql help

上一篇:windows 2003组策略打不开的故障该怎么解决

下一篇:Spring中什么是统一异常处理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》