Spark SQL错误提示(useSSL=false 和 Access denied for user ‘root‘@‘localhost‘ (using password: YES) )
Posted Mr.zhou_Zxy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spark SQL错误提示(useSSL=false 和 Access denied for user ‘root‘@‘localhost‘ (using password: YES) )相关的知识,希望对你有一定的参考价值。
Spark SQL错误提示(You need … setting useSSL=false, or set useSSL=true… 和Exception in thread “main” java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES) )
- 错误运行结果
- 执行代码
package com.zxy.spark.sql.Day01
import java.util.Properties
import com.zxy.spark.core.Day02.SparkUtils
import org.apache.spark.sql.{DataFrame, SparkSession}
object Demo12_DataLoad_mysql {
def main(args: Array[String]): Unit = {
val spark: SparkSession = SparkUtils.getDefaultSparkSession()
import spark.implicits._
val url = "jdbc:mysql://localhost:3306/zxy?useUnicode=true&characterEncoding=utf8"
val table = "users"
val properties = new Properties()
properties.setProperty("user","root")
properties.setProperty("password","111213")
val df: DataFrame = spark.read.jdbc(url,table,properties)
df.show()
spark.close()
}
}
- 错误1分析
Tue Jun 15 19:03:45 CST 2021 WARN: Establishing SSL connection without server’s identity verification is not recommended.
不建议在没有服务器身份验证的情况下建立SSL连接。
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.
MySQL 5.5.45+、5.6.26+和5.7.6+要求如果没有设置显式选项,则默认需要建立SSL连接。
For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’.
为了符合未使用SSL的现有应用程序,verifyServerCertificate属性被设置为“false”。
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任库。
val url = “jdbc:mysql://localhost:3306/zxy?useUnicode=true&characterEncoding=utf8&useSSL=false”
- 错误2分析
Exception in thread “main” java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
通过多次校验,发现自己的连接密码写错
- 成功代码
package com.zxy.spark.sql.Day01
import java.util.Properties
import com.zxy.spark.core.Day02.SparkUtils
import org.apache.spark.sql.{DataFrame, SparkSession}
object Demo12_DataLoad_mysql {
def main(args: Array[String]): Unit = {
val spark: SparkSession = SparkUtils.getDefaultSparkSession()
import spark.implicits._
val url = "jdbc:mysql://localhost:3306/zxy?useUnicode=true&characterEncoding=utf8&useSSL=false"
val table = "users"
val properties = new Properties()
properties.setProperty("user","root")
properties.setProperty("password","root")
val df: DataFrame = spark.read.jdbc(url,table,properties)
df.show()
spark.close()
}
}
- 成功页面
以上是关于Spark SQL错误提示(useSSL=false 和 Access denied for user ‘root‘@‘localhost‘ (using password: YES) )的主要内容,如果未能解决你的问题,请参考以下文章
JDBC——setting useSSL=false, or set useSSL=true
SpringBoot整合spark_sql:报错解决java.lang.NoClassDefFoundError: org/codehaus/janino/InternalCompilerExcept