Do you really use MySQL's help command|A comprehensive understanding of the mysql system library

Is MySQL help information important? not so important! is that useful? Have! It's like when you take a shower at home, suddenly someone keeps pressing the doorbell of your house, which can suppress your heart disease, hehe.

I think that fellow DBA colleagues, if you suddenly forget a certain SQL or how to spell a certain management command during the daily maintenance of the database, the first thing you think of is to use the "help xxx" statement to view the MySQL built-in help information.

But you must be able to encounter such a scenario more or less: you can't remember the specific spelling of a sentence, you can only remember a few letters vaguely, or you know clearly what help information you want to check, but you don't know What keywords are used to query the help information (for example: I want to view the SQL statement that parses the relaylog). What to do at this time? Don't panic, this article will tell you the answer!

If you want to know what to do, you have to fully understand the help system provided by MySQL. Below, we will show you the true face of Lushan!

01

Where did the help statement information come from

MySQL Server provides 4 tables for storing help information on the server side (help information viewed using the help syntax). These tables are located under the mysql system dictionary library. The help statement is to get data from these tables and return to the client, as follows:

  • help_category: information about the category of help topics

  • help_keyword: keyword information related to the help topic

  • help_relation: help the mapping between keyword information and topic information

  • help_topic: the detailed content of the help topic

02

When the help statement information was generated

These tables are created by loading the share/fill_help_tables.sql file when the database is initialized. If MySQL is installed using a binary or source code distribution on Unix, the file will be directly imported to initialize the contents of the help table when the data directory is initialized. For RPM distributions on Linux or binary distributions on Windows, the initialization of the contents of the help table is performed as part of the MySQL installation process.

  • If you use a binary distribution to upgrade MySQL, the help tables will not be automatically upgraded, but you can manually upgrade (load the share/fill_help_tables.sql file manually), such as: shell> mysql -u root mysql <fill_help_tables.sql

  • You can get the latest fill_help_tables.sql at any time to upgrade your help tables. Download the correct file for your MySQL version from http://dev.mysql.com/doc/index-other.html

03

help Help information storage table in detail

The help syntax supports matching queries of three patterns: view all topic top-level categories or subcategories, view keywords under help topics, and use unique keywords under a given topic to view help information. These information are stored in help_category, help_topic, The help_keyword table and the help_relation table store the mapping information of the information in the help_topic and help_keyword tables. The following will be a simple science popularization for the basic knowledge of these tables.

(1)help_category

This table provides category information for query help topics. Each category corresponds to N help topic names or topic subcategory names. We can also see from the information in the query table, as follows:

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)

Table field meaning

  • help_category_id: the record ID of the help topic name or subcategory name in the table

  • name: Help topic category name or word category name

  • parent_category_id: The record ID of the parent subject category name in the table. Some subject categories have child subject categories. For example, most subject categories are actually subcategories of the Contents category (and are the top-level category and the first-level parent category). Some are subcategories of Geographic Features category (second-level parent category), and some are subcategories of Functions (second-level parent category)

  • url: Corresponds to the link address in the official MySQL manual

(2)help_keyword

This table provides query string information related to help topics, as follows:

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)

Table field meaning

  • help_keyword_id: The ID of the help keyword name is recorded in the table

  • name: help keyword string

(3)help_relation

This table provides the mapping between query help keyword information and topic detailed information, and is used to correlate the query help_keyword and help_topic tables, as follows:

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)

Table field meaning

  • help_topic_id: help topic detailed information ID, the ID value is equal to the help_topic_id in the help_topic table

  • help_keyword_id: Help topic keyword information ID, the ID value is equal to help_keyword_id in the help_keyword table

(4)help_topic

This table provides detailed content (detailed help information) of a given keyword in the query help topic, as follows:

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)

Table field meaning

  • help_topic_id: the ID corresponding to the detailed information of the help topic in the table record

  • name: The name of the keyword given by the help topic, which is equal to the value of the name field in the help_keyword table

  • help_category_id: Help topic category ID, equal to the value of the help_category_id field in the help_category table

  • description: the detailed information of the help topic (here is what we really want to see when we usually query the help information, for example: tell us how to use the grammar and precautions of a certain sentence)

  • example: the example information of the help topic (here tells us an example of how to use XX sentence)

  • url: This help topic corresponds to the URL link address in the MySQL official online manual

