全部
常见问题
产品动态
精选推荐

MyBatis连接MySql数据库对数据表进行操作时报错 Error updating database.

管理 管理 编辑 删除

【问题描述】

使用MyBatis对MySQL数据库中的数据表进行操作时出现“Error updating database.”报错。主要内容为:Error updating database.  Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

【问题详情】

### Error updating database.  Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
### The error may exist in com/mapper/UserMapper.xml
### The error may involve com.mapper.UserMapper.addUser
### The error occurred while executing an update
### Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	at com.service.impl.UserServiceImpl.addUser(UserServiceImpl.java:64)
	at test.Test.main(Test.java:11)
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:827)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:447)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:221)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:216)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:422)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
	... 3 more

【初步检查】

根据报错内容检查相应的UserMapper.xml文件的代码后,确定代码逻辑、语法无误。

【问题分析】

报错内容“Access denied for user 'root'@'localhost' (using password: YES)”表达的直接意思是:名为“root”的用户在“localhost”端口使用密码对数据库的访问被拒绝了。

初步猜想有两种情况导致:1.数据库服务未启动。    2.连接数据库的用户名或密码错误。

【解决方案】

1.使用管理员权限,通过命令提示符打开mysql数据库的服务。

2.使用管理员权限,通过命令提示符重置密码。

【执行解决方案1】

使用管理员权限运行命令提示符,在弹出的窗口输入:“net start mysql;”回车。启动数据库服务后,发现问题依然存在。

【执行解决方案2】

接下来重置数据库8.0.16的root密码。

【解决完成】

重置root密码后,按照新重置的密码编辑代码,连接数据库成功。

【总结】

本次问题的症结是:遗忘了数据库root密码,编辑代码时使用了错误的密码访问数据库,导致访问被拒绝。

CRMEB-慕白寒窗雪 最后编辑于2023-05-29 17:39:30

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} 作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
1609
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

CRMEB-慕白寒窗雪 作者
社区运营专员---高冷のBoy | 呆萌のGirl

回答

1102

发布

1750

经验

39820

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

快速安全登录

使用微信扫码登录

手机登录

{{codeText}}
{{isQrcode ? '手机登录' : '扫码登录'}}
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服