java.sql.SQLException:拒绝用户“root”@“localhost”(使用密码:是)访问,网址为 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)~[mysql-connector-java-8.0.15.jar:8.0.15],网址为 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)~[mysql-connector-java-8.0.15.jar:8.0.15]
2019-04-25 16:29:48.930 WARN 18226 --- [main] osbaorm.jpa.DatabaseLookup:无法从数据源 org.springframework.jdbc.support.MetaDataAccessException 确定 jdbc url:无法获取用于提取元数据的连接;嵌套异常为 org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取 JDBC 连接;嵌套异常为 java.sql.SQLException:拒绝用户“root”@“localhost”访问(使用密码:YES) java.sql.SQLException:拒绝用户“root”@“localhost”访问(使用密码:YES) 启动 ApplicationContext 时出错。要显示条件报告,请在启用“调试”的情况下重新运行应用程序。 2019-04-25 16:29:50.140 错误 18226 --- [main] osboot.SpringApplication:应用程序运行失败
我使用了 spring boot 但仍然遇到这个问题
SpringBootApplication @EnableJpaRepositories公共类GestionFactureApplication {
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(GestionFactureApplication.class, args);
FactureRepository factureRepository = ctx.getBean(FactureRepository.class);
factureRepository.save(new Facture("123",56,6,"inProgress"));
factureRepository.save(new Facture("124",56,6,"Payed"));
factureRepository.save(new Facture("125",56,6,"Saved"));
RoleRepository roleRepository = ctx.getBean(RoleRepository.class);
Role roleUser = new Role(RoleEnum.ROLE_USER);
Role roleAdmin = new Role(RoleEnum.ROLE_ADMIN);
roleRepository.save(roleUser);
roleRepository.save(roleAdmin);
UserRepository userRepository = ctx.getBean(UserRepository.class);
User user = new User("user", "root", true);
user.setRoles(Arrays.asList(roleUser));
userRepository.save(user);
User admin = new User("admin", "root", true);
admin.setRoles(Arrays.asList(roleUser, roleAdmin));
userRepository.save(admin);
}
}
应用程序.属性
spring.jpa.hibernate.ddl-auto=create spring.datasource.url=jdbc:mysql://localhost:3306/GestionFacture spring.datasource.username=root spring.datasource.password=密码 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
PHPMYADMIN 错误
mysqli_real_connect():(HY000/1045):拒绝用户“phpmyadmin”@“localhost”访问(使用密码:是)与控制用户建立的连接,以确定您的配置。