04

Examples of help statement usage

As we mentioned earlier, the help syntax supports matching queries in three patterns. So, going back to the problem we raised at the beginning of the article, I can’t remember the specific spelling of a sentence. I can only remember a few letters vaguely, or say very clearly what help information I want to check, but I don’t know what to use. Keyword to query help information (for example: you want to view the SQL statement that parses the relaylog). What to do at this time?

(1) What should I do if I only remember a few letters

The help information provided by MySQL can actually be directly given a subject keyword for query, without specifying the subject name. If you record a few letters of a SQL clause keyword, you can use these letters to try several times ,as follows:

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: This is actually equivalent to the keyword given by the help statement to match the name field of the help_keyword table. If there is a record return, use the help_category, help_keyword, help_relation, and help_topic four tables to do complex related queries, right join the help_topic table In the name field, if a unique record is returned, help information is returned. If multiple rows are returned, a keyword list is returned. Use these specific keywords to query specific help information, for example:

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) I don’t remember what to do

If you don’t remember anything, you can only use the dumbest method, carpet search

First of all, we just type a few letters to give the help sentence, for example: 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

Then, view all the subject categories

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

Use help Administration to view all keywords under this help topic

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

Use SHOW RELAYLOG EVENTS statement to view specific help information

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, now I believe you have a clearer understanding of the composition of the MySQL help system and what help information help can provide us. Here are some more tips for everyone:

  • The search keywords given in the HELP statement are not case sensitive

  • Search keywords can include wildcards% and _, and the effect is the same as the pattern matching operation performed by the LIKE operator. For example: HELP'rep%' returns a list of topics starting with rep

  • If the help category string and help topic string contain multiple characters, you can use quotation marks or not. To avoid ambiguity, it is best to use quotation marks

05

Precautions related to the help information sheet

For database instances participating in replication, there are some considerations for helping table updates. The help tables are written to binlog by default (because these help tables match the version, you need to upgrade the version of one instance, and other instances need to be updated simultaneously), so you need to consider whether you need to upgrade the main library help table At the same time, these updates are synchronized to the slave library through the binlog of the master library.

  • If the master-slave library version is different, then the master-slave library needs to be upgraded separately to help information table 

  • If it is a version of MySQL before 5.7.5, the master and slave libraries respectively upgrade the help information table using the command: mysql --init-command="SET sql_log_bin=0" mysql <fill_help_tables.sql

  • If it is MySQL 5.7.5 and later versions, you do not need to use --init-command="SET sql_log_bin=0", because the fill_help_tables.sql file contains SET sql_log_bin=0, so the master and slave libraries only need to be executed separately Command: mysql mysql <fill_help_tables.sql

  • If the master-slave version is the same, then the master-slave library can be upgraded in the master library, and the help information table of the slave library can be updated by copying

  • If it is a version of MySQL before 5.7.5, you only need to execute the command in the main library: mysql mysql <fill_help_tables.sql 

  • If it is MySQL 5.7.5 or later, you need to modify the ll_help_tables.sql file in the main library server first, remove SET sql_log_bin=0, and then execute the command in the main library: mysql mysql <fill_help_tables.sql.

PS: Before MySQL 5.7.5, these tables used MyISAM, and changed to InnoDB engine after this version

| About the author

Luo Xiaobo·ScaleFlux Database Technology Expert

One of the authors of "A Thousand Gold Recipes-MySQL Performance Optimization Pyramid Rule", "Data Ecology: MySQL Replication Technology and Production Practice".

Familiar with MySQL architecture, good at overall database tuning, like to specialize in open source technology, and keen on the promotion of open source technology, have done many public database topic sharing online and offline, and published nearly 100 database-related research articles.

The full text is over.

Enjoy MySQL :)

Teacher Ye's "MySQL Core Optimization" class has been upgraded to MySQL 8.0, scan the code to start the journey of MySQL 8.0 practice

Guess you like

Origin blog.csdn.net/n88Lpo/article/details/110601002