即使主机值为%,我也无法远程连接到MySQL容器。
Error: Access denied for user 'root'@'172.28.0.1' (using passowrd: YES).
字符串
- 我使用HeidiSQL和MySQL库连接
- 注意到错误消息中指定的IP不断变化,这使得很难添加到主机值
- 在Windows 10上使用Docker Desktop(4.24.2)
my.cnf
绑定到0.0.0.0。- 已尝试不同的端口Map(例如3366:3306)
- Windows防火墙显示Docker Desktop对公共和私有网络开放
我可以通过Docker Desktop使用Exec选项卡连接。我可以看到root已经为远程访问配置了适当的主机:
mysql> select Host,User from user where User='root';
+-----------+------+
| Host | User |
+-----------+------+
| % | root |
| localhost | root |
+-----------+------+
2 rows in set (0.01 sec)
型
File:docker-compose.yml
version: "3.2"
services:
mysql:
container_name: mysql
build: './mysql/'
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_ROOT_HOST: "%"
TZ: "-03:00"
networks:
- frontend
- backend
ports:
- "3306:3306"
volumes:
- "$MYSQL_DATA:/var/lib/mysql"
networks:
frontend:
backend:
型
File:.env
MYSQL_ROOT_PASSWORD="root"
MYSQL_DATA=C:/Users/me/Downloads/docker_files/mysql/data
型
File:mysql/Dockerfile
FROM mysql:8.0
COPY conf/my.cnf /etc/my.cnf
型
文件conf/my.cnf
[mysqld]
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
bind-address=0.0.0.0
default-time-zone='-03:00'
general_log = 1
general_log_file = /var/log/mysql/mysql.log
#setting to 1 per recommendations, need to do this in Azure too.
lower_case_table_names=1
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
型
HeidiSQL:
的数据
更新#1
为了更好地衡量,我使用Docker Desktop的终端为两个用户设置了密码:
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.02 sec)
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
型
仍然无法进入。
1条答案
按热度按时间4sup72z81#
在HeidiSQL中,我了解到即使连接到MySQL,也应该始终使用
libmariadb.dll
:https://github.com/HeidiSQL/HeidiSQL/issues/1865