8baba opened a new issue, #28900:
URL: https://github.com/apache/shardingsphere/issues/28900
## Question
I want to use flyway to manage the database version, I want to use the data
source of shardingjdbc, but I encounter various problems when I start, please
help me look at this problem.
### dependencies version:
shardingsphere-jdbc-core-spring-boot-starter:5.1.1
flyway-core:8.5.13
flyway-mysql:8.5.13
mysql-connector-j:8.0.33
jdk8
### application.yaml
``` yaml
spring:
autoconfigure:
exclude:
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
shardingsphere:
enabled: true
datasource:
schema:
name: store
names: store
store:
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
username: root
password: root
url:
jdbc:mysql://pigx-mysql:3306/store?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
props:
sql-show: true
rules:
sharding:
sharding-algorithms:
table-inline:
props:
algorithm-expression: store_$->{tenant_id}
type: INLINE
tables:
version:
actual-data-nodes: store.t_version
table-strategy:
none:
store:
actual-data-nodes: store.store_1716476137853374465,
store.store_1717116448820633602
table-strategy:
standard:
sharding-algorithm-name: table-inline
sharding-column: tenant_id
## flyway ---------------------------------
flyway:
enabled: true
baseline-on-migrate: true
clean-disabled: false
out-of-order: true
```
### The following exception is displayed when the startup is displayed

``` java
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'flywayInitializer' defined in class path
resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed;
nested exception is org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to check whether schema `store` exists
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable
to check whether schema `store` exists
Caused by: java.sql.SQLSyntaxErrorException: Table 'store.schemata' doesn't
exist
at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
~[mysql-connector-j-8.0.33.jar:8.0.33]
```
#### SQL execution logs

``` sql
Logic SQL: SELECT COUNT(1) FROM information_schema.schemata WHERE
schema_name=? LIMIT 1
Actual SQL: store ::: SELECT COUNT(1) FROM schemata WHERE schema_name=?
LIMIT 1 ::: [store]
```
shardingjdbc routes SQL statements to the `store` database
So I added the information_schema to the data source, and configured it as
follows
```yaml
datasource:
names: store, information_schema
....
information_schema:
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
username: root
password: root
url: jdbc:mysql://pigx-mysql:3306/information_schema
...
rules:
...
sharding:
tables:
schemata:
actual-data-nodes: information_schema.schemata
table-strategy:
none:
tables:
actual-data-nodes: information_schema.tables
table-strategy:
none:
...
```
### The following is the startup execution log
``` java
Sql log:
Logic SQL: SELECT COUNT(1) FROM information_schema.schemata WHERE
schema_name=? LIMIT 1
Actual SQL: information_schema ::: SELECT COUNT(1) FROM schemata WHERE
schema_name=? LIMIT 1 ::: [store]
Exception information:
2023-10-30 22:36:40.986 WARN 23832 --- [ main]
s.c.a.AnnotationConfigApplicationContext : Exception encountered during context
initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'flywayInitializer' defined in class path resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is
org.apache.shardingsphere.infra.exception.SchemaNotExistedException: Schema
'store' doesn't exist.
....
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'flywayInitializer' defined in class path resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is
org.apache.shardingsphere.infra.exception.SchemaNotExistedException: Schema
'store' doesn't exist.
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
~[spring-beans-5.3.30.jar:5.3.30]
....
Caused by:
org.apache.shardingsphere.infra.exception.SchemaNotExistedException: Schema
'store' doesn't exist.
at
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.getSchema(SelectStatementContext.java:138)
~[shardingsphere-infra-binder-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.<init>(SelectStatementContext.java:111)
~[shardingsphere-infra-binder-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.infra.binder.SQLStatementContextFactory.getDMLStatementContext(SQLStatementContextFactory.java:146)
~[shardingsphere-infra-binder-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.infra.binder.SQLStatementContextFactory.newInstance(SQLStatementContextFactory.java:129)
~[shardingsphere-infra-binder-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.infra.binder.SQLStatementContextFactory.newInstance(SQLStatementContextFactory.java:114)
~[shardingsphere-infra-binder-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:181)
~[shardingsphere-jdbc-core-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:149)
~[shardingsphere-jdbc-core-5.1.1.jar:5.1.1]
at
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection.prepareStatement(ShardingSphereConnection.java:80)
~[shardingsphere-jdbc-core-5.1.1.jar:5.1.1]
at
org.flywaydb.core.internal.jdbc.JdbcTemplate.prepareStatement(JdbcTemplate.java:300)
~[flyway-core-8.5.13.jar:na]
at
org.flywaydb.core.internal.jdbc.JdbcTemplate.query(JdbcTemplate.java:339)
~[flyway-core-8.5.13.jar:na]
....
```
### shardingjdbc can't find the schema for the store, the break point is
only the schema of the logic_db, please teach how to solve this problem
## The git address of the project
https://github.com/8baba/flyway-shardingjdbc-test
## How will I properly use Flyway to manage the database? Thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]