0

I am trying to connect from my Java application to MySQL image, but for some reason, it gives me: [08001] Could not create connection to database server. Attempted to reconnect 3 times. Giving up. java.net.ConnectException: Connection refused: connect.

It seems like it tries to access the database, but login info is incorrect, though it is not true. I would appreciate any help, maybe I am just blind.

My docker-compose.yaml:

  version: "3.3"

services:

   db-mysql:
       image: mysql:8.0.21
       ports:
          - 3306:3306
       container_name: eRestaurant_db
       networks:
          - eRestaurant-network
       environment:
          MYSQL_DATABASE: happy_tummy
          MYSQL_ROOT_PASSWORD: password123
       volumes:
          - my-db:/var/lib/mysql

volumes:
   my-db:

networks:
   eRestaurant-network:

Stack when container is up:

    Recreating eRestaurant_db ... done                                                                                                                      Attaching to eRestaurant_db
eRestaurant_db | 2020-08-14 03:39:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
eRestaurant_db | 2020-08-14 03:39:19+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
eRestaurant_db | 2020-08-14 03:39:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
eRestaurant_db | 2020-08-14 03:39:20+00:00 [Note] [Entrypoint]: Initializing database files
eRestaurant_db | 2020-08-14T03:39:20.036357Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 42
eRestaurant_db | 2020-08-14T03:39:20.042898Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
eRestaurant_db | 2020-08-14T03:39:20.956247Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
eRestaurant_db | 2020-08-14T03:39:22.903509Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
eRestaurant_db | 2020-08-14 03:39:27+00:00 [Note] [Entrypoint]: Database files initialized
eRestaurant_db | 2020-08-14 03:39:27+00:00 [Note] [Entrypoint]: Starting temporary server
eRestaurant_db | 2020-08-14T03:39:27.698855Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 89
eRestaurant_db | 2020-08-14T03:39:27.718821Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
eRestaurant_db | 2020-08-14T03:39:27.944323Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
eRestaurant_db | 2020-08-14T03:39:28.061636Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
eRestaurant_db | 2020-08-14T03:39:28.185890Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
eRestaurant_db | 2020-08-14T03:39:28.186075Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
eRestaurant_db | 2020-08-14T03:39:28.192291Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
eRestaurant_db | 2020-08-14T03:39:28.213335Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
eRestaurant_db | 2020-08-14 03:39:28+00:00 [Note] [Entrypoint]: Temporary server started.
eRestaurant_db | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
eRestaurant_db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
eRestaurant_db | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
eRestaurant_db | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
eRestaurant_db | 2020-08-14 03:39:31+00:00 [Note] [Entrypoint]: Creating database happy_tummy
eRestaurant_db |
eRestaurant_db | 2020-08-14 03:39:31+00:00 [Note] [Entrypoint]: Stopping temporary server
eRestaurant_db | 2020-08-14T03:39:31.451056Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.21).
eRestaurant_db | 2020-08-14T03:39:34.401782Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21)  MySQL Community Server - GPL.
eRestaurant_db | 2020-08-14 03:39:34+00:00 [Note] [Entrypoint]: Temporary server stopped
eRestaurant_db |
eRestaurant_db | 2020-08-14 03:39:34+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
eRestaurant_db |
eRestaurant_db | 2020-08-14T03:39:34.689506Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
eRestaurant_db | 2020-08-14T03:39:34.699358Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
eRestaurant_db | 2020-08-14T03:39:34.928207Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
eRestaurant_db | 2020-08-14T03:39:35.042858Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
eRestaurant_db | 2020-08-14T03:39:35.123421Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
eRestaurant_db | 2020-08-14T03:39:35.123614Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
eRestaurant_db | 2020-08-14T03:39:35.130639Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
eRestaurant_db | 2020-08-14T03:39:35.150321Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

application.properties file:

spring.datasource.url=jdbc:mysql://10.0.75.1:3306/happy_tummy?allowPublicKeyRetrieval=true&useSSL=false&createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=password123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL8Dialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
bogdasha
  • 153
  • 1
  • 2
  • 11
  • 1
    Where is your application running? On host or inside a docker container? – Kapil Khandelwal Aug 14 '20 at 05:16
  • 1
    Can you please share the output of `docker ps`. Where is the java app running: in the same docker network, on the same machine as the host, on another machine. What is the IP address of your docker host? – Neo Anderson Aug 14 '20 at 06:16
  • `10.0.75.1` is the IP of MySQL host? Are you trying to connect to MySQL from another host? `Connection Refused` error is because the port you're trying to connect on that specific IP is not open. – Ali Tou Aug 14 '20 at 06:22

0 Answers0