【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to
写于 2024.03.07 北京.朝阳
[toc]
报错信息
先看看和你的报错一样不一样
null, message from server: "Host '172.17.0.1' is not allowed to connect to this MySQL server"
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/4a8824f02aea47689f3cd95e07acb871.webp)
环境现场
mac 电脑使用 docker 部署了一个 mysql。
docker pull mysql:5.7
docker run -p 3306:3306 --name mysql-container -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server:5.7
查看是否启动成功。
docker ps
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/465f531ab73948eb9667a0c0efe173f6.webp)
解决方案
步骤:
- 查看 docker 信息
docker ps
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/84ec6fe8b08342b4b1cf3b8c71265edd.webp)
- 进入 docker 容器内部
docker exec -it 你的容器id bash
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/7f3af9e2ad0b4437b770f025b87163fc.webp)
- 连接数据库
mysql -u root -p
4. 查询所有数据库
show databases ;
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/c576cef0c9a44c94b59e2c75b9595305.webp)
- 进入mysql数据库:
use mysql ;
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/e748fb8797324d8d988b66bf114ebfa3.webp)
- 查看mysql数据库中所有的表:
show tables ;
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/8f1465844abb45058403b2b30cf60792.webp)
- 查看user表中的数据:
select Host, User from user ;
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/485cf1f3001745ceb034773fb7cade76.webp)
- 修改user表中的Host:
update user set Host='%' where User='root' ;
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/1a8a3176583d4d83a3ca9a0128976aa4.webp)
- 最后刷新一下:
flush privileges ;
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/1afde077d802439280756f6d5e555698.webp)
成功
![【已解决】[图文步骤] message from server: “Host ‘172.17.0.1‘ is not allowed to connect to](https://static.blogweb.cn/article/8ba738c05cc14db4a9dcc133521d9d2c.webp)
最后
大家在学习中一定遇到很多异常情况无从下手,可以加入讨论、观看行业内技术人员讨论解答。
转载自:https://juejin.cn/post/7343225969236590628