TiDB speaks the MySQL 8.0 wire protocol. Your existing MySQL clients, drivers, and ORMs connect to TiDB the same way they connect to MySQL — same port, same authentication, same SQL syntax. Most applications can migrate with zero or minimal code changes.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pingcap/tidb/llms.txt
Use this file to discover all available pages before exploring further.
Connecting to TiDB
TiDB listens on port 4000 by default (configurable). You can also run it on the standard MySQL port 3306. Any MySQL client or driver works:mysql_native_password and caching_sha2_password.
ORM and framework compatibility
TiDB works with all major ORMs and frameworks that support MySQL 8.0.- Java
- Python
- Go
- Ruby
- Node.js
Supported SQL features
TiDB supports the vast majority of MySQL 8.0 SQL, including: DDL:CREATE/ALTER/DROP TABLE, ADD/DROP INDEX, ADD COLUMN, MODIFY COLUMN, RENAME TABLE, TRUNCATE, partitioning, views, generated columns.
DML: INSERT, UPDATE, DELETE, REPLACE, INSERT ... ON DUPLICATE KEY UPDATE, SELECT ... FOR UPDATE, SELECT ... FOR SHARE.
Data types: All MySQL numeric, string, date/time, JSON, and spatial types.
Functions: Most MySQL built-in functions, window functions, CTEs (WITH), JSON functions, and full-text search.
Stored procedures and triggers: Basic stored procedures, functions, and triggers are supported.
System variables: TiDB supports most MySQL system variables (@@global.*, @@session.*). Some variables are accepted for compatibility but have no effect because TiDB handles the underlying behavior differently.
Differences from MySQL
TiDB is not a drop-in replacement in every case. The following differences are the most commonly encountered.Foreign key enforcement
Foreign key enforcement
TiDB parses
FOREIGN KEY constraints but does not enforce them by default. Referential integrity must be maintained by the application or enforced with tidb_enable_foreign_key = ON (available in recent TiDB versions).AUTO_INCREMENT behavior
AUTO_INCREMENT behavior
TiDB’s
AUTO_INCREMENT allocates IDs in batches per TiDB server node to avoid a single-point bottleneck. This means:- IDs are guaranteed to be unique and monotonically increasing per node, but not globally monotonic across all nodes.
- Gaps in the sequence are possible when a batch is allocated but not fully consumed.
- If you need a globally monotonic sequence, use
AUTO_RANDOMinstead.
Some DDL behaviors
Some DDL behaviors
TiDB uses an online DDL mechanism similar to MySQL’s online DDL, but the implementation differs:
ALTER TABLEoperations that add columns are non-blocking and do not populate new column data immediately; the default value is returned at read time for existing rows.- Only one DDL owner processes DDL jobs cluster-wide; DDL operations are serialized per table (though different tables can be altered in parallel).
INSTANTalgorithm forADD COLUMNis supported.
Repeatable Read semantics
Repeatable Read semantics
TiDB’s Repeatable Read is implemented with MVCC snapshots rather than MySQL’s gap locks. As a result:
- Phantom reads are prevented within a snapshot, but via snapshot isolation rather than range locks.
SELECT ... FOR UPDATEreads the latest committed version of a row (not the transaction snapshot), which can differ from MySQL’s behavior in some edge cases.
Unsupported or partially supported features
Unsupported or partially supported features
The following features are not supported or only partially supported:
FULLTEXTindexes have limited support; consider using dedicated search solutions for production full-text search.GET_LOCK()/RELEASE_LOCK()advisory locks are supported.LOAD DATA INFILEis supported with some restrictions.CREATE TABLE ... SELECTis supported.- User-defined functions (UDFs) compiled as shared libraries are not supported.
XAtransactions have limited support.
Migrating from MySQL
Export your schema and data
Use
mysqldump or TiDB’s migration tool (Dumpling) to export your MySQL database.Verify compatibility
Run your application’s test suite against TiDB. Check for foreign key enforcement differences, AUTO_INCREMENT gaps, and any MySQL-specific syntax your application uses.
System variables
TiDB exposes its own configuration through session and global variables, using the sameSET/SHOW VARIABLES syntax as MySQL.