【发布时间】:2019-10-20 14:26:18
【问题描述】:
我是 docker compose 的新手,想将 mysql 附加到我的 Spring Boot 应用程序中。
我的撰写文件看起来
version: '3'
volumes:
mysql_data:
services:
ww-mysql:
image: mysql:5.7
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ww
MYSQL_USER: admin
MYSQL_PASSWORD: admin
ww-app:
build: .
image: ww-app
ports:
- 8080:8080
depends_on:
- ww-mysql
links:
- ww-mysql
连接到mysql的应用程序属性
spring.datasource.url = jdbc:mysql://localhost:3306/ww?useSSL=false
spring.datasource.username = admin
spring.datasource.password = admin
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
我遇到的错误
2019-06-05 04:58:16.411 ERROR 6 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000319: Could not get database metadata
ww-app_1 |
ww-app_1 | com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
ww-app_1 |
ww-app_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
我很困惑。我的 ubuntu 18 上运行着 mysql 服务器
【问题讨论】:
标签: mysql spring-boot docker docker-compose