Heartsuit's Simple Blog

A place to hold mainly reading notes, and some technical stuff occasionally. 这里主要是一些读书笔记、感悟;还有部分技术相关的内容。


Project maintained by heartsuit Hosted on GitHub Pages — Theme by mattgraham

神通数据库ShenTong7在CentOS7上的安装与MySQL迁移遇到的兼容性问题

目录[-]

背景

最近接触了个项目,数据库用的是国产数据库:神通数据库 ShenTong7 。简单总结下 ShenTong7CentOS7 上的安装与使用。此外,在开发环境使用的是 MySQL 数据库,部署时需要迁移到神通数据库 ShenTong7 ,并且记录了在迁移过程中以及迁移之后遇到的问题及解决方法。

以下信息是在安装过程中关于神通数据库 ShenTong7 的官方介绍:

神通数据库是天津神舟通用数据技术有限公司(以下简称“神舟通用公司”)拥有自主知识产权的企业级、大型通用关系型数据库管理系统, 是神舟通用公司多年的大型数据库领域研发积累和深厚的航天信息化建设经验的集中体现,也是国家“核高基”重大专项、国家“863”计划大力支持基础软件领域发展所取得的一项重要成果。

神通数据库的研发得到了国家发改委、国家科技部、工信部、国防科工委以及中国航天科技集团公司的大力支持,在国产数据库中居于领先水平,获得了国家版权局颁发的16项计算机软件著作权证书,申报了32项并获得了14项数据库技术发明专利,入选了国家火炬计划和信息产业部博望计划。神通数据库获得国家核高基科技重大专项的重点支持,在国家主管部门组织的专家评审和产品测评中综合排名第一。

神通数据库采用关系数据模型作为核心数据模型,支持SQL通用数据库查询语言,提供标准的ODBC、JDBC、OLEDB/ADO和. Net DataProvider等数据访问接口,并具有海量数据管理和大规模并发处理能力。系统功能完善、性能稳定,可广泛应用于各类企事业单位、政府机关的信息化建设。

安装准备

登录并下载神通数据库V7.0,这里选用试用版下载。

2022-10-24-DownloadShenTong7.jpg

# 先下载rar解压缩软件
[root@hadoop5 opt]# wget https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz --no-check-certificate
--2022-10-20 06:20:07--  https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz
正在解析主机 www.rarlab.com (www.rarlab.com)... 51.195.68.162
正在连接 www.rarlab.com (www.rarlab.com)|51.195.68.162|:443... 已连接。
警告: 无法验证 www.rarlab.com 的由 “/C=US/O=Let\'s Encrypt/CN=R3” 颁发的证书:
  颁发的证书已经过期。
已发出 HTTP 请求,正在等待回应... 200 
长度:604520 (590K) [application/x-gzip]
正在保存至: “rarlinux-x64-612.tar.gz”

100%[============================================================================================>] 604,520     60.0KB/s 用时 9.9s   

2022-10-20 06:20:18 (59.9 KB/s) - 已保存 “rarlinux-x64-612.tar.gz” [604520/604520])

# tar 解压
[root@hadoop5 opt]# tar -xzpvf rarlinux-x64-612.tar.gz 
rar/
rar/unrar
rar/acknow.txt
rar/whatsnew.txt
rar/order.htm
rar/readme.txt
rar/rar.txt
rar/makefile
rar/default.sfx
rar/rar
rar/rarfiles.lst
rar/license.txt

# 进入rar目录、构建
[root@hadoop5 opt]# cd rar
[root@hadoop5 rar]# make
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
cp rar unrar /usr/local/bin
cp rarfiles.lst /etc
cp default.sfx /usr/local/lib

控制台安装

作为服务器,为了节约系统资源,我们一般都不采用图形化界面的安装方式。凭借控制台交互方式指定数据库的安装路径与默认库名。这对于无特殊需求的用户或要求服务器内没有图形化功能时是很有用的。

# rar 解压神通数据库压缩包
[root@hadoop5 opt]# rar x ShenTong7.0_linux64.rar

[root@hadoop5 opt]# cd ShenTong7.0_linux64

# 增加执行权限
[root@hadoop5 ShenTong7.0_linux64]# chmod +x setup

# 使用控制台方式安装
[root@hadoop5 ShenTong7.0_linux64]# ./setup -console
Command line arguments: -console 
Select your language
0  [x] chn
1  [ ] eng
Input selection: 

神通数据库简介

略……

Press 1 to continue, 2 to quit, 3 to redisplay
1
神通数据库管理系统软件许可协议

软件许可协议("SLA")

略……

天津神舟通用数据技术有限公司 2019版权所有(c)。保留所有权利。

Press 1 to accept, 2 to reject, 3 to redisplay
1
选择安装路径 : [/opt/ShenTong] 

------------------------
警告!

目标目录将创建在 :
/opt/ShenTong
------------------------
Enter O for OK, C to Cancel: 
O

Press 1 to continue, 2 to quit, 3 to redisplay
1
----
full
----
Enter Y for Yes, N for No: 
Y
minimum Not Selected
option Not Selected
Done!

