无法使用 Scala 在 Spark 中使用 JDBC 连接到数据库
Unable to connect to a database using JDBC within Spark with Scala
我正在尝试从 Spark Scala 中的 JDBC 读取数据。下面是用Databricks写的代码。
val df = spark
.read
.format("jdbc")
.option("url", <connection-string>)
.option("dbtable", <table-name>)
.option("user", <username>)
.option("password", <password>)
.option("ssl", True)
.option("sslmode", "require")
.load()
我收到以下错误消息:
java.sql.SQLNonTransientConnectionException: Could not connect to 10.6.8.86:3306 : PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
谁能告诉我如何解决这个问题。
java 不信任您的主机使用的证书。
方案一(简单,不推荐)
禁用证书检查并始终信任服务器提供的证书。
添加trustServerCertificate
属性.
val df = (spark
.read
.format("jdbc")
.option("url", <connection-string>)
.option("dbtable", <table-name>)
.option("user", <username>)
.option("password", <password>)
.option("ssl", True)
.option("trustServerCertificate", True)
.option("sslmode", "require")
.load()
方案二(难,推荐)
获取证书并将其存储在系统的受信任存储中。
在此处阅读更多相关信息
- https://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed/
- "PKIX path building failed" and "unable to find valid certification path to requested target"
我正在尝试从 Spark Scala 中的 JDBC 读取数据。下面是用Databricks写的代码。
val df = spark
.read
.format("jdbc")
.option("url", <connection-string>)
.option("dbtable", <table-name>)
.option("user", <username>)
.option("password", <password>)
.option("ssl", True)
.option("sslmode", "require")
.load()
我收到以下错误消息:
java.sql.SQLNonTransientConnectionException: Could not connect to 10.6.8.86:3306 : PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
谁能告诉我如何解决这个问题。
java 不信任您的主机使用的证书。
方案一(简单,不推荐)
禁用证书检查并始终信任服务器提供的证书。
添加trustServerCertificate
属性.
val df = (spark
.read
.format("jdbc")
.option("url", <connection-string>)
.option("dbtable", <table-name>)
.option("user", <username>)
.option("password", <password>)
.option("ssl", True)
.option("trustServerCertificate", True)
.option("sslmode", "require")
.load()
方案二(难,推荐)
获取证书并将其存储在系统的受信任存储中。
在此处阅读更多相关信息
- https://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed/
- "PKIX path building failed" and "unable to find valid certification path to requested target"