mybatis connection error Cannot create PoolableConnectionFactory (Access denied for user 'root '@'local

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

rg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException:
Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))
### The error may exist in com/sample/mappers/EmployeeMapper.xml
### The error may involve com.sample.dao.EmployeeDao.listall
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException:
Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))

 

 

 

notice: the user is 'root ' not 'root'

这个问题大致就是需要检查你的数据源配置即Resource中的:url,username,password

url这个一般是"jdbc:mysql://localhost:3306/test",一定要注意3306,这个是你数据库连接用的端口,可以把它改成别的,但是如果你用的tomcat容器,别把它写成8080,这样就会产生Cannot create PoolableConnectionFactory (Communications link failure问题,还有就是url=jdbc:mysql://localhost:3306/test中的localhost,也不是随便配置的,要看你的数据库中的from host

我当时实在MySql Workbench5.2 CE中的 Users and Privileges中,有个Server Access Management

User  From Host 你看From Host中有没有localhost,如果有你就能写成url=jdbc:mysql://localhost:3306/test,要是from host有127.0.0.1的话,也可以写成url=jdbc:mysql://127.0.0.1:3306/test

还有就是 username=  这个一定要写正确,我当时写的是name= ,结果mysql找不到username,然后他自动把username设为"",以至于错误提示: java.sql.SQLException: Access denied for user ‘’ @'localhost' (using password: YES) 你看到@前面是两个单引号了吗,那就是我没输入username而导致默认的默认username,其实这个错误也可以用设置权限改,但是那是mysql内容,就不说了。

总结起来就是:url端口要写对,不能写其他程序被占用的,127.0.01还是localhost要看数据库里面有哪个,还要就是把对的驱动放入项目中的WEB-INF/lib里,这里提一下不用再放到tomcat的lib中。



本文转自hcy's workbench博客园博客,原文链接:http://www.cnblogs.com/alterhu/p/4471051.html ,如需转载请自行联系原作者。
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
SQL Java 数据库连接
Mybatis系列之 Error parsing SQL Mapper Configuration. Could not find resource com/zyz/mybatis/mapper/
文章讲述了在使用Mybatis时遇到的资源文件找不到的问题,并提供了通过修改Maven配置来解决资源文件编译到target目录下的方法。
Mybatis系列之 Error parsing SQL Mapper Configuration. Could not find resource com/zyz/mybatis/mapper/
|
2月前
|
SQL 关系型数据库 MySQL
解决:Mybatis-plus向数据库插入数据的时候 报You have an error in your SQL syntax
该博客文章讨论了在使用Mybatis-Plus向数据库插入数据时遇到的一个常见问题:SQL语法错误。作者发现错误是由于数据库字段中使用了MySQL的关键字,导致SQL语句执行失败。解决方法是将这些关键字替换为其他字段名称,以避免语法错误。文章通过截图展示了具体的操作步骤。
|
3月前
|
Java 数据库连接 Maven
文本,使用SpringBoot工程创建一个Mybatis-plus项目,Mybatis-plus在编写数据层接口,用extends BaseMapper<User>继承实体类
文本,使用SpringBoot工程创建一个Mybatis-plus项目,Mybatis-plus在编写数据层接口,用extends BaseMapper<User>继承实体类
|
5月前
|
XML Java 数据库连接
mybatis和mybatiplus中Error attempting to get column ‘xx‘ from result set
mybatis和mybatiplus中Error attempting to get column ‘xx‘ from result set
137 0
|
12月前
|
XML Java 数据库连接
MyBatis参数映射问题解决教程: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 wit
MyBatis参数映射问题解决教程: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 wit
847 1
|
Java 数据库连接 mybatis
Mybatis之Error building SqlSession.
Mybatis之Error building SqlSession.
502 0
|
SQL Java 数据库连接
Mybatis:Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource
Mybatis:Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource
|
SQL Java 关系型数据库
【已解决】Mybatis 批量动态更新数据时出现异常:java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax
【已解决】Mybatis 批量动态更新数据时出现异常:java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax
1191 0
|
Java 数据库连接 mybatis
idea Mybatis报错statement or DELIMITER expected, got ‘user‘
idea Mybatis报错statement or DELIMITER expected, got ‘user‘
idea Mybatis报错statement or DELIMITER expected, got ‘user‘
|
XML Java 关系型数据库
Springboot mybatis逆向工程org.springframework.beans.factory.BeanCreationException: Error creating bean错误
声明:这个错误只是作者在学习时候的一种情况,并不一定能够解决所有情况。还望各位审视出错具体环境!谢谢。
311 0
Springboot mybatis逆向工程org.springframework.beans.factory.BeanCreationException: Error creating bean错误