How TiDB Implements Operations Similar to Read-Only MySQL Replica

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: Tidb如何实现类似只读取mysql从库的操作

| username: Hacker_5dlWhpPx

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version] 5.0 and above
[Encountered Problem] Deadlocks occur during query and insert modifications. I want to achieve read-write separation, for example, in MySQL, you can read data only from the replica. Can using follower read achieve a similar effect?

| username: xfworld | Original post link

You can refer to this document:

Deadlock is a resource competition in business scenarios, and this requires considering a better solution. Relying on the database alone still cannot avoid it.

| username: Hacker_5dlWhpPx | Original post link

Thank you for your reply. According to the documentation, stale read is reading historical data. But I just want to simulate the operation similar to reading from a MySQL replica.
Or I won’t mention deadlocks. I just purely want to read replica data. Can it achieve a similar effect to reading from a MySQL replica?

| username: xfworld | Original post link

Yes, to fully simulate, you can set up TiCDC, then connect it to a MySQL or another complete set of TiDB, and it will work. :star_struck:

| username: Hacker_5dlWhpPx | Original post link

The cost is too high this way. Considering TiDB has replicas, I hope to only read data from the replicas.

| username: 特雷西-迈克-格雷迪 | Original post link

Is there a way to specify that SQL only reads the follow replica? I only know the implementation principle of follow read.

| username: Hacker_5dlWhpPx | Original post link

You’re right, I posted this to ask if there is such a method.

| username: yilong | Original post link

Is the learner’s approach feasible?

| username: Hacker_5dlWhpPx | Original post link

This is a product of a synchronous process, it won’t work, right?

| username: 张雨齐0720 | Original post link

It should be necessary to find a way to solve the cause of the deadlock. If it’s read-only, there might be issues with accuracy.

| username: wuxiangdong | Original post link

Try synchronizing data to MySQL with TiCDC, and use Atlas or Cetus for read-write separation.

| username: wuxiangdong | Original post link

The deadlock issue might be a problem with the program, and implementing read-write separation probably won’t solve it.