SQLServer数据通过java保存到MySQL中出现unicode编码问题

双数据源将sqlserver中的数据导出存入mysql时出现编码问题,SQLServer的字集为unicode,而需要在mysql中存入utf-8的字集。

 

通过配置application.properties文件,如下

#SQLServer数据库
spring.datasource.remote.url=jdbc:sqlserver://192.168.1.1:1433;DatabaseName=DatabaseName
spring.datasource.remote.username=sa
spring.datasource.remote.password=123456
spring.datasource.remote.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

#MySql数据库
spring.datasource.location.url=jdbc:mysql://192.168.1.2:3306/databasename2?useSSL=false&serverTimezone=UTC&useUnicode=yes&characterEncoding=utf-8&allowPublicKeyRetrieval=true
spring.datasource.location.username=root
spring.datasource.location.password=234567
spring.datasource.localtion.driver-class-name=com.mysql.jdbc.Driver

 

同时应更改mysql中表的编码

mysql>alter table tablename convert to character set utf8mb4 collate utf8mb4_unicode_ci;

修改数据库编码

mysql>alter database databasename character set utf8mb4 collate utf8mb4_unicode_ci;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值