JDBC Hibernate - Mysql连接错误 [英] JDBC Hibernate - Mysql Connection Error
问题描述
我的Ubuntu 11.10桌面上有一个本地mysql服务器。 hostname = localhost; username = root;密码= root;数据库名称= CBS。我真的很困惑,因为当我使用终端
, mysql管理员
和 mysql查询访问mysql时浏览器
我使用上面提到的那些身份验证,一切正常。我的问题是当我在Java App中配置我的jdbc.properties时出现此错误:
I have a local mysql server on my Ubuntu 11.10 desktop. The hostname = localhost; username = root; password = root; database name = CBS. I am really confused because when I access mysql using terminal
, mysql administrator
, and mysql query browser
I use those authentication I mentioned above and everything is OK. My problem is when I configure my jdbc.properties in my Java App I'm getting this error:
org.springframework.web.util .NestedServletException:请求处理失败;嵌套异常是org.springframework.jdbc.UncategorizedSQLException:Hibernate操作:无法打开连接;未分类的SQL的SQLException [???]; SQL状态[28000];错误代码[1045];用户'root'@'localhost'访问被拒绝(使用密码:YES);嵌套异常是java.sql.SQLException:用户'root'@'localhost'拒绝访问(使用密码:YES)
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [28000]; error code [1045]; Access denied for user 'root '@'localhost' (using password: YES); nested exception is java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)
My配置文件,jdbc.properties:
My configuration file, jdbc.properties:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/CBS
jdbc.username=root
jdbc.password=root
顺便说一句,我将使用本地服务器的原因是因为我们的主服务器关闭所以我必须使用我的本地mysql来继续我的项目。请帮助我......提前致谢。
By the way, the reason I will be using local server because our main server shutdown so I have to use my local mysql to continue with my project. Please help me... Thanks in advance.
推荐答案
您的框架很可能以<$ c的形式登录本地数据库$ C> 127.0.0.1 。如果您尚未定义适当的域范围凭据,那么将在MySQL中创建登录问题。试试这个来验证:
More than likely your framework is logging into your local database as 127.0.0.1
. Which will create a login problem in MySQL if you have not defined an appropriate domain scoped credential. Try this to verify:
mysql -uroot -proot
SELECT * from mysql.user WHERE user = 'root';
如果没有'root'@'127.0.0.1'那么找到问题并补救它,执行以下两项操作之一:
If there is no 'root'@'127.0.0.1' then have found the problem and to remedy it, do one of two things:
- 为'root'定义域范围的凭证,位于'127.0.0.1'。
- 为'root'定义通配符域范围的凭据,因此您可以使用来自多个位置的凭据登录到您的MySQL。
以下是第二个例子:
mysql -uroot -proot
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
在旁注中,我肯定会建议您使用更具创意的用户ID和密码。特别是如果你的服务器启用了TCP套接字。
On a side note, I would definitely recommend using something more creative for your user id and password. Especially if you have TCP sockets enabled for your server.
这篇关于JDBC Hibernate - Mysql连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!