无法连接到MySQL映像:无法创建与数据库服务器的连接

时间:2020-08-14 03:50:59

标签: mysql spring-boot docker jdbc docker-compose

我正在尝试从Java应用程序连接到MySQL映像,但是由于某种原因,它给了我:[08001] Could not create connection to database server. Attempted to reconnect 3 times. Giving up. java.net.ConnectException: Connection refused: connect.

它似乎试图访问数据库,但是登录信息不正确,尽管不是正确的。我将不胜感激,也许我只是盲目的。

我的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:

在容器启动时堆叠:

    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文件:

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

0 个答案:

没有答案