I believe that as operation and maintenance masters & programming experts, everyone has their own set of memos to record some commonly used scripts. Now! It’s time! To show your cards!
In this informal script collection contest, we welcome all TiDBers to showcase their treasured TiDB-related SQL scripts If you have any practical/convenient/highly recommended scripts, feel free to show them off together!
Contest Rewards: A comprehensive collection of TiDB community SQL scripts & 100 points for those who make it to the list!
This Topic:
SQL script collection, we welcome all TiDBers to showcase the TiDB-related SQL scripts they find practical/convenient/highly recommended!
For example, from @I am Coffee Brother:
View table metadata
show stats_meta where db_name like ‘%sbtest%’;
Event Rewards:
TiDBers who showcase their recommended TiDB-related SQL scripts will receive a reward of 100 points!
select query_time, query, user
from information_schema.slow_query
where is_internal=false -- Exclude TiDB internal slow query SQL
and user = "user1" -- The username to search for
order by query_time desc
limit 2;
If partition tables are not involved, use the following method to check the usage of the table:
select TABLE_SCHEMA, TABLE_NAME, TABLE_ROWS,
(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024 as table_size from tables order by table_size
desc limit 20;
Additionally, partition tables provide resource usage information for both partitioned and non-partitioned tables (we use partitioned tables more frequently):
select TABLE_SCHEMA, TABLE_NAME, PARTITION_NAME, TABLE_ROWS,
(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024 as table_size from
information_schema.PARTITIONS order by table_size desc limit 20;
In the query analyzer, view the configuration file parameters: show config
The SHOW CONFIG statement is used to display the current configuration being applied by each component of TiDB. Please note that configurations and system variables operate on different dimensions, so do not confuse them. If you want to obtain information about system variables, please use the SHOW VARIABLES syntax.