• SpringBoot登陆Mysql密码设置的一坑(java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES))


    先说一下我的环境,

    Mysql版本:5.5.60 MySQL Community Server (GPL)

    SpringBoot:2.2.5.RELEASE

    YAML 配置:

    spring:
     datasource:
      username: root
      password: 000000
      #Mysql5: com.mysql.jdbc.Driver
      #Mysql6: com.mysql.cj.jdbc.Driver
      driver-class-name: com.mysql.cj.jdbc.Driver
      #Mysql5:jdbc:mysql://localhost:3306/fms?useUnicode=true&characterEncoding=utf8&useSSL=false
      #Mysql6:jdbc:mysql://localhost:3306/fms?serverTimezone=GMT%2B8&useSSL=false
      url: jdbc:mysql://localhost:3306/fms?serverTimezone=GMT%2B8&useSSL=false

    首先认为我的mysql安装的时5.X版本,驱动用的com.mysql.cj.jdbc.Drive,会不是因为这个原因造成的。

    连接url方式也换成了jdbc:mysql://localhost:3306/fms?useUnicode=true&characterEncoding=utf8&useSSL=false

    得知serverTimezone参数为Mysql6必须要配置的参数。

    这里我把com.mysql.jdbc.Driver和com.mysql.cj.jdbc.Driver两种方法全部试了一下,

    得到错误

    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

    于是开始质疑难道真的密码记错了。。。登陆mysql测试

     

     登陆测试完全OK,最终将Yaml配置文件密码改成"000000",加上引号作为一个字符串传递,成功!

    分析了一下原因,直接这样配置在登陆mysql时传入的字符是0

    spring:
     datasource:
      username: root
      password: 000000

    改为,作为字符串"000000"

    spring:
     datasource:
      username: root
      password: "000000"

    最终成功!

     

  • 相关阅读:
    Linux RAID部署
    系统运维架构师体系
    Linux系统上文件的特殊权限及文件acl
    Linux磁盘使用及文件系统管理
    中小规模网站架构组成
    优化配置模板主机
    网络原理基础
    MySQL二进制安装
    网络通讯基础
    点击改变背景
  • 原文地址:https://www.cnblogs.com/loyung/p/14084693.html
Copyright © 2020-2023  润新知