一、问题说明

最近在学习springboot实现ssm框架的搭建,跟踪B站的视频学习,然而框架搭建好了之后程序访问数据库出现了Access denied for user ‘’@‘localhost’ (using password: NO) 无法获取什么username和password的问题,百度发现说是什么权限问题,但自己的数据库其他项目都可以用的,不应该是权限问题。
在这里插入图片描述
最后看到一篇CSDN博客说的是配置文件的问题,然后问题解决了。

二、问题处理

2.1 程序原配置

在这里插入图片描述

2.2 改过后的配置

在这里插入图片描述
修改前后的唯一区别是:

修改前 修改后
spring.datasource.data_password=123456 spring.datasource.password=123456
spring.datasource.data_username=root spring.datasource.username=root

其实出现这样的错误是使用idea自动提示的,错误的与正常非常相似,而且错误的先弹出来,直接选择错误了,所以就出现了“Access denied for user ‘’@‘localhost’ (using password: NO)”,其实最关键的还是没有完全理解配置文件的编写。

通过修改后,程序问题排查。

三、问题分析

在这里,我们需求深入理解下data_username/data_password与username/data_username的区别。

分析springboot:配置属性之DataSource,上面发生错误的内容都是DataSource的属性。
下面我们将一一说明各个属性的意思,进而理解错误的原因。

属性 说明
spring.datasource.username 指定数据库名
spring.datasource.password 指定数据库密码
spring.datasource.data-username Username of the database to execute DML scripts(if different)
spring.datasource.data-password Password of the database to execute DML scripts (if different).

参考:
https://blog.csdn.net/weixin_41507991/article/details/80242611
https://blog.csdn.net/weixin_38750084/article/details/88549515

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