- Docs Home
- About TiDB
- Quick Start
- Develop
- Overview
- Quick Start
- Build a TiDB Cluster in TiDB Cloud (Developer Tier)
- CRUD SQL in TiDB
- Build a Simple CRUD App with TiDB
- Example Applications
- Connect to TiDB
- Design Database Schema
- Write Data
- Read Data
- Transaction
- Optimize
- Troubleshoot
- Reference
- Cloud Native Development Environment
- Third-party Support
- Deploy
- Software and Hardware Requirements
- Environment Configuration Checklist
- Plan Cluster Topology
- Install and Start
- Verify Cluster Status
- Test Cluster Performance
- Migrate
- Overview
- Migration Tools
- Migration Scenarios
- Migrate from Aurora
- Migrate MySQL of Small Datasets
- Migrate MySQL of Large Datasets
- Migrate and Merge MySQL Shards of Small Datasets
- Migrate and Merge MySQL Shards of Large Datasets
- Migrate from CSV Files
- Migrate from SQL Files
- Migrate from One TiDB Cluster to Another TiDB Cluster
- Migrate from TiDB to MySQL-compatible Databases
- Advanced Migration
- Integrate
- Maintain
- Monitor and Alert
- Troubleshoot
- TiDB Troubleshooting Map
- Identify Slow Queries
- Analyze Slow Queries
- SQL Diagnostics
- Identify Expensive Queries Using Top SQL
- Identify Expensive Queries Using Logs
- Statement Summary Tables
- Troubleshoot Hotspot Issues
- Troubleshoot Increased Read and Write Latency
- Save and Restore the On-Site Information of a Cluster
- Troubleshoot Cluster Setup
- Troubleshoot High Disk I/O Usage
- Troubleshoot Lock Conflicts
- Troubleshoot TiFlash
- Troubleshoot Write Conflicts in Optimistic Transactions
- Troubleshoot Inconsistency Between Data and Indexes
- Performance Tuning
- Tuning Guide
- Configuration Tuning
- System Tuning
- Software Tuning
- SQL Tuning
- Overview
- Understanding the Query Execution Plan
- SQL Optimization Process
- Overview
- Logic Optimization
- Physical Optimization
- Prepare Execution Plan Cache
- Control Execution Plans
- Tutorials
- TiDB Tools
- Overview
- Use Cases
- Download
- TiUP
- Documentation Map
- Overview
- Terminology and Concepts
- Manage TiUP Components
- FAQ
- Troubleshooting Guide
- Command Reference
- Overview
- TiUP Commands
- TiUP Cluster Commands
- Overview
- tiup cluster audit
- tiup cluster check
- tiup cluster clean
- tiup cluster deploy
- tiup cluster destroy
- tiup cluster disable
- tiup cluster display
- tiup cluster edit-config
- tiup cluster enable
- tiup cluster help
- tiup cluster import
- tiup cluster list
- tiup cluster patch
- tiup cluster prune
- tiup cluster reload
- tiup cluster rename
- tiup cluster replay
- tiup cluster restart
- tiup cluster scale-in
- tiup cluster scale-out
- tiup cluster start
- tiup cluster stop
- tiup cluster template
- tiup cluster upgrade
- TiUP DM Commands
- Overview
- tiup dm audit
- tiup dm deploy
- tiup dm destroy
- tiup dm disable
- tiup dm display
- tiup dm edit-config
- tiup dm enable
- tiup dm help
- tiup dm import
- tiup dm list
- tiup dm patch
- tiup dm prune
- tiup dm reload
- tiup dm replay
- tiup dm restart
- tiup dm scale-in
- tiup dm scale-out
- tiup dm start
- tiup dm stop
- tiup dm template
- tiup dm upgrade
- TiDB Cluster Topology Reference
- DM Cluster Topology Reference
- Mirror Reference Guide
- TiUP Components
- PingCAP Clinic Diagnostic Service
- TiDB Operator
- Dumpling
- TiDB Lightning
- TiDB Data Migration
- About TiDB Data Migration
- Architecture
- Quick Start
- Deploy a DM cluster
- Tutorials
- Advanced Tutorials
- Maintain
- Cluster Upgrade
- Tools
- Performance Tuning
- Manage Data Sources
- Manage Tasks
- Export and Import Data Sources and Task Configurations of Clusters
- Handle Alerts
- Daily Check
- Reference
- Architecture
- Command Line
- Configuration Files
- OpenAPI
- Compatibility Catalog
- Secure
- Monitoring and Alerts
- Error Codes
- Glossary
- Example
- Troubleshoot
- Release Notes
- Backup & Restore (BR)
- TiDB Binlog
- TiCDC
- Dumpling
- sync-diff-inspector
- TiSpark
- Reference
- Cluster Architecture
- Key Monitoring Metrics
- Secure
- Privileges
- SQL
- SQL Language Structure and Syntax
- SQL Statements
ADD COLUMN
ADD INDEX
ADMIN
ADMIN CANCEL DDL
ADMIN CHECKSUM TABLE
ADMIN CHECK [TABLE|INDEX]
ADMIN SHOW DDL [JOBS|QUERIES]
ADMIN SHOW TELEMETRY
ALTER DATABASE
ALTER INDEX
ALTER INSTANCE
ALTER PLACEMENT POLICY
ALTER TABLE
ALTER TABLE COMPACT
ALTER USER
ANALYZE TABLE
BACKUP
BATCH
BEGIN
CHANGE COLUMN
COMMIT
CHANGE DRAINER
CHANGE PUMP
CREATE [GLOBAL|SESSION] BINDING
CREATE DATABASE
CREATE INDEX
CREATE PLACEMENT POLICY
CREATE ROLE
CREATE SEQUENCE
CREATE TABLE LIKE
CREATE TABLE
CREATE USER
CREATE VIEW
DEALLOCATE
DELETE
DESC
DESCRIBE
DO
DROP [GLOBAL|SESSION] BINDING
DROP COLUMN
DROP DATABASE
DROP INDEX
DROP PLACEMENT POLICY
DROP ROLE
DROP SEQUENCE
DROP STATS
DROP TABLE
DROP USER
DROP VIEW
EXECUTE
EXPLAIN ANALYZE
EXPLAIN
FLASHBACK TABLE
FLUSH PRIVILEGES
FLUSH STATUS
FLUSH TABLES
GRANT <privileges>
GRANT <role>
INSERT
KILL [TIDB]
LOAD DATA
LOAD STATS
MODIFY COLUMN
PREPARE
RECOVER TABLE
RENAME INDEX
RENAME TABLE
REPLACE
RESTORE
REVOKE <privileges>
REVOKE <role>
ROLLBACK
SELECT
SET DEFAULT ROLE
SET [NAMES|CHARACTER SET]
SET PASSWORD
SET ROLE
SET TRANSACTION
SET [GLOBAL|SESSION] <variable>
SHOW ANALYZE STATUS
SHOW [BACKUPS|RESTORES]
SHOW [GLOBAL|SESSION] BINDINGS
SHOW BUILTINS
SHOW CHARACTER SET
SHOW COLLATION
SHOW [FULL] COLUMNS FROM
SHOW CONFIG
SHOW CREATE PLACEMENT POLICY
SHOW CREATE SEQUENCE
SHOW CREATE TABLE
SHOW CREATE USER
SHOW DATABASES
SHOW DRAINER STATUS
SHOW ENGINES
SHOW ERRORS
SHOW [FULL] FIELDS FROM
SHOW GRANTS
SHOW INDEX [FROM|IN]
SHOW INDEXES [FROM|IN]
SHOW KEYS [FROM|IN]
SHOW MASTER STATUS
SHOW PLACEMENT
SHOW PLACEMENT FOR
SHOW PLACEMENT LABELS
SHOW PLUGINS
SHOW PRIVILEGES
SHOW [FULL] PROCESSSLIST
SHOW PROFILES
SHOW PUMP STATUS
SHOW SCHEMAS
SHOW STATS_HEALTHY
SHOW STATS_HISTOGRAMS
SHOW STATS_META
SHOW STATUS
SHOW TABLE NEXT_ROW_ID
SHOW TABLE REGIONS
SHOW TABLE STATUS
SHOW [FULL] TABLES
SHOW [GLOBAL|SESSION] VARIABLES
SHOW WARNINGS
SHUTDOWN
SPLIT REGION
START TRANSACTION
TABLE
TRACE
TRUNCATE
UPDATE
USE
WITH
- Data Types
- Functions and Operators
- Overview
- Type Conversion in Expression Evaluation
- Operators
- Control Flow Functions
- String Functions
- Numeric Functions and Operators
- Date and Time Functions
- Bit Functions and Operators
- Cast Functions and Operators
- Encryption and Compression Functions
- Locking Functions
- Information Functions
- JSON Functions
- Aggregate (GROUP BY) Functions
- Window Functions
- Miscellaneous Functions
- Precision Math
- Set Operations
- List of Expressions for Pushdown
- TiDB Specific Functions
- Clustered Indexes
- Constraints
- Generated Columns
- SQL Mode
- Table Attributes
- Transactions
- Garbage Collection (GC)
- Views
- Partitioning
- Temporary Tables
- Cached Tables
- Character Set and Collation
- Placement Rules in SQL
- System Tables
mysql
- INFORMATION_SCHEMA
- Overview
ANALYZE_STATUS
CLIENT_ERRORS_SUMMARY_BY_HOST
CLIENT_ERRORS_SUMMARY_BY_USER
CLIENT_ERRORS_SUMMARY_GLOBAL
CHARACTER_SETS
CLUSTER_CONFIG
CLUSTER_HARDWARE
CLUSTER_INFO
CLUSTER_LOAD
CLUSTER_LOG
CLUSTER_SYSTEMINFO
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
COLUMNS
DATA_LOCK_WAITS
DDL_JOBS
DEADLOCKS
ENGINES
INSPECTION_RESULT
INSPECTION_RULES
INSPECTION_SUMMARY
KEY_COLUMN_USAGE
METRICS_SUMMARY
METRICS_TABLES
PARTITIONS
PLACEMENT_POLICIES
PROCESSLIST
REFERENTIAL_CONSTRAINTS
SCHEMATA
SEQUENCES
SESSION_VARIABLES
SLOW_QUERY
STATISTICS
TABLES
TABLE_CONSTRAINTS
TABLE_STORAGE_STATS
TIDB_HOT_REGIONS
TIDB_HOT_REGIONS_HISTORY
TIDB_INDEXES
TIDB_SERVERS_INFO
TIDB_TRX
TIFLASH_REPLICA
TIKV_REGION_PEERS
TIKV_REGION_STATUS
TIKV_STORE_STATUS
USER_PRIVILEGES
VIEWS
METRICS_SCHEMA
- UI
- TiDB Dashboard
- Overview
- Maintain
- Access
- Overview Page
- Cluster Info Page
- Top SQL Page
- Key Visualizer Page
- Metrics Relation Graph
- SQL Statements Analysis
- Slow Queries Page
- Cluster Diagnostics
- Search Logs Page
- Instance Profiling
- Session Management and Configuration
- FAQ
- CLI
- Command Line Flags
- Configuration File Parameters
- System Variables
- Storage Engines
- Telemetry
- Errors Codes
- Table Filter
- Schedule Replicas by Topology Labels
- FAQs
- Release Notes
- All Releases
- Release Timeline
- TiDB Versioning
- v6.1
- v6.0
- v5.4
- v5.3
- v5.2
- v5.1
- v5.0
- v4.0
- v3.1
- v3.0
- v2.1
- v2.0
- v1.0
- Glossary
TiDB Control User Guide
TiDB Control is a command-line tool of TiDB, usually used to obtain the status information of TiDB for debugging. This document introduces the features of TiDB Control and how to use these features.
Get TiDB Control
You can get TiDB Control by installing it using TiUP or by compiling it from source code.
It is recommended that the version of the Control tool you use is consistent with the version of the cluster.
Install TiDB Control using TiUP
After installing TiUP, you can use tiup ctl tidb
command to get and execute TiDB Control.
Compile from source code
- Compilation environment requirement: Go Version 1.13 or later
- Compilation procedures: Go to the root directory of the TiDB Control project, use the
make
command to compile, and generatetidb-ctl
. - Compilation documentation: you can find the help files in the
doc
directory; if the help files are lost or you want to update them, use themake doc
command to generate the help files.
Usage introduction
This section describes how to use commands, subcommands, options, and flags in tidb-ctl
.
- command: characters without
-
or--
- subcommand: characters without
-
or--
that follow a command - option: characters with
-
or--
- flag: characters exactly following a command/subcommand or option, passing value to the command/subcommand or option
Usage example: tidb-ctl schema in mysql -n db
schema
: the commandin
: the subcommand ofschema
mysql
: the flag ofin
-n
: the optiondb
: the flag of-n
Currently, TiDB Control has the following subcommands:
tidb-ctl base64decode
: used forBASE64
decodingtidb-ctl decoder
: used forKEY
decodingtidb-ctl etcd
: used for operating etcdtidb-ctl log
: used to format the log file to expand the single-line stack informationtidb-ctl mvcc
: used to get the MVCC informationtidb-ctl region
: used to get the Region informationtidb-ctl schema
: used to get the schema informationtidb-ctl table
: used to get the table information
Get help
Use tidb-ctl -h/--help
to get usage information.
TiDB Control consists of multiple layers of commands. You can use -h/--help
after each command/subcommand to get its respective usage information.
The following example shows how to obtain the schema information:
Use tidb-ctl schema -h
to get usage details. The schema
command itself has two subcommands: in
and tid
.
in
is used to obtain the table schema of all tables in the database through the database name.tid
is used to obtain the table schema by using the uniquetable_id
in the whole database.
Global options
tidb-ctl
has the following connection-related global options:
--host
: TiDB Service address (default 127.0.0.1)--port
: TiDB status port (default 10080)--pdhost
: PD Service address (default 127.0.0.1)--pdport
: PD Service port (default 2379)--ca
: The CA file path used for the TLS connection--ssl-key
: The key file path used for the TLS connection--ssl-cert
: The certificate file path used for the TLS connection
--pdhost
and --pdport
are mainly used in the etcd
subcommand. For example, tidb-ctl etcd ddlinfo
. If you do not specify the address and the port, the following default value is used:
- The default service address of TiDB and PD:
127.0.0.1
. The service address must be an IP address. - The default service port of TiDB:
10080
. - The default service port of PD:
2379
.
The schema
command
The in
subcommand
in
is used to obtain the table schema of all tables in the database through the database name.
tidb-ctl schema in <database name>
For example, running tidb-ctl schema in mysql
returns the following result:
[
{
"id": 13,
"name": {
"O": "columns_priv",
"L": "columns_priv"
},
...
"update_timestamp": 399494726837600268,
"ShardRowIDBits": 0,
"Partition": null
}
]
The result is displayed in the JSON format. (The above output is truncated.)
If you want to specify the table name, use
tidb-ctl schema in <database> -n <table name>
to filter.For example,
tidb-ctl schema in mysql -n db
returns the table schema of thedb
table in themysql
database:{ "id": 9, "name": { "O": "db", "L": "db" }, ... "Partition": null }
(The above output is also truncated.)
If you do not want to use the default TiDB service address and port, use the
--host
and--port
options to configure. For example,tidb-ctl --host 172.16.55.88 --port 8898 schema in mysql -n db
.
The tid
subcommand
tid
is used to obtain the table schema by using the unique table_id
in the whole database. You can use the in
subcommand to get all table IDs of certain schema and use the tid
subcommand to get the detailed table information.
For example, the table ID of mysql.stat_meta
is 21
. You can use tidb-ctl schema tid -i 21
to obtain the detail of mysql.stat_meta
.
{
"id": 21,
"name": {
"O": "stats_meta",
"L": "stats_meta"
},
"charset": "utf8mb4",
"collate": "utf8mb4_bin",
...
}
Like the in
subcommand, if you do not want to use the default TiDB service address and status port, use the --host
and --port
options to specify the host and port.
The base64decode
command
base64decode
is used to decode base64
data.
tidb-ctl base64decode [base64_data]
tidb-ctl base64decode [db_name.table_name] [base64_data]
tidb-ctl base64decode [table_id] [base64_data]
Execute the following SQL statement to prepare the environment:
use test; create table t (a int, b varchar(20),c datetime default current_timestamp , d timestamp default current_timestamp, unique index(a)); insert into t (a,b,c) values(1,"哈哈 hello",NULL); alter table t add column e varchar(20);
Obtian MVCC data using the HTTP API interface:
$ curl "http://$IP:10080/mvcc/index/test/t/a/1?a=1" { "info": { "writes": [ { "start_ts": 407306449994645510, "commit_ts": 407306449994645513, "short_value": "AAAAAAAAAAE=" # The unique index a stores the handle id of the corresponding row. } ] } }% $ curl "http://$IP:10080/mvcc/key/test/t/1" { "info": { "writes": [ { "start_ts": 407306588892692486, "commit_ts": 407306588892692489, "short_value": "CAIIAggEAhjlk4jlk4ggaGVsbG8IBgAICAmAgIDwjYuu0Rk=" # Row data that handle id is 1. } ] } }%
Decode
handle id (uint64) using `base64decode`
.$ tidb-ctl base64decode AAAAAAAAAAE= hex: 0000000000000001 uint64: 1
Decode row data using
base64decode
.$ ./tidb-ctl base64decode test.t CAIIAggEAhjlk4jlk4ggaGVsbG8IBgAICAmAgIDwjYuu0Rk= a: 1 b: 哈哈 hello c is NULL d: 2019-03-28 05:35:30 e not found in data # if the table id of test.t is 60, you can also use below command to do the same thing. $ ./tidb-ctl base64decode 60 CAIIAggEAhjlk4jlk4ggaGVsbG8IBgAICAmAgIDwjYuu0Rk= a: 1 b: 哈哈 hello c is NULL d: 2019-03-28 05:35:30 e not found in data
The decoder
command
The following example shows how to decode the row key, similar to decoding the index key.
$ ./tidb-ctl decoder "t\x00\x00\x00\x00\x00\x00\x00\x1c_r\x00\x00\x00\x00\x00\x00\x00\xfa" format: table_row table_id: -9223372036854775780 table_id: -9223372036854775780 row_id: -9223372036854775558 row_id: -9223372036854775558
The following example shows how to decode
value
.$ ./tidb-ctl decoder AhZoZWxsbyB3b3JsZAiAEA== format: index_value type: bigint, value: 1024 index_value[0]: {type: bytes, value: hello world} index_value[1]: {type: bigint, value: 1024}
The etcd
command
tidb-ctl etcd ddlinfo
is used to obtain DDL information.tidb-ctl etcd putkey KEY VALUE
is used to add KEY VALUE to etcd (All the KEYs are added to the/tidb/ddl/all_schema_versions/
directory).tidb-ctl etcd putkey "foo" "bar"
In fact, a key-value pair is added to the etcd whose KEY is
/tidb/ddl/all_schema_versions/foo
and VALUE isbar
.tidb-ctl etcd delkey
deletes the KEY in etcd. Only those KEYs with the/tidb/ddl/fg/owner/
or/tidb/ddl/all_schema_versions/
prefix can be deleted.tidb-ctl etcd delkey "/tidb/ddl/fg/owner/foo" tidb-ctl etcd delkey "/tidb/ddl/all_schema_versions/bar"
The log
command
The stack information for the TiDB error log is in one line format. You could use tidb-ctl log
to change its format to multiple lines.
The keyrange
command
The keyrange
subcommand is used to query the global or table-related key range information, which is output in the hexadecimal form.
Execute the
tidb-ctl keyrange
command to check the global key range information:tidb-ctl keyrange
global ranges: meta: (6d, 6e) table: (74, 75)
Add the
--encode
option to display encoded keys (in the same format as in TiKV and PD):tidb-ctl keyrange --encode
global ranges: meta: (6d00000000000000f8, 6e00000000000000f8) table: (7400000000000000f8, 7500000000000000f8)
Execute the
tidb-ctl keyrange --database={db} --table={tbl}
command to check the global and table-related key range information:tidb-ctl keyrange --database test --table ttt
global ranges: meta: (6d, 6e) table: (74, 75) table ttt ranges: (NOTE: key range might be changed after DDL) table: (74800000000000002f, 748000000000000030) table indexes: (74800000000000002f5f69, 74800000000000002f5f72) index c2: (74800000000000002f5f698000000000000001, 74800000000000002f5f698000000000000002) index c3: (74800000000000002f5f698000000000000002, 74800000000000002f5f698000000000000003) index c4: (74800000000000002f5f698000000000000003, 74800000000000002f5f698000000000000004) table rows: (74800000000000002f5f72, 748000000000000030)