gpt4 book ai didi

java - spring boot/jpa 无法使用用户名 "@localhost"使用密码 no 连接到 mysql?

转载 作者:行者123 更新时间:2023-12-02 11:03:58 25 4
gpt4 key购买 nike

我正在尝试连接到 MySQL 数据库。

持久性.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

spring.datasource.url = jdbc:mysql://localhost:3306/myDB?useSSL=false

# Username and password
spring.datasource.username = root
spring.datasource.password = root

错误

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)

最佳答案

尝试删除=用户名密码之间的空格。

spring.datasource.username=root
spring.datasource.password=root

关于java - spring boot/jpa 无法使用用户名 "@localhost"使用密码 no 连接到 mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51119307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com