Phpmyadmin 和 mysql 在 docker-compose down and up 后连接失败
Phpmyadmin and mysql connection fails after docker-compose down and up again
这是我的 docker-compose.yml 文件,用于启动 PMA 和 mysql:
version: '3.8'
services:
mysql_db:
image: mysql:8.0.28
ports:
- "64121:3306"
environment:
- MYSQL_ROOT_PASSWORD=rootsecretpassword
- MYSQL_DATABASE=dbname
- MYSQL_USER=db-username
- MYSQL_PASSWORD=db-password
volumes:
- mysql_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:5.1.2
ports:
- "64122:80"
environment:
- MAX_EXECUTION_TIME=600
- UPLOAD_LIMIT=800M
- PMA_HOST=mysql_db
- PMA_PORT=3306
- PMA_ARBITRARY=1
depends_on:
- mysql_db
volumes:
mysql_data:
docker-compose up --build
然后,我可以到达 localhost:64122
查看 PMA(phpmyadmin),我可以使用凭据登录,一切正常,但是 在 运行 docker-compose down
和 docker-compose up --build
我无法登录 PMA,它显示:
Cannot log in to the MySQL server
mysqli::real_connect(): (HY000/1130): Host 'SOME IP ADRESS' is not allowed to connect to this MySQL server
那么,在 docker 中的 down
和 up
期间发生了什么导致了这个错误?
默认情况下,数据库用户只能从本地主机连接
SELECT host FROM mysql.user WHERE user = "db-username";
更新table:
GRANT ALL ON dbname.* to 'db-username'@'%' IDENTIFIED BY 'db-password';
FLUSH PRIVILEGES;
SELECT host FROM mysql.user WHERE user = "db-username";
这是我的 docker-compose.yml 文件,用于启动 PMA 和 mysql:
version: '3.8'
services:
mysql_db:
image: mysql:8.0.28
ports:
- "64121:3306"
environment:
- MYSQL_ROOT_PASSWORD=rootsecretpassword
- MYSQL_DATABASE=dbname
- MYSQL_USER=db-username
- MYSQL_PASSWORD=db-password
volumes:
- mysql_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:5.1.2
ports:
- "64122:80"
environment:
- MAX_EXECUTION_TIME=600
- UPLOAD_LIMIT=800M
- PMA_HOST=mysql_db
- PMA_PORT=3306
- PMA_ARBITRARY=1
depends_on:
- mysql_db
volumes:
mysql_data:
docker-compose up --build
然后,我可以到达 localhost:64122
查看 PMA(phpmyadmin),我可以使用凭据登录,一切正常,但是 在 运行 docker-compose down
和 docker-compose up --build
我无法登录 PMA,它显示:
Cannot log in to the MySQL server
mysqli::real_connect(): (HY000/1130): Host 'SOME IP ADRESS' is not allowed to connect to this MySQL server
那么,在 docker 中的 down
和 up
期间发生了什么导致了这个错误?
默认情况下,数据库用户只能从本地主机连接
SELECT host FROM mysql.user WHERE user = "db-username";
更新table:
GRANT ALL ON dbname.* to 'db-username'@'%' IDENTIFIED BY 'db-password';
FLUSH PRIVILEGES;
SELECT host FROM mysql.user WHERE user = "db-username";