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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 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 ,如需转载请自行联系原作者。
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
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/
|
SQL 关系型数据库 MySQL
解决:Mybatis-plus向数据库插入数据的时候 报You have an error in your SQL syntax
该博客文章讨论了在使用Mybatis-Plus向数据库插入数据时遇到的一个常见问题:SQL语法错误。作者发现错误是由于数据库字段中使用了MySQL的关键字,导致SQL语句执行失败。解决方法是将这些关键字替换为其他字段名称,以避免语法错误。文章通过截图展示了具体的操作步骤。
|
Java 数据库连接 Maven
文本,使用SpringBoot工程创建一个Mybatis-plus项目,Mybatis-plus在编写数据层接口,用extends BaseMapper<User>继承实体类
文本,使用SpringBoot工程创建一个Mybatis-plus项目,Mybatis-plus在编写数据层接口,用extends BaseMapper<User>继承实体类
|
XML Java 数据库连接
mybatis和mybatiplus中Error attempting to get column ‘xx‘ from result set
mybatis和mybatiplus中Error attempting to get column ‘xx‘ from result set
439 0
|
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
1442 1
|
Java 数据库连接 mybatis
Mybatis之Error building SqlSession.
Mybatis之Error building SqlSession.
751 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
|
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错误
声明:这个错误只是作者在学习时候的一种情况,并不一定能够解决所有情况。还望各位审视出错具体环境!谢谢。
587 0
Springboot mybatis逆向工程org.springframework.beans.factory.BeanCreationException: Error creating bean错误
|
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
1657 0