D2RQ 的安装和基本使用

  本内容主要介绍 D2RQ 的安装,以及使用 D2RQ 将关系数据库转换为 RDF 文件。

1.1 工具安装

  在使用过程中,本人使用的工具对应版本号如下:

工具 版本号
D2RQ 0.8.1
MySQL 8.0.28.0
mysql-connector-java 5.1.44(mysql-connector-java-5.1.44.jar)

1.1.1 D2RQ 下载

  在 D2RQ 官网下载 d2rq-0.8.1.zip,然后将其解压。

1.1.2 下载 JDBC driver

  因为 D2RQ 需要与 Java、MySQL 进行联合应用,所以需要 JDBC driver。在其 官网 下载,本人使用的版本是 5.1.44。将下载的文件 mysql-connector-java-5.1.44.jar 复制到上一步 D2RQ 解压后的 lib 目录下。


1.2 生成映射文件

  生成映射文件的方法:首先打开 CMD,然后切换到 D2RQ 工具所在的目录,最后执行以下命令:

generate-mapping -u root -p XXX -o test.ttl jdbc:mysql:///test

注意:
-p 后面的 XXX 为 MySQL 的密码,如果没有密码,就不用输入。test.ttl 为生成的映射文件名。jdbc:mysql:///test 中的 test 为对应的 MySQL 数据库。

  但是在执行过程可能不会很顺利,会出现一些问题。

1.2.1 问题一

  首先,会出现以下错误

Wed Mar 16 10:55:37 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Database connection to jdbc:mysql:///test failed (user: root): Communications link failure

  解决方法:在上面的命令中添加 useSSL=false,即执行如下命令:

generate-mapping -u root -p 123456 -o test.ttl jdbc:mysql:///test?useSSL=false

1.2.2 问题二

  然后,会出现以下错误:

Database connection to jdbc:mysql:///test?useSSL=false failed (user: root): Unable to load authentication plugin 'caching_sha2_password'. (E54)

  问题原因:MySQL 8 之前的版本,默认加密规则为 mysql_native_password,但是从 MySQL 8 版本开始,默认的加密规则变更为 caching_sha2_password。但是客户端不支持新的加密规则。

  解决方法:将加密规则从 caching_sha2_password 修改为 mysql_native_password。具体步骤如下:

  • 打开 MySQL 8.0 Command Line Client
  • 输入密码,登录 MySQL。
  • 依次输入以下命令:
use mysql

alter user 'root'@'localhost' identified with mysql_native_password by 'XXX';

注意:

  • 上面的 XXX 为 MySQL 的密码。
  • 可以使用 select user,host,plugin,authentication_string from user; 命令查看,变更前后的加密方式。

1.3 将关系数据库转换为 RDF 文件

  在前面得到映射文件后,现在可以将关系数据库转换 RDF 文件。执行以下命令:

.\dump-rdf.bat -o test.nt .\test.ttl

注意:
其中 test.nt 为生成的 RDF 文件名,test.ttl 为上面生成的映射文件名。

  会出现以下错误:

        at d2rq.dump_rdf.run(dump_rdf.java:97)
        at de.fuberlin.wiwiss.d2rq.CommandLineTool.process(CommandLineTool.java:158)
        at d2rq.dump_rdf.main(dump_rdf.java:40)
Caused by: java.lang.IllegalArgumentException: Invalid version number: Version number may be negative or greater than 255
        at com.ibm.icu.util.VersionInfo.getInstance(VersionInfo.java:188)
        at com.ibm.icu.impl.ICUDebug.getInstanceLenient(ICUDebug.java:65)
        at com.ibm.icu.impl.ICUDebug.<clinit>(ICUDebug.java:69)

  问题原因:在旧版 ICU4J 中,VersionInfo 类将版本号限制为两个字符,即限制为 255 以内。当 Java 版本号中大于 255 时,就会出错,比如 1.8.0_321(321 大于 255)。

  解决方法
方法一:降低 Java 版本,即使用小于 255 的 Java 版本。
方法二:使用新版本的 ICU4J(需要 68.1 及以上版本)替换旧版本的 ICU4J。具体操作:将 .\d2rq-0.8.1\lib\arq-2.9 中的 icu4j-3.4.4.jar 删除,然后将下载的 icu4j-68_2.jar 复制进去。

  至此,我们就完成了将关系数据库转换为 RDF 文件的操作。

参考:

[1] D2RQ的下载和使用实例教程

[2] D2RQ安装与基本使用

[3] D2RQ问题总结

[4] mysql 无法连接 Unable to load authentication plugin ‘caching_sha2_password’.

[5] 连接MySQL报错Unable to load authentication plugin ‘caching_sha2_password’

[6] Invalid version number: Version number may be negative or greater than 255

猜你喜欢

转载自blog.csdn.net/benzhujie1245com/article/details/123519995