我花了很多天时间尝试找到问题所以请帮助我。
我遇到了与数据库连接的hibernate问题始终对用户'root'@“localhost”(使用密码:YES)拒绝异常访问,即使我的用户xx不是root用户。
我的hibernate.cfg.xml是:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/user</property>
<property name="hibernate.connection.username">wojtek</property>
<property name="hibernate.connection.password">xx</property>
<mapping resource="program/Members.hbm.xml"/>
</session-factory>
</hibernate-configuration>
我看到拒绝访问是针对root的,但在我的hibenrate.cfg.xml中是wojtek所以这里必须是主要问题。
BTW我可以正常连接到数据库表单行命令root或wojtek,使用jdbc的aplication也可以连接但只有Hibernate我有拒绝用错误的用户。
答案 0 :(得分:0)
要考虑的一点是,如果在连接到mysql时指定localhost,那么mysql将使用Unix Socket
而不是TCP/IP
。为了确保mysql正在使用TCP/IP
,与Hibernate
相同,请确保在使用mysql进行测试时指定--host。 “Unix Socket”和“TCP / IP”的权限不同。
答案 1 :(得分:0)
我有类似的问题,并尝试了几个小时来找到解决方案。最后,我能够通过更新mysql-connector版本来解决问题。试试最新的连接器版本(5.1.29),让我知道他的作品是否适用。如果您更新了MySQL服务器版本,这可能会有所帮助。
答案 2 :(得分:0)
谢谢所有回答。
我认为版本jdk和netbeans的版本有冲突,这就是为什么它不能在我的Windows 7,xp,debian上工作(在所有这个操作系统上我使用Netbeans 7.4和jdk 7u51)
BTW:我安装了Linux Mint并安装了OpenJDK版本7u51 + netbeans 8,一切正常。