双数据源将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;