0

I have a problem about running docker-compose.yml in my spring boot microservices.

When I tried to run the docker-compose.yml file through docker compose up, I got this issue shown below.

Caused by: java.sql.SQLSyntaxErrorException: Access denied for user 'springmicroserviceuser'@'%' to database 'userdb'

Here is the related part of docker-compose.yml

  authservice:
    image: 'microservicedailybuffer/authservice:0.0.1'
    container_name: authservice
    ports:
      - '7777:7777'
    environment:
      - EUREKA_SERVER_ADDRESS=http://serviceregistry:8761/eureka
      - CONFIG_SERVER_URL=configserver
      - spring.datasource.url=jdbc:mysql://database:3306/userdb?createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
      - spring.datasource.username=springmicroserviceuser
      - spring.datasource.password=111111
    depends_on:
      database:
        condition: service_healthy
      configserver:
        condition: service_started
    networks:
      - backend

How can I fix it?

Here is the github repo : Link

Here is the git based system file : Link

Here is the docker-compose.yml file : Link

qwercan
  • 89
  • 7
  • Your `docker-compose.yml` file seems to be missing the `database` service; did you mean to include it? Have you verified that those credentials work, possibly using the `mysql` CLI tool? – David Maze Dec 17 '22 at 22:36
  • @DavidMaze I shared the docker-compose.yml file. – qwercan Dec 18 '22 at 12:03
  • You seem to have added an additional link. Can you [edit] the question to make sure all of the required details are in the question itself, not behind links? (Once you fix this issue, will the master branch of your GitHub repository still demonstrate the issue?) – David Maze Dec 18 '22 at 12:12
  • @DavidMaze I shared the issue regarding not connecting mysql for auth service. – qwercan Dec 18 '22 at 12:17
  • @DavidMaze I got the same issue when I work with Kubernetes. How can I fix it? Here is the link : https://stackoverflow.com/questions/75329920/spring-cloud-in-kubernetes-caused-by-java-sql-sqlexception-access-denied-for – qwercan Feb 03 '23 at 02:17

1 Answers1

0

Try to change the database user on authservice (springmicroserviceuser ) to user (root)

...Change the user

  • spring.datasource.username=springmicroserviceuser ... to
  • spring.datasource.username=root
  • When I changed `spring.datasource.username=root`, `spring.datasource.password=root`, `password=root`, `MYSQL_USER: root`, `MYSQL_PASSWORD: root` and `MYSQL_ROOT_PASSWORD: root`, I get this issue (`Caused by: java.sql.SQLException: Access denied for user 'root'@'172.24.0.7' (using password: YES)`) How can I fix it? I shared all docker-compose.yml file as a link – qwercan Dec 18 '22 at 12:11
  • I got the same issue when I work with Kubernetes. How can I fix it? Here is the link : https://stackoverflow.com/questions/75329920/spring-cloud-in-kubernetes-caused-by-java-sql-sqlexception-access-denied-for – qwercan Feb 03 '23 at 02:09