关于业务库从MySQL迁移到DM8的操作指南

升级前准备

jdbc:dm://10.252.10.15:5237
username: datashare
password: datashare123

把当前MySQL数据库下的数据库表以及数据迁移到DM8。通过达梦8自带的工具可以实现迁移(仅支持Win)

DM8管理工具下载:https://www.dameng.com/DM8.html

迁移数据参考博客:https://portal.s.au/clientarea.php?action=productdetails&id=1473863

注意:MySQL的DateTime类型到了DM8会自动转为Timestamp,要注意在同步的时候,配置表手动修改为DateTime

项目修改

  1. 新增Maven依赖

<dependency>
    <groupId>com.damenggroupId>
    <artifactId>DmJdbcDriver18artifactId>
    <version>8.1.2.192version>
dependency>


<dependency>
    <groupId>com.damenggroupId>
    <artifactId>DmDialect-for-hibernate5.3artifactId>
    <version>8.1.2.192version>
dependency>
  1. Nacos配置改成DM8数据源
primary: slave
slave:
  driver-class-name: dm.jdbc.driver.DmDriver
  url: jdbc:dm://10.252.10.15:5237?schema=ds_exchange
  username: datashare
  password: datashare123
  1. 在MybatisConfig类下新增Bean
@Bean
@ConditionalOnMissingBean
public DatabaseIdProvider getDatabaseIdProvider() {
    DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
    Properties p = new Properties();
    p.setProperty("DM DBMS", "dm");
    p.setProperty("MySQL", "mysql");
    databaseIdProvider.setProperties(p);
    return databaseIdProvider;
}
  1. Mapper.xml文件的SQL冗余两份,用databaseId隔离,后面上线如果遇到语法不兼容,可以直接修改在databaseId=dm的SQL

    例如:

    原来的:

   <select id="getDetailById" resultMap="syncJobWithFlowInfoMap">
        select j.id, j.owner_ids, j.owner_names, j.source_id, j.target_id, j.project_id, j.properties, j.xxl_job_info_id, j.remark, j.name, j.status, j.parent_id, j.ancestors, j.job_catalog_id, j.CREATE_TIME, j.MODIFY_TIME, j.CREATOR_ID, j.UPDATER_ID, f.name catalog_name
        from sync_job_info j left join sync_job_catalog f on f.id = j.job_catalog_id where j.delete_status=0 and j.id = #{id}
    select>

​ 修改后:

<select id="getDetailById" resultMap="syncJobWithFlowInfoMap" databaseId="mysql">
    select j.id, j.owner_ids, j.owner_names, j.source_id, j.target_id, j.project_id, j.properties, j.xxl_job_info_id, j.remark, j.name, j.status, j.parent_id, j.ancestors, j.job_catalog_id, j.CREATE_TIME, j.MODIFY_TIME, j.CREATOR_ID, j.UPDATER_ID, f.name catalog_name
    from sync_job_info j left join sync_job_catalog f on f.id = j.job_catalog_id where j.delete_status=0 and j.id = #{id}
select>

<select id="getDetailById" resultMap="syncJobWithFlowInfoMap" databaseId="dm">
    select j.id, j.owner_ids, j.owner_names, j.source_id, j.target_id, j.project_id, j.properties, j.xxl_job_info_id, j.remark, j.name, j.status, j.parent_id, j.ancestors, j.job_catalog_id, j.CREATE_TIME, j.MODIFY_TIME, j.CREATOR_ID, j.UPDATER_ID, f.name catalog_name
    from sync_job_info j left join sync_job_catalog f on f.id = j.job_catalog_id where j.delete_status=0 and j.id = #{id}
select>

问题总结

序号 问题 原因 解决方案 备注
1 生成id问题 dm不支持UUID 可使用sys_guid代替 例如:sys_guid AS bill_Id
2 求两个时间相差天数 dm不支持DATEDIFF 可使用BIGDATEDIFF代替 例如:BIGDATEDIFF(DAY,admission_time,discharge_time)
3 group by 关键字后面不能使用字段的别名 直接使用字段本身
4 group by 时 select 除了聚合字段和聚合参数,其他字段不允许查询 默认标准select限制 修改标准语法 例如:select type,count(id) from t_1 group by type
5 mysql中DATEDIFF和 dm中BIGDATEDIFF 参数位置位置相反 示例:
mysql :select DATEDIFF(discharge_time,admission_time) from drg_idl_performance_basic;
dm:select BIGDATEDIFF(DAY,admission_time,discharge_time) from drg_idl_performance_basic
6 表备份时,若表的主键是自增会报错 自增字段不能插入自己值 在复制表的创建sql语句中去掉“IDENTITY(1, 1)”,备份成功后再修改表主键为自增列
7 STR_TO_DATE()不支持 使用TO_DATE()代替 实例:TO_DATE( rysj,‘YYYYMMDD’) ;不支持%Y%m%d 写法
8 列长度超出定义 达梦数据库一个汉字占2个长度,mysql为1个 对于存储汉字的列,长度比mysql多定义一倍
9 DATE_SUB( now( ), INTERVAL 1 DAY ) dm中INTERVAL 1 DAY 需要给1加上‘1’才可以使用 DATE_SUB( now( ), INTERVAL ‘1’ DAY )
10 replace into 不支持 使用 merge into 代替

你可能感兴趣的:(mysql,数据库,达梦)