mysql cas字段_cas 持久化TGT到mysql JPA方式 增加自定义字段

springboot2.0配置多数据源:

spring.datasource.primary.url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true

spring.datasource.primary.username=root

spring.datasource.primary.password=root

spring.datasource.primary.driver-class=com.mysql.cj.jdbc.Driver

spring.datasource.secondary.url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true

spring.datasource.secondary.username=root

spring.datasource.secondary.password=root

spring.datasource.secondary.driver-class=com.mysql.cj.jdbc.Driver

改为:

spring.datasource.primary.jdbc-url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true

spring.datasource.primary.username=root

spring.datasource.primary.password=root

spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.secondary.jdbc-url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true

spring.datasource.secondary.username=root

spring.datasource.secondary.password=root

spring.datasource.secondary.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.url 数据库的 JDBC URL。

spring.datasource.jdbc-url 用来重写自定义连接池

官方文档的解释是:

因为连接池的实际类型没有被公开,所以在您的自定义数据源的元数据中没有生成密钥,而且在IDE中没有完成(因为DataSource接口没有暴露属性)。另外,如果您碰巧在类路径上有Hikari,那么这个基本设置就不起作用了,因为Hikari没有url属性(但是确实有一个jdbcUrl属性)。在这种情况下,您必须重写您的配置。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL DDL同步表相差字段可以使用以下步骤: 1. 使用SHOW CREATE TABLE语句获取源表和目标表的DDL语句。 2. 将两个DDL语句分别解析为字段列表。 3. 比较两个字段列表,找出相差的字段。 4. 使用ALTER TABLE语句将目标表添加缺失字段或删除多余字段。 下面是一个示例脚本,可以自动比较并同步两个表的DDL: ``` #!/bin/bash # source table src_table="source_table" src_db="source_database" # target table tgt_table="target_table" tgt_db="target_database" # get source table ddl src_ddl=$(echo "SHOW CREATE TABLE ${src_db}.${src_table}" | mysql | tail -n +2 | awk '{print $2}') # get target table ddl tgt_ddl=$(echo "SHOW CREATE TABLE ${tgt_db}.${tgt_table}" | mysql | tail -n +2 | awk '{print $2}') # parse source and target ddl into field lists src_fields=$(echo ${src_ddl} | awk -F"(" '{print $2}' | awk -F")" '{print $1}' | sed 's/ /\n/g' | sed '/^$/d') tgt_fields=$(echo ${tgt_ddl} | awk -F"(" '{print $2}' | awk -F")" '{print $1}' | sed 's/ /\n/g' | sed '/^$/d') # find missing fields in target table for field in ${src_fields} do if [[ ! ${tgt_fields} =~ ${field} ]] then echo "Adding field ${field} to ${tgt_db}.${tgt_table}..." alter_stmt="ALTER TABLE ${tgt_db}.${tgt_table} ADD COLUMN ${field} $(echo ${src_ddl} | grep ${field} | awk -F"${field} " '{print $2}' | sed 's/,//g')" echo ${alter_stmt} | mysql fi done # find extra fields in target table for field in ${tgt_fields} do if [[ ! ${src_fields} =~ ${field} ]] then echo "Dropping field ${field} from ${tgt_db}.${tgt_table}..." alter_stmt="ALTER TABLE ${tgt_db}.${tgt_table} DROP COLUMN ${field}" echo ${alter_stmt} | mysql fi done ``` 注意:这个脚本只能同步字段的添加和删除,不能处理字段顺序、类型、长度等的变化。如果需要完整的DDL同步功能,可以考虑使用开源工具如Liquibase或Flyway。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值