java - springboot/jpa 无法使用用户名“@localhost”使用密码连接到 mysql 否?
问题描述
我正在尝试连接到 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>
应用程序属性
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)
解决方案
尝试删除=
andusername
和之间的空格password
。
spring.datasource.username=root
spring.datasource.password=root
推荐阅读
- string - 如何在 Qt 字符串中单独截断主 URL
- python - Python Selenium Google 登录机器人
- node.js - Mongo 错误:$sort 阶段必须至少有一个排序键
- java - java - 如何在java sql中的spring boot中每次从jdbcTemplate.queryForList(sql)中删除列名
- javascript - React Native:在切换底部导航选项卡时设置参数
- javascript - 访问被点击的元素
- css - Safari浏览器的媒体查询
- r - 按日期查找表中的最新行
- html - 容器对齐问题
- python - 在带有链接的输出 ipywidget 中显示超链接