Recommended the content of MySQLHELPCONTENTS
I often encounter this kind of situation.I want to perform an operation when I log in to the database through the MySQL client in an environment where the Internet cannot be accessed, but I forgot the specific syntax of the operation, which is inconvenient.
Actually, the MySQL database has built-in help documents, which can be viewed through help contents.
As shown below:
It can be seen that this document covers most of the topics of database operations.
Documents are divided into the above categories, and each category includes smaller-grained categories, and the category finally consists of specific topics.
So what is the hierarchical relationship between these?
I wanted to perform an operation yesterday
mysql> backup table emp to'/tmp/mysqlbackup';
Because this backup operation has not been used before, I am going to use the help file that comes with MySQL to view the specific usage.The category to which this command belongs is a bit vague, for example, Administration and Utility are both possible.Finally, I found it, but I still couldn't find it.
Thinking about it, it is really not very efficient to look at the help files in this way.If you know the hierarchical relationship between them, it will be easier.
So, I wrote a script to visually display the relationship between the big category and the small category, and the small category and topic in the help document.
The details are as follows:
#!/bin/bash #All operations are performed in/tmp/test, because many temporary files are created in the middle to facilitate subsequent deletion. mkdir/tmp/test #Get the content of the above picture and redirect to the/tmp/test/test.txt file mysql-uroot-p123456-e "help contents ">/tmp/test/test.txt #Define the output format, \t output tab, \b is equivalent to a space in the backspace, referring to the output mode of the tree command. format="|\t\b" #Delete the first and last line sed-i '1d;$d'/tmp/test/test.txt cd/tmp/test #The function of introducing number lies in the output of subsequent format number=0 #Recursive call is used in the follow-up, here is the function defined function recursive(){ filename=$1 number=$[$number+1] while read line do #name should be a file name, such as Account Management, use the tr function to remove the spaces between the characters name=`echo $line|tr-d [:blank:]` #Output the content of each category, it may be topic, it may be categories mysql-uroot-p123456-e "help $line" > $name #Take the content of the first line of the output file.If it is a specific topic, the content of the first line is: Name:'ALTER USER', otherwise it is still categories and needs to be called recursively firstline=`head-1 $name` #The whole logic is more complicated in two categories, one is Numeric Functions, and the other is PLUGINS.Let me talk about PLUGINS.Generally, for a specific topic, its output is similar to Name:'ALTER USER', and PLUGINS #The corresponding output is Name:'SHOW PLUGINS', so the judgment sentence below has one more "$firstline"="Name:'SHOW PLUGINS'", which is aimed at PLUGINS.Another more complicated one is Numeric Functions #The topic under it has a division sign "/", which basically cannot be used as a file name.Therefore, in the following judgment logic, if you encounter Numeric Functions, you will directly print out the topic in this class without making the judgment of Name:'ALTER USER' if ["$firstline"="Name:'$line'"-o "$firstline"="Name:'SHOW PLUGINS'" ];then for i in `seq $[$number-1]` do echo-ne $format done echo "├── $line" else #If it is not topic, it means categories, which can be judged recursively, the only exception is Numeric Functions #The echo "├── $line" below prints out the names of categories for i in `seq $[$number-1]` do echo-ne $format done echo "├── $line" #When encountering Numeric Functions, directly print out the topic in this class if ["$line"="Numeric Functions" ];then sed-i '1d;$d' $name while read functions do for i in `seq $number` do echo-ne $format done echo "├── $functions" done < $name else #Other categories, call this function recursively for judgment. sed-i '1d;$d' $name recursive $name number=$[$number-1] fi fi done < $filename } #Main function recursive/tmp/test/test.txt #Processed, delete the folder rm-rf/tmp/test
Because the MySQL client directly specifies the password when logging in to the database, if it is executed directly, a lot of "Warning: Using a password on the command line interface can be insecure." will be output,
Can be redirected to a file
# sh 2.sh > 1.txt
The results in the final file are as follows:
├── Account Management | ├── ALTER USER | ├── CREATE USER | ├── DROP USER | ├── GRANT | ├── RENAME USER | ├── REVOKE | ├── SET PASSWORD ├── Administration | ├── BINLOG | ├── CACHE INDEX | ├── FLUSH | ├── FLUSH QUERY CACHE | ├── HELP COMMAND | ├── KILL | ├── LOAD INDEX | ├── RESET | ├── SET | ├── SHOW | ├── SHOW AUTHORS | ├── SHOW BINARY LOGS | ├── SHOW BINLOG EVENTS | ├── SHOW CHARACTER SET | ├── SHOW COLLATION | ├── SHOW COLUMNS | ├── SHOW CONTRIBUTORS | ├── SHOW CREATE DATABASE | ├── SHOW CREATE EVENT | ├── SHOW CREATE FUNCTION | ├── SHOW CREATE PROCEDURE | ├── SHOW CREATE TABLE | ├── SHOW CREATE TRIGGER | ├── SHOW CREATE VIEW | ├── SHOW DATABASES | ├── SHOW ENGINE | ├── SHOW ENGINES | ├── SHOW ERRORS | ├── SHOW EVENTS | ├── SHOW FUNCTION CODE | ├── SHOW FUNCTION STATUS | ├── SHOW GRANTS | ├── SHOW INDEX | ├── SHOW MASTER STATUS | ├── SHOW OPEN TABLES | ├── SHOW PLUGINS | ├── SHOW PRIVILEGES | ├── SHOW PROCEDURE CODE | ├── SHOW PROCEDURE STATUS | ├── SHOW PROCESSLIST | ├── SHOW PROFILE | ├── SHOW PROFILES | ├── SHOW RELAYLOG EVENTS | ├── SHOW SLAVE HOSTS | ├── SHOW SLAVE STATUS | ├── SHOW STATUS | ├── SHOW TABLE STATUS | ├── SHOW TABLES | ├── SHOW TRIGGERS | ├── SHOW VARIABLES | ├── SHOW WARNINGS ├── Compound Statements | ├── BEGIN END | ├── CASE STATEMENT | ├── CLOSE | ├── DECLARE CONDITION | ├── DECLARE CURSOR | ├── DECLARE HANDLER | ├── DECLARE VARIABLE | ├── FETCH | ├── GET DIAGNOSTICS | ├── IF STATEMENT | ├── ITERATE | ├── LABELS | ├── LEAVE | ├── LOOP | ├── OPEN | ├── REPEAT LOOP | ├── RESIGNAL | ├── RETURN | ├── SIGNAL | ├── WHILE ├── Data Definition | ├── ALTER DATABASE | ├── ALTER EVENT | ├── ALTER FUNCTION | ├── ALTER LOGFILE GROUP | ├── ALTER PROCEDURE | ├── ALTER SERVER | ├── ALTER TABLE | ├── ALTER TABLESPACE | ├── ALTER VIEW | ├── CONSTRAINT | ├── CREATE DATABASE | ├── CREATE EVENT | ├── CREATE FUNCTION | ├── CREATE INDEX | ├── CREATE LOGFILEGROUP | ├── CREATE PROCEDURE | ├── CREATE SERVER | ├── CREATE TABLE | ├── CREATE TABLESPACE | ├── CREATE TRIGGER | ├── CREATE VIEW | ├── DROP DATABASE | ├── DROP EVENT | ├── DROP FUNCTION | ├── DROP INDEX | ├── DROP PROCEDURE | ├── DROP SERVER | ├── DROP TABLE | ├── DROP TABLESPACE | ├── DROP TRIGGER | ├── DROP VIEW | ├── RENAME TABLE | ├── TRUNCATE TABLE ├── Data Manipulation | ├── CALL | ├── DELETE | ├── DO | ├── DUAL | ├── HANDLER | ├── INSERT | ├── INSERT DELAYED | ├── INSERT SELECT | ├── JOIN | ├── LOAD DATA | ├── LOAD XML | ├── REPLACE | ├── SELECT | ├── UNION | ├── UPDATE ├── Data Types | ├── AUTO_INCREMENT | ├── BIGINT | ├── BINARY | ├── BIT | ├── BLOB | ├── BLOB DATA TYPE | ├── BOOLEAN | ├── CHAR | ├── CHAR BYTE | ├── DATE | ├── DATETIME | ├── DEC | ├── DECIMAL | ├── DOUBLE | ├── DOUBLE PRECISION | ├── ENUM | ├── FLOAT | ├── INT | ├── INTEGER | ├── LONGBLOB | ├── LONGTEXT | ├── MEDIUMBLOB | ├── MEDIUMINT | ├── MEDIUMTEXT | ├── SET DATA TYPE | ├── SMALLINT | ├── TEXT | ├── TIME | ├── TIMESTAMP | ├── TINYBLOB | ├── TINYINT | ├── TINYTEXT | ├── VARBINARY | ├── VARCHAR | ├── YEAR DATA TYPE ├── Functions | ├── Bit Functions | | ├── & | | ├── << | | ├── >> | | ├── BIT_COUNT | | ├── ^ | | ├── | | | ├── ~ | ├── Comparison operators | | ├── != | | ├── < | | ├── <= | | ├── <=> | | ├──= | | ├── > | | ├── >= | | ├── BETWEEN AND | | ├── COALESCE | | ├── GREATEST | | ├── IN | | ├── INTERVAL | | ├── IS | | ├── IS NOT | | ├── IS NOT NULL | | ├── IS NULL | | ├── ISNULL | | ├── LEAST | | ├── NOT BETWEEN | | ├── NOT IN | ├── Control flow functions | | ├── CASE OPERATOR | | ├── IF FUNCTION | | ├── IFNULL | | ├── NULLIF | ├── Date and Time Functions | | ├── ADDDATE | | ├── ADDTIME | | ├── CONVERT_TZ | | ├── CURDATE | | ├── CURRENT_DATE | | ├── CURRENT_TIME | | ├── CURRENT_TIMESTAMP | | ├── CURTIME | | ├── DATE FUNCTION | | ├── DATEDIFF | | ├── DATE_ADD | | ├── DATE_FORMAT | | ├── DATE_SUB | | ├── DAY | | ├── DAYNAME | | ├── DAYOFMONTH | | ├── DAYOFWEEK | | ├── DAYOFYEAR | | ├── EXTRACT | | ├── FROM_DAYS | | ├── FROM_UNIXTIME | | ├── GET_FORMAT | | ├── HOUR | | ├── LAST_DAY | | ├── LOCALTIME | | ├── LOCALTIMESTAMP | | ├── MAKEDATE | | ├── MAKETIME | | ├── MICROSECOND | | ├── MINUTE | | ├── MONTH | | ├── MONTHNAME | | ├── NOW | | ├── PERIOD_ADD | | ├── PERIOD_DIFF | | ├── QUARTER | | ├── SECOND | | ├── SEC_TO_TIME | | ├── STR_TO_DATE | | ├── SUBDATE | | ├── SUBTIME | | ├── SYSDATE | | ├── TIME FUNCTION | | ├── TIMEDIFF | | ├── TIMESTAMP FUNCTION | | ├── TIMESTAMPADD | | ├── TIMESTAMPDIFF | | ├── TIME_FORMAT | | ├── TIME_TO_SEC | | ├── TO_DAYS | | ├── TO_SECONDS | | ├── UNIX_TIMESTAMP | | ├── UTC_DATE | | ├── UTC_TIME | | ├── UTC_TIMESTAMP | | ├── WEEK | | ├── WEEKDAY | | ├── WEEKOFYEAR | | ├── YEAR | | ├── YEARWEEK | ├── Encryption Functions | | ├── AES_DECRYPT | | ├── AES_ENCRYPT | | ├── COMPRESS | | ├── DECODE | | ├── DES_DECRYPT | | ├── DES_ENCRYPT | | ├── ENCODE | | ├── ENCRYPT | | ├── MD5 | | ├── OLD_PASSWORD | | ├── PASSWORD | | ├── RANDOM_BYTES | | ├── SHA1 | | ├── SHA2 | | ├── UNCOMPRESS | | ├── UNCOMPRESSED_LENGTH | | ├── VALIDATE_PASSWORD_STRENGTH | ├── Information Functions | | ├── BENCHMARK | | ├── CHARSET | | ├── COERCIBILITY | | ├── COLLATION | | ├── CONNECTION_ID | | ├── CURRENT_USER | | ├── DATABASE | | ├── FOUND_ROWS | | ├── LAST_INSERT_ID | | ├── ROW_COUNT | | ├── SCHEMA | | ├── SESSION_USER | | ├── SYSTEM_USER | | ├── USER | | ├── VERSION | ├── Logical operators | | ├──! | | ├── AND | | ├── ASSIGN-EQUAL | | ├── ASSIGN-VALUE | | ├── OR | | ├── XOR | ├── Miscellaneous Functions | | ├── DEFAULT | | ├── GET_LOCK | | ├── INET6_ATON | | ├── INET6_NTOA | | ├── INET_ATON | | ├── INET_NTOA | | ├── IS_FREE_LOCK | | ├── IS_IPV4 | | ├── IS_IPV4_COMPAT | | ├── IS_IPV4_MAPPED | | ├── IS_IPV6 | | ├── IS_USED_LOCK | | ├── MASTER_POS_WAIT | | ├── NAME_CONST | | ├── RELEASE_LOCK | | ├── SLEEP | | ├── UUID | | ├── UUID_SHORT | | ├── VALUES | ├── Numeric Functions | | ├──% | | ├── * | | ├── + | | ├──-BINARY | | ├──-UNARY | | ├──/ | | ├── ABS | | ├── ACOS | |├── ASIN | | ├── ATAN | | ├── ATAN2 | | ├── CEIL | | ├── CEILING | | ├── CONV | | ├── COS | | ├── COT | | ├── CRC32 | | ├── DEGREES | | ├── DIV | | ├── EXP | | ├── FLOOR | | ├── LN | | ├── LOG | | ├── LOG10 | | ├── LOG2 | | ├── MOD | | ├── PI | | ├── POW | | ├── POWER | | ├── RADIANS | | ├── RAND | | ├── ROUND | | ├── SIGN | | ├── SIN | | ├── SQRT | | ├── TAN | | ├── TRUNCATE | ├── String Functions | | ├── ASCII | | ├── BIN | | ├── BINARY OPERATOR | | ├── BIT_LENGTH | | ├── CAST | | ├── CHAR FUNCTION | | ├── CHARACTER_LENGTH | | ├── CHAR_LENGTH | | ├── CONCAT | | ├── CONCAT_WS | | ├── CONVERT | | ├── ELT | | ├── EXPORT_SET | | ├── EXTRACTVALUE | | ├── FIELD | | ├── FIND_IN_SET | | ├── FORMAT | | ├── FROM_BASE64() | | ├── HEX | | ├── INSERT FUNCTION | | ├── INSTR | | ├── LCASE | | ├── LEFT | | ├── LENGTH | | ├── LIKE | | ├── LOAD_FILE | | ├── LOCATE | | ├── LOWER | | ├── LPAD | | ├── LTRIM | | ├── MAKE_SET | | ├── MATCH AGAINST | | ├── MID | | ├── NOT LIKE | | ├── NOT REGEXP | | ├── OCT | | ├── OCTET_LENGTH | | ├── ORD | | ├── POSITION | | ├── QUOTE | | ├── REGEXP | | ├── REPEAT FUNCTION | | ├── REPLACE FUNCTION | | ├── REVERSE | | ├── RIGHT | | ├── RPAD | | ├── RTRIM | | ├── SOUNDEX | | ├── SOUNDS LIKE | | ├── SPACE | | ├── STRCMP | | ├── SUBSTR | | ├── SUBSTRING | | ├── SUBSTRING_INDEX | | ├── TO_BASE64() | | ├── TRIM | | ├── UCASE | | ├── UNHEX | | ├── UPDATEXML | | ├── UPPER | | ├── WEIGHT_STRING ├── Functions and Modifiers for Use with GROUP BY | ├── AVG | ├── BIT_AND | ├── BIT_OR | ├── BIT_XOR | ├── COUNT | ├── COUNT DISTINCT | ├── GROUP_CONCAT | ├── MAX | ├── MIN | ├── STD | ├── STDDEV | ├── STDDEV_POP | ├── STDDEV_SAMP | ├── SUM | ├── VARIANCE | ├── VAR_POP | ├── VAR_SAMP ├── Geographic Features | ├── GEOMETRY | ├── GEOMETRY HIERARCHY | ├── SPATIAL | ├── Geometry constructors | | ├── GEOMETRYCOLLECTION | | ├── LINESTRING | | ├── MULTILINESTRING | | ├── MULTIPOINT | | ├── MULTIPOLYGON | | ├── POINT | | ├── POLYGON | ├── Geometry properties | | ├── DIMENSION | | ├── ENVELOPE | | ├── GEOMETRYTYPE | | ├── ISEMPTY | | ├── ISSIMPLE | | ├── SRID | | ├── ST_DIMENSION | | ├── ST_ENVELOPE | | ├── ST_GEOMETRYTYPE | | ├── ST_ISEMPTY | | ├── ST_ISSIMPLE | | ├── ST_SRID | ├── Geometry relations | | ├── CONTAINS | | ├── CROSSES | | ├── DISJOINT | | ├── EQUALS | | ├── INTERSECTS | | ├── OVERLAPS | | ├── ST_CONTAINS | | ├── ST_CROSSES | | ├── ST_DISJOINT | | ├── ST_DISTANCE | | ├── ST_EQUALS | | ├── ST_INTERSECTS | | ├── ST_OVERLAPS | | ├── ST_TOUCHES | | ├── ST_WITHIN | | ├── TOUCHES | | ├── WITHIN | ├── LineString properties | | ├── ENDPOINT | | ├── GLENGTH | | ├── ISCLOSED | | ├── NUMPOINTS | | ├── POINTN | | ├── STARTPOINT | | ├── ST_ENDPOINT | | ├── ST_ISCLOSED | | ├── ST_NUMPOINTS | | ├── ST_POINTN | | ├── ST_STARTPOINT | ├── MBR | | ├── ASYMMETRIC_DECRYPT | | ├── ASYMMETRIC_DERIVE | | ├── ASYMMETRIC_ENCRYPT | | ├── ASYMMETRIC_SIGN | | ├── ASYMMETRIC_VERIFY | | ├── CREATE_ASYMMETRIC_PRIV_KEY | | ├── CREATE_ASYMMETRIC_PUB_KEY | | ├── CREATE_DH_PARAMETERS | | ├── CREATE_DIGEST | | ├── GTID_SUBSET | | ├── GTID_SUBTRACT | | ├── MBR DEFINITION | | ├── MBRCONTAINS | | ├── MBRDISJOINT | | ├── MBREQUAL | | ├── MBRINTERSECTS | | ├── MBROVERLAPS | | ├── MBRTOUCHES | | ├── MBRWITHIN | | ├── SQL_THREAD_WAIT_AFTER_GTIDS | | ├── WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS | ├── Point properties | | ├── ST_X | | ├── ST_Y | | ├── X | | ├── Y | ├── Polygon properties | | ├── AREA | | ├── CENTROID | | ├── EXTERIORRING | | ├── INTERIORRINGN | | ├── NUMINTERIORRINGS | | ├── ST_AREA | | ├── ST_CENTROID | | ├── ST_EXTERIORRING | | ├── ST_INTERIORRINGN | | ├── ST_NUMINTERIORRINGS | ├── WKB | | ├── ASBINARY | | ├── ASTEXT | | ├── GEOMCOLLFROMWKB | | ├── GEOMFROMWKB | | ├── LINEFROMWKB | | ├── MLINEFROMWKB | | ├── MPOINTFROMWKB | | ├── MPOLYFROMWKB | | ├── POINTFROMWKB | | ├── POLYFROMWKB | | ├── ST_ASBINARY | | ├── ST_ASTEXT | | ├── ST_GEOMCOLLFROMWKB | | ├── ST_GEOMFROMWKB | | ├── ST_LINEFROMWKB | | ├── ST_POINTFROMWKB | | ├── ST_POLYFROMWKB | ├── WKT | | ├── GEOMCOLLFROMTEXT | | ├── GEOMFROMTEXT | | ├── LINEFROMTEXT | | ├── MLINEFROMTEXT | | ├── MPOINTFROMTEXT | | ├── MPOLYFROMTEXT | | ├── POINTFROMTEXT | | ├── POLYFROMTEXT | | ├── ST_GEOMCOLLFROMTEXT | | ├── ST_GEOMFROMTEXT | | ├── ST_LINEFROMTEXT | | ├── ST_POINTFROMTEXT | | ├── ST_POLYFROMTEXT | | ├── WKT DEFINITION ├── Help Metadata | ├── HELP_DATE | ├── HELP_VERSION ├── Language Structure ├── Plugins ├── Procedures ├── Storage Engines ├── Table Maintenance | ├── ANALYZE TABLE | ├── CHECK TABLE | ├── CHECKSUM TABLE | ├── OPTIMIZE TABLE | ├── REPAIR TABLE ├── Transactions | ├── CHANGE MASTER TO | ├── DEALLOCATE PREPARE | ├── EXECUTE STATEMENT | ├── ISOLATION | ├── LOCK | ├── PREPARE | ├── PURGE BINARY LOGS | ├── RESET MASTER | ├── RESET SLAVE | ├── SAVEPOINT | ├── SET GLOBAL SQL_SLAVE_SKIP_COUNTER | ├── SET SQL_LOG_BIN | ├── START SLAVE | ├── START TRANSACTION | ├── STOP SLAVE | ├── XA ├── User-Defined Functions | ├── CREATE FUNCTION UDF | ├── DROP FUNCTION UDF ├── Utility | ├── EXPLAIN | ├── HELP STATEMENT | ├── USE
Summary:
There are two interesting points in the process of writing the whole script.
1.Function recursive operation, Shell has not been used to perform function recursive operation before.
2.Use the tree's output format for reference, and format the result for output.
The idea is as follows: First define a number as 0, and every time you enter the recursive function, the current number will be increased by 1.If this is the case, the number value will always increase, so call the recursive function part in the else script above , Will execute number=$[$number-1] afterwards, similar to restoring to the upper level directory.
The above article recommends a hierarchical output method for the content of MySQL help contents, which is the whole content shared by the editor.I hope to give you a reference, and I hope you can support the script home more.
0 Comments