简体   繁体   English

springboot / jpa无法使用密码“ no”连接用户名“ @localhost”的mysql?

[英]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 . 尝试删除=以及usernamepassword之间的空格。

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.

相关问题 无法连接到本地主机上的MySQL - can't connect to MySQL on localhost SpringBoot 2使用HikariCP无法连接到MySQL - SpringBoot 2 use HikariCP can't connect to MySQL 无法在docker中将springboot连接到mysql - Can't connect springboot to mysql in docker 除非使用本地主机,否则无法使用Java连接到MySQL - Can't connect to MySQL using java unless its localhost 无法使用密码连接到mysql - can not connect to mysql using the password 在 SpringBoot 中使用 spring-data-jpa 构建登录验证 API 以与 MySQL 连接。 任何人都可以建议为什么会出现错误。? - Building an Login Validation API using in SpringBoot with spring-data-jpa to connect with MySQL. Can anyone advice why the error is coming.? 使用Springboot在https url中的用户名和密码 - Username and password in https url using Springboot 如何在localhost url中传递用户名和密码以连接Java中的memcached? - How to pass username and password in the localhost url to connect with the memcached in Java? java.sql.SQLException:使用Spring + JPA + MySql对用户“ @&#39;localhost”(使用密码:NO)的访问被拒绝 - java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) with Spring+JPA+ MySql spring boot数据jpa无法连接到mysql数据库 - spring boot data jpa can't connect to mysql database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM