Often encounter this situation, in an environment can not access the Internet through the MySQL client login database, want to perform an operation, but forgot the operation of the specific syntax, all kinds of inconvenient.
In fact, the MySQL database has a built-in help document, which can be viewed by helping contents.
As shown below:
Visible, this document covers most of the topics of database operations.
The document is divided into the above categories, each large class includes a smaller granularity of the class, the class finally has a specific topic composition.
So what is the hierarchical relationship?
I wanted to do an operation yesterday
Mysql> Backup table emp to '/tmp/mysqlbackup ';
Because this backup operation has not been used before, prepare to use MySQL's own help document to see the specific usage. The category that this order belonged to is somewhat vague, for example administration and utility are possible. Finally found a pass, still did not find.
If you think about it, it's really not very efficient to look at the Help document, if you know the hierarchical relationship between the two is good.
As a result, a script was written to visually display the relationship between large classes and small classes, small classes, and topic in the Help document.
Specifically as follows:
#!/bin/bash #所有操作都是在/tmp/test Because many temporary files are created in the middle to facilitate subsequent deletions. Mkdir/tmp/test #获取上图的内容重定向到/tmp/test/test.txt file mysql-uroot-p123456-e "Help Contents" >/tmp/test/test.txt #定义输出的
format, \ t output tab,\b equivalent to backspace a space, reference to the tree command output mode. format= "|\t\b" #删除第一行和最后一行 sed-i ' 1d; $d '/tmp/test/test.txt cd/tmp/test #引入number的作用在于后续格式的输出 number=0 #后续用了递归调用, defined here is the function functions recursive () {filename=$1 number=$[$number +1] While the read line does #name要做为文件名, such as Account Management, which uses the TR function to remove the word The space in the middle of the Name= ' echo $line |tr-d [: blank:] ' #输出每个分类中的内容, may be topic, categories MYSQL-UROOT-P123456-E "Help $line" > $na Me #取输出文件的第一行的内容, if it is a specific topic, the first line of content is: ' Name: ' ALTER USER ', otherwise it is categories, you need to call firstline= ' head-1 $name ' The whole logic is more complex there are two categories, one is numeric functions, the other is plugins. First of all, PLUGINS, generally for a specific topic, its output is similar to the name: ' ALTER USER ', and PLUGINS #对应的输出却是Name: ' Show PLUGINS ', so the following judgment statement has a more "$firstline" = "Name: ' Show PLUGINS '", for that is PLUGINS. Another complication is the numeric functions #它下面的topic有除号 "/", which is basically not a filename. So in the following judgment logic, if you encounter numeric functions, you print out the top of the class directlyIC without Name: ' ALTER USER ' judgment if ["$firstline" = "Name: ' $line '"-o "$firstline" = "Name: ' Show PLUGINS '"];then for I In ' seq $[$number-1] ' doing echo-ne $format done echo "├── $line" Else #如果不是topic, the representative is categories, can be judged recursively, the only exception is numeric Fu Nctions #下面的echo "├── $line" prints out the name of categories for I in ' seq $[$number-1] ' doing echo-ne $format done echo ' ├── $line ' #遇到
Numeric functions, directly print out the topic if ["$line" = "Numeric functions"];then sed-i ' 1d; $d ' $name while read functions do
For i in ' seq $number ' does Echo-ne $format do echo "├── $functions" Done < $name else #其它的categories, recursively call the function for judgment. Sed-i ' 1d $d ' $name recursive $name number=$[$number-1] fi fi done < $filename} #主函数 Recursive/tmp/test/test.txt # Finished processing, delete folder Rm-rf/tmp/test
When the MySQL client logs in to the database, the password is specified directly, and if executed directly, a lot of "warning:using a password on the command line interface can insecure."
Can be redirected to a file
# sh 2.sh > 1.txt
The results in the final document 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 LOGFILE GROUP | ├──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 | ├──setSql_log_bin | ├──start SLAVE | ├──start TRANSACTION | ├──stop SLAVE | ├──xa├──user-defined Functions | ├──create FUNCTION UDF | ├──drop FUNCTION udf├──utility | ├──explain | ├──help STATEMENT | ├──use
Summarize:
The entire script is written in the process of two points is more interesting.
1. Function recursive operation, not before how to use the shell for recursive functions.
2. Using the output format of tree, the result is formatted and output.
The idea is as follows: first define a number of 0, each time into the recursive function, will be the current number plus 1, if this is the case, the number will continue to increase, so in the above script else call the recursive function section, Executes number=$[$number-1] Later, similar to restoring to the previous level of the directory.
The above article will be MySQL Help contents content of the level of output method recommended is small set to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.