[英]Docker container can't connect to its mysql server (ACCESS DENIED)
I created a docker container and its mysql server like so:我创建了一个 docker 容器及其 mysql 服务器,如下所示:
docker run -d\
--name mysql-server
--restart on-failure\
-e MYSQL_ROOT_PASSWORD=1234\
-e MYSQL_DATABASE=users\
-v volume1:/var/lib/mysql\
mysql:latest --default-authentication-plugin=mysql_native_password
but when I try to login I get an access denied error.但是当我尝试登录时,出现访问被拒绝错误。 Here's how I'm trying to log in to the mysql server:
这是我尝试登录 mysql 服务器的方式:
docker exec -it spawning-pool mysql -uroot -p
This is the response I get:这是我得到的回应:
Enter password: (I put 1234 here)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
docker ps -a shows: docker ps -a 显示:
6909b7003519 mysql:latest "docker-entrypoint.s…" 38 minutes ago Up 38
minutes 3306/tcp, 33060/tcp mysql-server
docker exec mysql-server env shows: docker exec mysql-server env 显示:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=6909b7003519
MYSQL_ROOT_PASSWORD=1234
MYSQL_DATABASE=users
GOSU_VERSION=1.7
MYSQL_MAJOR=8.0
MYSQL_VERSION=8.0.18-1debian9
HOME=/root
I've tried changing the mysql version but that doesn't work.我试过更改 mysql 版本,但这不起作用。 Getting a random password works and I don't know why.
获取随机密码有效,我不知道为什么。 I also can't use the random password because this is a school project and there is guidelines I have to follow.
我也不能使用随机密码,因为这是一个学校项目,我必须遵循一些指导方针。 I've spent hours on this and any help is appreciated.
我已经花了几个小时在这上面,任何帮助表示赞赏。
seems like you have to change the password and run the command with existing volume, so it's not going to set new password as the default behaviour of Docker MySQL image.似乎您必须更改密码并使用现有卷运行命令,因此不会将新密码设置为 Docker MySQL 映像的默认行为。
You have two option你有两个选择
docker volume rm volume1 && docker run -it --rm -v volume1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=12345 -e MYSQL_DATABASE=users mysql:latest --default-authentication-plugin=mysql_native_password
Login to Your docker machine and check is mysql server running.登录到您的 docker 机器并检查 mysql 服务器是否正在运行。 I had similar problem.
我有类似的问题。 In my situation MySQL server dosent start after container run.
在我的情况下,容器运行后 MySQL 服务器不会启动。 Helped:
帮助:
ENTRYPOINT service mysql start && /bin/bash
Here is complete working examples with two serwers: apache and mysql on two differents containers这是带有两个服务器的完整工作示例:两个不同容器上的 apache 和 mysql
I hope, it help You我希望,它可以帮助你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.