MySQL show command method to obtain detailed information about the table column and the entire database (excellent collection)

Source: Internet
Author: User
In MySQL, the show syntax is used to obtain detailed information about the table column and the entire database, allowing you to conveniently view detailed information about the database.

In MySQL, the show syntax is used to obtain detailed information about the table column and the entire database, allowing you to conveniently view detailed information about the database.

Show databases;
Show tables from db_name;

Show columns from table_name from db_name;
Show index from talbe_name [from db_name];

Show status;
Show variables;

Show [full] processlist;
Show table status [from db_name];

Show grants for user;

In addition to status, processlist, and grants, other options can contain the like wild option, which can use the SQL '%' and '_' characters;

Show databases like '% T ';

All databases whose names end with the 'T' character will be listed


Of course, in these SQL statements, you can also use db_name.table_name to replace table_name from db_name for easier writing!

If a user does not have any permissions for a table, the table will notSHOW TABLESOrmysqlshow db_nameShown in the output

You may still remember describe table_name, which achieves the same effect as show columns from db_name.table_name.

You can use mysqlshow -- status to get the same effect on show status.


SHOW FIELDSYesSHOW COLUMNSA synonym,SHOW KEYSYesSHOW INDEXA synonym. You can also usemysqlshow db_name tbl_nameOrmysqlshow -k db_name tbl_nameLists the columns or indexes of a table.

SHOW INDEXSimilar to ODBCSQLStatisticsThe format of the call to return the index information. The following columns are returned:

SHOW STATUSProvide server status information (e.g.mysqladmin extended-status). The output is similar to the following display, although the format and number can be a bit different:

+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| Aborted_clients | 0 |
| Aborted_connects | 0 |
| Connections | 17 |
| Created_tmp_tables | 0 |
| Delayed_insert_threads | 0 |
| Delayed_writes | 0 |
| Delayed_errors | 0 |
| Flush_commands | 2 |
| Handler_delete | 2 |
| Handler_read_first | 0 |
| Handler_read_key | 1 |
| Handler_read_next | 0 |
| Handler_read_rnd | 35 |
| Handler_update | 0 |
| Handler_write | 2 |
| Key_blocks_used | 0 |
| Key_read_requests | 0 |
| Key_reads | 0 |
| Key_write_requests | 0 |
| Key_writes | 0 |
| Max_used_connections | 1 |
| Not_flushed_key_blocks | 0 |
| Not_flushed_delayed_rows | 0 |
| Open_tables | 1 |
| Open_files | 2 |
| Open_streams | 0 |
| Opened_tables | 11 |
| Questions | 14 |
| Slow_queries | 0 |
| Threads_connected | 1 |
| Threads_running | 1 |
| Uptime | 149111 |
+--------------------------+--------+

The state variables listed above have the following meanings:

Notes:

  • IfOpened_tablesToo big, so yourtable_cacheThe variable may be too small.
  • Ifkey_readsToo big, so yourkey_cacheIt may be too small. The cache hit rate can be used.key_reads/key_read_requestsComputing.
  • IfHandler_read_rndIf it is too large, you may have a large number of queries that require MySQL to scan the entire table or that you have not correctly used the join key value ).

SHOW VARIABLESShow someMySQLSystem variable value, you can also usemysqladmin variablesCommand to obtain this information. If the default value is not suitable, you canmysqldUse the command line option to set the majority of these variables at startup. The output is similar to the following display, although the format and number can be a bit different:

+ ------------------------ + -------------------------- +
| Variable_name | Value |
+ ------------------------ + -------------------------- +
| Back_log | 5 |
| Connect_timeout | 5 |
| Basedir |/my/monty/|
| Datadir |/my/monty/data/|
| Delayed_insert_limit | 1, 100 |
| Delayed_insert_timeout | 300 |
| Delayed_queue_size | 1, 1000 |
| Join_buffer_size | 131072 |
| Flush_time | 0 |
| Interactive_timeout | 28800 |
| Key_buffer_size | 1048540 |
| Language |/my/monty/share/english/|
| Log | OFF |
| Log_update | OFF |
| Long_query_time | 10 |
| Low_priority_updates | OFF |
| Max_allowed_packet| 1048576 |
| Max_connections | 100 |
| Max_connect_errors | 10 |
| Max_delayed_threads | 20 |
| Max_heap_table_size | 16777216 |
| Max_join_size | 4294967295 |
| Max_sort_length | 1024 |
| Max_tmp_tables | 32 |
| Net_buffer_length | 16384 |
| Port | 1, 3306 |
| Protocol-version | 10 |
| Record_buffer | 131072 |
| Skip_locking | ON |
| Socket |/tmp/mysql. sock |
| Sort_buffer | 2097116 |
| Table_cache | 64 |
| Thread_stack | 131072 |
| Tmp_table_size | 1048576 |
| Tmpdir |/machine/tmp/|
| Version | 3.23.0-alpha-debug |
| Wait_timeout | 28800 |
+ ------------------------ + -------------------------- +

SHOW PROCESSLISTShows which thread is running. You can also usemysqladmin processlistCommand to obtain this information.
If you haveProcessPermission, you can see all the threads, otherwise, you can only see your own threads.
See 7.20 KILLSyntax. If you do not useFULLThen, each query is only displayed with the first 100 characters.

SHOW GRANTS FOR userLists authorization commands that must be repeatedly authorized to a user.

mysql> SHOW GRANTS FOR root@localhost;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root''localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.