Springboot踩坑记录:“There was an unexpected error (type=Internal Server Error, status=500)“

问题描述

基于Springboot的代码,编写了一个数据库访问的接口,但是当通过链接访问时出现了以下错误:

在这里插入图片描述

查看IDEA中的错误信息,显示为:

Could not create connection to database server

以及

mysql.cj.exceptions.CJException: null, message from server: “Host ‘x‘ is not allowed to connect

原因分析及解决方案:

原因一:mysql版本与驱动版本不一致。
原因二:Thymeleaf报错。

在我的搜索过程中,许多博主对该问题进行了解释说明和解决,但在我的应用中,经过仔细检查,不存在该问题,故就此略过,如果存在该问题,可移步其他博文。

原因三:mysql权限问题。

此处参考了 https://blog.csdn.net/Gaozier/article/details/115515440 中对权限修改的方法,进入可以敲mysql语句的界面后,输入:

use mysql
update user set host = "%" where user="root";
flush privilege;

在这里插入图片描述

之后,在我的项目中出现了新的问题:Public Key Retrieval is not allowed.

继续查资料,参考这篇Mysql 8报错:Public Key Retrieval is not allowed(解决方式),其实就是在 application.yml 中数据库部分,添加public key的信息,如下代码中第四行url的最后,allowPublicKeyRetrieval=true

spring:
  datasource:
    name: test  # 数据库名称
    url: jdbc:mysql://127.0.0.1:13306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&useSSL=false&allowPublicKeyRetrieval=true
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
  redis:
    host: 127.0.0.1
    port: 16379
    password: 123456
    database: 0

然后就解决了!

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值