Press 1 to continue, 2 to quit, 3 to redisplay
1
您可以选择是否立即设置agent密码
0  [x] 不需要设置密码(使用默认密码)
1  [ ] 请输入agent密码
Input selection: 

Press 1 to continue, 2 to quit, 3 to redisplay
1
您可以选择是否注册HA服务
0  [x] 否
1  [ ] 是
Input selection: 
0

Press 1 to continue, 2 to quit, 3 to redisplay
1
您可以选择jre的版本
0  [x] jre1.8
1  [ ] jre1.6
Input selection: 
0

Press 1 to continue, 2 to quit, 3 to redisplay
1
------
创建快捷方式
------
Enter Y for Yes, N for No: 
Y
---------
在桌面创建快捷方式
---------
Enter Y for Yes, N for No: 
N
------------
创建快捷方式: 所有用户
------------
Enter Y for Yes, N for No: 
N
whether create db
0  [x] 不需要创建数据库
1  [ ] 需要创建数据库
Input selection: 

Press 1 to continue, 2 to quit, 3 to redisplay
1
====================
Installation started
Framework: 5.1.4-SNAPSHOT-9ce6b (IzPack)
Platform: linux,version=3.10.0-1127.el7.x86_64,arch=x64,symbolicName=null,javaVersion=1.8.0_181
[ Starting to unpack ]
[ Processing package:  (1/48) ]
[ Processing package: 神通数据库服务器端 (2/48) ]
[ Processing package: 神通数据库客户端 (3/48) ]
[ Processing package: 神通数据库驱动程序 (4/48) ]
[ Processing package: 神通数据库帮助 (5/48) ]
[ Processing package:  (6/48) ]
[ Processing package:  (7/48) ]
[ Processing package: stpython驱动 (8/48) ]
[ Processing package: ACCI驱动 (9/48) ]
[ Processing package: 全文索引组件 (10/48) ]
[ Processing package: Isql交互终端 (11/48) ]
[ Processing package: 神通数据库帮助手册 (12/48) ]
[ Processing package: DBA管理工具 (13/48) ]
[ Processing package: 数据库维护工具 (14/48) ]
[ Processing package: ODBC驱动 (15/48) ]
[ Processing package: 神通数据库工作台 (16/48) ]
[ Processing package: 策略管理工具 (17/48) ]
[ Processing package: 数据库配置工具 (18/48) ]
[ Processing package: datamigrate工具 (19/48) ]
[ Processing package: 同步工具 (20/48) ]
[ Processing package: PHP驱动 (21/48) ]
[ Processing package: Hibernate方言包 (22/48) ]
[ Processing package: ESQL驱动 (23/48) ]
[ Processing package: 神通数据库后台 (24/48) ]
[ Processing package:  (25/48) ]
[ Processing package: 逻辑备份恢复工具 (26/48) ]
[ Processing package: cdc驱动 (27/48) ]
[ Processing package:  (28/48) ]
[ Processing package: SQL交互工具 (29/48) ]
[ Processing package: 神通数据库agent服务 (30/48) ]
[ Processing package: OscarHA (31/48) ]
[ Processing package: 运行时诊断工具 (32/48) ]
[ Processing package: ACI驱动 (33/48) ]
[ Processing package: 参数配置工具 (34/48) ]
[ Processing package: ORACLE导入导出工具 (35/48) ]
[ Processing package: JDBC驱动 (36/48) ]
[ Processing package:  (37/48) ]
[ Processing package:  (38/48) ]
[ Processing package: 审计工具 (39/48) ]
[ Processing package:  (40/48) ]
[ Processing package: 升级工具 (41/48) ]
[ Processing package: 跨平台迁移工具 (42/48) ]
[ Processing package:  (43/48) ]
[ Processing package:  (44/48) ]
[ Processing package:  (45/48) ]
[ Processing package:  (46/48) ]
[ Processing package:  (47/48) ]
[ Processing package:  (48/48) ]
[ Unpacking finished ]
Installation finished
Installation was successful
Application installed on /opt/ShenTong
[ Writing the uninstaller data ... ]
[ Console installation done ]

创建数据库

由于前面安装过程中我并没有创建数据库,导致当前并没有实例在运行。

# 一开始list database命令报错
[root@hadoop5 init.d]# oscar -e "list database"
-bash: oscar: 未找到命令

# 重新加载
[root@hadoop5 init.d]# source /etc/profile

# 再次执行list database,结果为0,表明没有数据库
[root@hadoop5 init.d]# oscar -e "list database"
(total number 0)

# 连接数据库服务器
[root@hadoop5 init.d]# oscar

# 创建数据库TPXT
backend> create database TPXT encoding'utf-8'; 
/*Session 0*/ LOG, instance recovery... 1: start log analyze RestartLSN: 0
/*Session 0*/ LOG, instance recovery... 1: finish log analyze, waste 0(S)

