The SpringBoot program connects to the Ali server mysql and appears Access denied for user'root'@'own computer's public network ip' (using password: YES)

1, caused by the incident

  • I am using Ali server, and MySQL is installed in it. When connecting with SpringBoot, the error shown in the title appears. Access denied for user'root'@'own computer's public network ip' (using password: YES)

2. The first idea

  • The remote authority of the database is not open, so modify it
  • Enter MySQL
 mysql -u root -p
  • Login after entering the password
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的数据库密码'  
  • Refresh permissions
flush privileges; 
  • After this was done, it was unsuccessful and still not resolved, so the problem does not appear here.

3. View the configuration file

  • Found low-level errors here
spring:
  main:
    allow-bean-definition-overriding: true
  datasource:
    url: jdbc:mysql://ip:3306/database
    driver-class-name: com.mysql.jdbc.Driver
    name: root
    password: 123456
  • In the above configuration file, the name attribute is wrong, and name is the name of the datasource. Since it was not found before, we have been investigating it.
  • Modify, change to username, username is the attribute of logging in to the database
spring:
  main:
    allow-bean-definition-overriding: true
  datasource:
    url: jdbc:mysql://ip:3306/database
    driver-class-name: com.mysql.jdbc.Driver
    password: 123456
    username: root
  • Before this, I also modified DNS and so on, but all failed, so next time I make this mistake, I still have to start with the configuration file.

Guess you like

Origin blog.csdn.net/JISOOLUO/article/details/104561253