Spring Boot应用程序与Docker MySQL服务器用户连接

 收藏

我有一个spring boot应用程序,当我将其连接到本地mysql服务器时,它运行得很好。

现在,我正在尝试将其连接到docker mysql服务器。但是我总是收到这个错误:

java.sql.SQLException: Access denied for user 'arqam'@'172.17.0.1' (using password: YES)

但它可以完全与DOCKER MYSQL的根用户连接。

Spring启动资源文件:

spring:
datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://172.17.0.2:3306/test_db?useSSL=false&allowPublicKeyRetrieval=true
    username: arqam
    password: root
  jpa:
    hibernate.ddl-auto: update
    generate-ddl: true
    show-sql: true

Docker部分

  • When I run sudo docker inspect imageId :

    "Ports": { "3306/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "3310" } ], "33060/tcp": null }, "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", }

Running docker ps :

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
3c7sj342938        mysql:8             "docker-entrypoint.s…"   3 months ago        Up About an hour    33060/tcp, 0.0.0.0:3310->3306/tcp   mysqlContainer

I haven't posted other data, if anything else is needed will post that also. I went through this post, and made my ddatasource url as mentioned, but its not connecting to the mysql server.

因此,如何将用户连接到Spring Boot应用程序。如果我缺少什么,请告诉我。

回复