/*Session 0*/ LOG, instance recovery... 2: start prefetch dirty pages... 
/*Session 0*/ LOG, instance recovery... 2: prefetch dirty page count: 0
/*Session 0*/ LOG, instance recovery... 2: finish prefetch dirty pages, waste 0(S)

/*Session 0*/ LOG, instance recovery... 3: start redo, RedoStartLsn: 0
/*Session 0*/ LOG, instance recovery... 3: finish redo, waste 0(S) RedoEndLsn: 0

/*Session 0*/ NOTICE, 添加数据文件TPXT01.dbf成功
/*Session 0*/ NOTICE, 添加数据文件undots01.dbf成功
/*Session 0*/ NOTICE, 添加数据文件TPXTtmp01.dbf成功
/*Session 0*/ NOTICE, 添加数据文件TPXTaux01.dbf成功
/*Session 0*/ NOTICE, 开始进行系统表的初始化..

# 安装服务
[root@hadoop5 init.d]# oscar -o install -d TPXT
Created symlink from /etc/systemd/system/graphical.target.wants/oscardb_TPXTd.service to /usr/lib/systemd/system/oscardb_TPXTd.service.
service type : systemctl
Database service was successfully installed!
[root@hadoop5 init.d]# oscar -o restrict -d TPXT

# 启动数据库实例服务
[root@hadoop5 init.d]# /etc/init.d/oscardb_TPXTd start
Starting oscar -o normal -d TPXT:
Database TPXT startup success

查看版本

数据库安装、启动成功后,可以通过神通自带的数据库管理系统(我们是在 Windows 系统单独安装)或者第三方 GUI 可视化工具进行远程连接,执行 SELECT VERSION(); 查看数据库版本信息。

SELECT VERSION(); 
神通数据库7.0.8.191204 for Linux(x86 64bit) (200 connections) (license invalid after 90 days)

GUI可视化远程连接

第三方 GUI 可视化工具可通过 DBeaverIDEA 实现,可以参考人大金仓数据库Kingbase8在CentOS7上的安装与使用中关于客户端工具的使用。

数据迁移

可以使用神通自带的数据迁移工具将开发环境下的 MySQL 数据迁移到实际部署的神通数据库 ShenTong7 ,迁移工具的使用我这里就不做介绍了,用起来比较简单。现在对迁移过程中遇到的问题做个记录。

反引号“`”报错问题

解决方案:去掉 SQL 语句中的反引号,在下面的示例代码中是 query

	<sql id="selectMenuVo">
        select menu_id, menu_name, parent_id, order_num, path, component, `query`, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time 
		from sys_menu
    </sql>

Blob类型改为Clob类型后SQL语句报错

解决方案:代码中的 cast 函数去掉。

    <sql id="selectNoticeVo">
        select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark 
		from sys_notice
    </sql>

系统报错数据库中的FIND_IN_SET函数作为WHERE条件的问题

我记得之前做 MySQL 向达梦数据库迁移时,遇到过 FIND_IN_SET 函数不存在的问题;在神通数据库 ShenTong7 中是有 FIND_IN_SET 这个函数的,不过需要注意 FIND_IN_SET 函数作为 WHERE 条件的写法。错误信息如下:

Error querying database. Cause: com.oscar.util.OSQLException: ERROR, type conversion errors, Argument of WHERE must be type boolean, not type numeric ### The error may exist in URL [jar:file:/data/db/TongWeb7.0/deployment/vote-admin/WEB-INF/lib/vote-system-1.0.0.jar!/mapper/system/SysUserMapper.xml] ### The error may involve com.yjy.system.mapper.SysUserMapper.selectUserList-Inline ### The error occurred while setting parameters ### SQL: SELECT count(0) FROM sys_user u LEFT JOIN sys_dept d ON u.dept_id = d.dept_id WHERE u.del_flag = '0' AND (u.dept_id = ? OR u.dept_id IN (SELECT t.dept_id FROM sys_dept t WHERE find_in_set(?, ancestors))) ### Cause: com.oscar.util.OSQLException: ERROR, type conversion errors, Argument of WHERE must be type boolean, not type numeric ; ERROR, type conversion errors, Argument of WHERE must be type boolean, not type numeric ; nested exception is com.oscar.util.OSQLException: ERROR, type conversion errors, Argument of WHERE must be type boolean, not type numeric 

MySQL 中以下两条 SQL 语句是等价的,即 MySQL 会帮我们将 WHERE 条件的非0值隐式转换为布尔值 true ,可到了神通数据库 ShenTong7 中就没人帮我们转换了。

select * from sys_dept where find_in_set(100, ancestors);

select * from sys_dept where find_in_set(100, ancestors) > 0;

解决方案:在神通数据库 ShenTong7 中, FIND_IN_SET 函数作为 WHERE 条件时,需要把条件安装正常人的逻辑写完整即可: select * from sys_dept where find_in_set(100, ancestors) > 0;

小总结

关于神通数据库 ShenTong7 的参考资料建议参考官方文档。

其实,如果在安装神通数据库 ShenTong7 中时,我们会看到在安装目录下有一些文档,可以作为第一手的参考资料。


If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!


「说点什么吧😊~~😊」: