I have spring boot app and deployed to a remote server. The app runs on my computer. MySQL connection URL, user name and password are the same local and remote MySQL. DB and app in same machine!!
I checked my connection info and executed about below commands.
GRANT ALL PRIVILEGES ON burrda.* TO 'root'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
My application.properties
is below.
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL57Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/burrda
spring.datasource.username=root
spring.datasource.password= password
When apps runs I'm getting java.sql.SQLException: Access denied for user 'root'@'localhost'
I'm not getting these exceptions java.sql.SQLException: Access denied for user 'root'@'localhost'
(using password: YES) or java.sql.SQLException: Access denied for user 'root'@'localhost'
(using password: NO)
I also faced the same issue.
The solution which worked for me
Create
a new user Grant
this new user privileges of your database: create user '<new_user_name>'@'localhost' identified by '<new_user_password>';
grant all privileges on <your_db_name>.* to '<new_user_name>'@'localhost' identified by '<new_user_password>';
The SQL command for granting the user must not contain PASSWORD
keyword, it must be like:
GRANT ALL PRIVILEGES ON burrda.* TO 'root'@'localhost' IDENTIFIED BY 'password';
I know it's way to late.. I got this issue in a spring-boot application.
I solved this problem by using defaults, let me explain.
When I used hibernate, I use the property
<property name="connection.user">root</property>
ie connection.user
now, I tried using the same in spring-boot application.
spring.datasource.user
Solution is spring.datasource.username
It's unclear from your question, does DB runs in same machine where web application is running? If no, you need to provide IP address of the remote machine where the web application is running in the GRANT
command.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.