Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[Mycat] Primary key id self-growing configuration

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In the case of sub-database and sub-table, the database self-increasing primary key can no longer guarantee the global uniqueness of the self-increasing primary key. For this reason, MyCat provides global sequence, and provides a variety of implementation methods, including local configuration and database configuration, mainly in three ways: local file mode, database mode, local timestamp algorithm.

This paper mainly introduces the way of database.

1. Look at the configuration file as follows: rule= "sharding-by-intfile" / >

Configure Server.xml

Mysql > insert into employee (id,name,sharding_id) values (91J 123m 10010)

Query OK, 1 row affected (0.12 sec)

Mysql > select * from employee

+-- +

| | id | name | sharding_id | |

+-- +

| | 91 | 123 | 10000 | |

| | 92 | 123 | 10000 | |

| | 93 | 123 | 10010 | |

| | 94 | 123 | 10010 | |

| | 91 | 123 | 10010 | |

+-- +

4 rows in set (0.01sec)

The summary is as follows:

The original id=current_value+increment, continue to insert if the id has been

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report