Desc/explain and show in Mysql

explain/desc

explainOr desccan be used to view the basic information of the table and show how mysql uses the index to process select statements and join tables.

-- 显示数据表各字段含义
explain/desc <表名>
-- 显示sql的执行效率
explain/desc <sql>

For example

explain select * from emp \G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: emp
   partitions: NULL
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 14
     filtered: 100.00
        Extra: NULL
1 row in set, 1 warning (0.00 sec)

explain column explanation

Insert picture description here

  • select_type: indicates the type of query
    Insert picture description here

  • table: which table the corresponding row is accessing, table name or alias.

  • ype: type shows the access type, which is a more important indicator. The resulting value from good to bad is:
    system> const> eq_ref> ref> fulltext> ref_or_null> index_merge> unique_subquery> index_subquery> range> index> ALL, general In other words, you must ensure that the query reaches at least the range level, preferably ref.
    Insert picture description here

  • possible_keys
    shows which indexes are used by the query, indicating that the index can be searched efficiently, but the listed indexes may be useless for the subsequent optimization process.

  • The key
    column shows the key (index) that MySQL actually decided to use. If no index is selected, the key is NULL. To force MySQL to use or ignore the index in the possible_keys column, use FORCE INDEX, USE INDEX, or IGNORE INDEX in the query.

  • key_len The
    key_len column shows the key length that MySQL decided to use. If the key is NULL, the length is NULL. The length of the index used. Without loss of accuracy, the shorter the length, the better


  • Which ref column or constant is used with the index key column in the query

  • The rows
    rows column shows the number of rows that MySQL thinks it must check when executing a query. Note that this is an estimate.

  • Extra
    Extra is another very important column in the EXPLAIN output. This column shows some detailed information of MySQL during the query process, and important supplementary information for the query plan during the execution of the query by the MySQL query optimizer.

show

help show;
Name: 'SHOW'
Description:
SHOW has many forms that provide information about databases, tables,
columns, or status information about the server. This section describes
those following:
-- show有很多形式,提供有关数据库、表、列或有关服务器的状态信息

SHOW {
   
   BINARY | MASTER} LOGS
SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]
SHOW CHARACTER SET [like_or_where]
SHOW COLLATION [like_or_where]
SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [like_or_where]
SHOW CREATE DATABASE db_name
SHOW CREATE EVENT event_name
SHOW CREATE FUNCTION func_name
SHOW CREATE PROCEDURE proc_name
SHOW CREATE TABLE tbl_name
SHOW CREATE TRIGGER trigger_name
SHOW CREATE VIEW view_name
SHOW DATABASES [like_or_where]
SHOW ENGINE engine_name {
   
   STATUS | MUTEX}
SHOW [STORAGE] ENGINES
SHOW ERRORS [LIMIT [offset,] row_count]
SHOW EVENTS
SHOW FUNCTION CODE func_name
SHOW FUNCTION STATUS [like_or_where]
SHOW GRANTS FOR user
SHOW INDEX FROM tbl_name [FROM db_name]
SHOW MASTER STATUS
SHOW OPEN TABLES [FROM db_name] [like_or_where]
SHOW PLUGINS
SHOW PROCEDURE CODE proc_name
SHOW PROCEDURE STATUS [like_or_where]
SHOW PRIVILEGES
SHOW [FULL] PROCESSLIST
SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n]
SHOW PROFILES
SHOW RELAYLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]
SHOW SLAVE HOSTS
SHOW SLAVE STATUS [FOR CHANNEL channel]
SHOW [GLOBAL | SESSION] STATUS [like_or_where]
SHOW TABLE STATUS [FROM db_name] [like_or_where]
SHOW [FULL] TABLES [FROM db_name] [like_or_where]
SHOW TRIGGERS [FROM db_name] [like_or_where]
SHOW [GLOBAL | SESSION] VARIABLES [like_or_where]
SHOW WARNINGS [LIMIT [offset,] row_count]

like_or_where:
    LIKE 'pattern'
  | WHERE expr

If the syntax for a given SHOW statement includes a LIKE 'pattern'
part, 'pattern' is a string that can contain the SQL % and _ wildcard
characters. The pattern is useful for restricting statement output to
matching values.
-- show后面可加通配符

Several SHOW statements also accept a WHERE clause that provides more
flexibility in specifying which rows to display. See
https://dev.mysql.com/doc/refman/8.0/en/extended-show.html.
-- show后面可加where语句来限定显示哪一行
URL: https://dev.mysql.com/doc/refman/8.0/en/show.html

Commonly used show

Display the names of all databases in mysql

show databases;

Display the names of all tables in the current/a database

show tables;
show tables from databas_name

Display the information of the columns in the table (equivalent to desc/explain table_name)

show columns from database_name.table_name

Show whether the create database statement can create the specified database, and you can view the SQL information of the create database statement

show create database database_name;

Shows whether the create table statement can create the specified data table, and you can view the SQL information of the table creation statement.

show create table table_name

Display storage engines and default engines available after installation

show engines;

Display errors, warnings and notifications generated by the last executed statement

show warnings;

Display the error generated by the last executed statement

show errors;

Guess you like

Origin blog.csdn.net/qq_42962353/article/details/108676910