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 TABLES
Ormysqlshow db_name
Shown 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 FIELDS
YesSHOW COLUMNS
A synonym,SHOW KEYS
YesSHOW INDEX
A synonym. You can also usemysqlshow db_name tbl_name
Ormysqlshow -k db_name tbl_name
Lists the columns or indexes of a table.
SHOW INDEX
Similar to ODBCSQLStatistics
The format of the call to return the index information. The following columns are returned:
SHOW STATUS
Provide 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:
- If
Opened_tables
Too big, so yourtable_cache
The variable may be too small.
- If
key_reads
Too big, so yourkey_cache
It may be too small. The cache hit rate can be used.key_reads
/key_read_requests
Computing.
- If
Handler_read_rnd
If 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 VARIABLES
Show someMySQLSystem variable value, you can also usemysqladmin variables
Command to obtain this information. If the default value is not suitable, you canmysqld
Use 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 PROCESSLIST
Shows which thread is running. You can also usemysqladmin processlist
Command to obtain this information.
If you haveProcessPermission, you can see all the threads, otherwise, you can only see your own threads.
See 7.20 KILL
Syntax. If you do not useFULL
Then, each query is only displayed with the first 100 characters.
SHOW GRANTS FOR user
Lists 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 |
+---------------------------------------------------------------------+