当我按照本教程:https://spring.io/guides/gs/accessing-data-mysql/#initial并启动一些新的docker容器时:
version: '2'
services:
db:
image: mysql
environment:
- MYSQL_DATABASE=test
- MYSQL_USER=test
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=root
volumes:
- ./db:/var/lib/mysql
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_ARBITRARY: 1
MYSQL_USER: test
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root
ports:
- "80:80"
links:
# for mysql container
- "db:db"
volumes:
db:
driver: "local"
我无法连接MySql数据库,当我在Spring中运行示例应用程序时,我收到错误:
Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
我的应用程序属性:
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://db:3306/test
spring.datasource.username=springuser
spring.datasource.password=ThePassword
出了什么问题?我也试过像localhost这样的不同组合。我可以在浏览器中访问phpmyadmin。