我是这样尝试连接的。但它显示:"Host'host.docker.internal'is not allowed to connect:
Host 'host.docker.internal' is not allowed to connect(不允许连接)
YAML。
environment:
- MYSQL_DSN=mysql:host=192.168.0.1;port=3307;dbname=dbname
你的MySQL用户不允许外部连接。
使用 "GRANT "更新你的用户以允许永恒的连接,或者使用 "CREATE USER "创建一个新用户。https:/linuxize.composthow-to-creation-mysql-user-accounts-and-grant-privileges。
要接受所有的连接,请使用 %
通配符作为主机部分。
以上2个步骤使用yaml文件作为。
services:
mysql-data:
image: image_path/mysql-data:latest
container_name: mysql-data
my-container-name:
image: mysql/mysql-server:5.6
container_name: my-container-name
env_file:
- MYSQL_ROOT_HOST=%
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_USER=username
- MYSQL_PASSWORD=password
ports:
- 9999:3306
volumes_from:
- mysql-data
使用命令登录到mysql数据库。
mysql -h <your-host-ip> -P9999 -uusername -ppassword