Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExce

2022/5/10 19:04:15

本文主要是介绍Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExce,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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



这篇关于Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExce的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程