数据库
首页 > 数据库> > Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExce

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,jdbc,jdbc4,option,val,mysql,spark,com
来源: https://www.cnblogs.com/sam0/p/16248483.html