Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol

1. 环境:mysql 8.0.28、mysql驱动5.1.17

2. BUG描述:使用spark连接mysql出现错误

2.1 spark连接mysql语句

//TODO 创建SparkSQL的运行环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("sparkSQL")
    val spark = SparkSession.builder().config(sparkConf).getOrCreate()
    import spark.implicits._

    //读取MySQL数据
    val df = spark.read.format("jdbc")
      .option("url", "jdbc:mysql://localhost:3306/spark_sql?useSSL=false")
      .option("driver", "com.mysql.cj.jdbc.Driver")
      .option("user", "root")
      .option("password", "12345678")
      .option("dbtable", "user")
      .load()
      df.show

    //TODO 关闭环境
    spark.close()

2.2 BUG提示

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol 

3. 解决方法--更新mysql驱动的版本为8.0.11

posted @ 2022-05-09 11:17  递茶大户  阅读(133)  评论(0编辑  收藏  举报