Thank you for the question, could you translate to English and send it
again?

------------------

Sincerely,
Liang Zhang (John)
Apache ShardingSphere


chenj...@ultrapower.com.cn <chenj...@ultrapower.com.cn> 于2023年7月13日周四
20:55写道:

>
> 您好:我现在需要通过shardingsphere-jdbc-core-spring-boot-starter:5.1.1实现读写分离,但是我遇到的问题如下:
> *场景介绍*:
>     现在项目有两台Mysql数据库,数据库关系为主备关系,每台数据库包含了多个逻辑库,为了缓解主库的压力,需要将部分查询负载到备库,因此选择使用
> shardingsphere-jdbc的读写分离功能。
> *问题*:
>     由于我的mysql包含多个逻辑库:
> ynemos_online、ynemos_test、ynemos_demo,在使用mybatis-plus查询时报错:
> org.apache.shardingsphere.infra.exception. Schema 'ynemos_online' doesn't
> exist.
> org.apache.shardingsphere.infra.exception. Schema 'ynemos_test' doesn't
> exist.
> *该问题需如何解决*
>
> mybatis-plus的Tablename 如下:
>
> *我的配置如下(数据源链接未指定逻辑库)*:
> # Shardingsphere配置
> spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
> spring.shardingsphere.datasource.names = master,slave
> spring.shardingsphere.mode.type = Memory
> # 主库数据源配置
> spring.shardingsphere.datasource.master.type =
> com.zaxxer.hikari.HikariDataSource
> spring.shardingsphere.datasource.master.driver-class-name =
> com.mysql.jdbc.Driver
> spring.shardingsphere.datasource.master.jdbc-url =
> *jdbc:mysql://address=(protocol=tcp)(host=10.173.101.245)(port=22306)?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true*
> spring.shardingsphere.datasource.master.username = root
> spring.shardingsphere.datasource.master.password = root
> # 从库数据源配置
> spring.shardingsphere.datasource.slave.type =
> com.zaxxer.hikari.HikariDataSource
> spring.shardingsphere.datasource.slave.driver-class-name =
> com.mysql.jdbc.Driver
> spring.shardingsphere.datasource.slave.jdbc-url =*
> jdbc:mysql://address=(protocol=tcp)(host=10.173.101.244)(port=22306)?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true*
> spring.shardingsphere.datasource.slave.username = root
> spring.shardingsphere.datasource.slave.password = root
>
> spring.shardingsphere.enabled = true
> spring.shardingsphere.rules.readwrite-splitting.data-sources.master-slave.type
> = Static
> spring.shardingsphere.rules.readwrite-splitting.data-sources.master-slave.props.auto-aware-data-source-name
> = *master*
> # 写数据源名称
> spring.shardingsphere.rules.readwrite-splitting.data-sources.master-slave.props.write-data-source-name
> = master
> # 读数据源名称,多个从数据源用逗号分隔
> spring.shardingsphere.rules.readwrite-splitting.data-sources.master-slave.props.read-data-source-names
> = slave
> # 数据库发现逻辑数据源名称
> spring.shardingsphere.rules.readwrite-splitting.data-sources.master-slave.dynamic-strategy.write-data-source-query-enabled
> = true
>
> spring.shardingsphere.props.sql-show = true
>
> ------------------------------
> chenj...@ultrapower.com.cn
>

Reply via email to