Sign InTry Free

Developer Guide Overview

This guide is written for application developers, but if you are interested in the inner workings of TiDB or want to get involved in TiDB development, read the TiDB Kernel Development Guide for more information about TiDB.

This tutorial shows how to quickly build an application using TiDB, the possible use cases of TiDB and how to handle common problems.

Before reading this page, it is recommended that you read the Quick Start Guide for the TiDB Database Platform.

This tutorial shows how to quickly build an application using TiDB Cloud, the possible use cases of TiDB Cloud and how to handle common problems.

TiDB basics

Before you start working with TiDB, you need to understand some important mechanisms of how TiDB works:

TiDB transaction mechanisms

TiDB supports distributed transactions and offers both optimistic transaction and pessimistic transaction modes. The current version of TiDB uses the pessimistic transaction mode by default, which allows you to transact with TiDB as you would with a traditional monolithic database (for example, MySQL).

You can start a transaction using BEGIN, explicitly specify a pessimistic transaction using BEGIN PESSIMISTIC, or explicitly specify an optimistic transaction using BEGIN OPTIMISTIC. After that, you can either commit (COMMIT) or roll back (ROLLBACK) the transaction.

TiDB guarantees atomicity for all statements between the start of BEGIN and the end of COMMIT or ROLLBACK, that is, all statements that are executed during this period either succeed or fail as a whole. This is used to ensure data consistency you need for application development.

If you are not sure what an optimistic transaction is, do NOT use it yet. Because optimistic transactions require that the application can correctly handle all errors returned by the COMMIT statement. If you are not sure how your application handles them, use a pessimistic transaction instead.

If you are not sure what an optimistic transaction is, do NOT use it yet. Because optimistic transactions require that the application can correctly handle all errors returned by the COMMIT statement. If you are not sure how your application handles them, use a pessimistic transaction instead.

The way applications interact with TiDB

TiDB is highly compatible with the MySQL protocol and supports most MySQL syntax and features, so most MySQL connection libraries are compatible with TiDB. If your application framework or language does not have an official adaptation from PingCAP, it is recommended that you use MySQL's client libraries. More and more third-party libraries are actively supporting TiDB's different features.

Since TiDB is compatible with the MySQL protocol and MySQL syntax, most of the ORMs that support MySQL are also compatible with TiDB.

Read More

Download PDFRequest docs changes
Was this page helpful?
Open Source Ecosystem
TiDB
TiKV
TiSpark
Chaos Mesh
© 2022 PingCAP. All Rights Reserved.