1.广播表用途
用于数据量不大且需要和很多表关联的表,例如字典表。
广播表需要建到所有数据库。
新增数据时会所有库中同步新增。
查询时从随机一个库中查询。
目的是方便和其他表做关联,减少跨库查询次数。
2.广播表配置
表名为dict,在所有数据库中创建dict表。
shardingsphereconf.yaml中添加:
...
rules:
...
- !BROADCAST
tables: # 广播表规则列表
- dict
...
...
官方文档:
https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/broadcast/
https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding/
3.打印sql
shardingsphereconf.yaml中添加:
...
props:
sql-show: true
...
官方文档:
https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/props/
4.参考代码
链接:https://pan.baidu.com/s/1oPBrqthEvgz3j6Z5yWrhMQ?pwd=1111
提取码:1111
需要用init.sql中语句建表,更换数据库链接和账号密码