
19

mysql 分库分表
source link: https://www.80shihua.com/archives/2686
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

mysql 分库分表
mysql 分库分表
分库分表时机
当业务量小的时候,我们不需要去关注数据库存储的数据多少,当业务量大的时候,单个表的行数有几百万的时候,我们需要考虑分库分表。
- 根据业务增常量,推算出分库的片数
- 选出分表的关键字段作为分表key
- 根据具体的key选择分表算法是hash还是range
- 执行数据库双写将新的数据写入到新表和老表中
- 进行新表老表的数据比对,然后统一读写新表。
- 分库分表之后,需要注意使用分布式id,也就是全局id作为主键。
- 分页排序会跨库跨表,需要进行数据的分别查询汇总。
- 减少联合查询可以通过反范式进行冗余字段的设计
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK