[英]springboot/jpa can't connect to mysql with username “@localhost” using password no?
I'm trying to connect to MySQL database. 我正在尝试连接到MySQL数据库。
persistent.xml persistent.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="myApp">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<!-- TODO: Change file location to your H2 database ! -->
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/myDB"/>
<property name="hibernate.dialect"value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
application.properties application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/myDB?useSSL=false
# Username and password
spring.datasource.username = root
spring.datasource.password = root
Error 错误
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
Try removing space between =
and username
and password
. 尝试删除
=
以及username
和password
之间的空格。
spring.datasource.username=root
spring.datasource.password=root
Looks like problem came from drivers version 看起来问题来自驱动程序版本
Now i use : 现在我使用:
Mysql Connector : 5.1.36 Hibernate-Entitymanager 5.2.10 Hibernante-core 4.3.10 Application.properties deleted No more use of any spring-boot dependencies. Mysql Connector:5.1.36 Hibernate-Entitymanager 5.2.10 Hibernante-core 4.3.10 Application.properties已删除不再使用任何spring-boot依赖项。
persistence.xml : persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="myapp" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.myapp.jpa.commande</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myDB" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
</properties>
</persistence-unit>
It's all ok now. 现在没事了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.