当前位置:网站首页>docker部署完mysql无法连接
docker部署完mysql无法连接
2022-08-05 05:25:00 【用户昵称23】
1、创建实例命令
docker run -id --name=c_mysql -p 3306:3306 -v /docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6.37
2、查看启动的实例 docker ps
3、这里映射的是宿主机的3306端口,我已经把端口开放了
4、在宿主机进行连接
#这个报错像是mysql不存在,查看mysql是否启动
#mysql已启动,端口也没有被占用
5、已经在容器里面测试了,mysql可以正常连接;在试试将root用户开放可以任何主机访问
5.1、进入容器,并连接mysql
docker exec -it c_mysql bash
mysql -uroot -p123456
5.2、将root用户开放所有主机可以访问
mysql> grant all privileges on . to [email protected]‘%’; #授权
mysql> flush privileges; #刷新权限表
6、在宿主进再次进行连接测试
#还是不行!!!
7、去百度了一下,觉得是宿主机的路由没有开启,来试试看
#一圈回来,发现问题出在宿主机,因为如果要使用mysql命令,就是必须要/usr/bin/目录下有这个命令。但是我是docker安装mysql所以,宿主机不能使用mysql连接docker的数据库,使用远程工具navicat连接时报的错,应该是root用户没有开启,任何主机可以访问的权限。由于上面已经开了,我现在测试navicat是可以远程连接的
8、上面说到了一个宿主机路由的问题,我们路由没开的话就会导致宿主机于容器实例网络隔绝,所以是要打开的。
8.1、查看路由是否打开
sysctl net.ipv4.ip_forward
#返回值为1代表路由已开启,为0就是未开启
8.2、开启路由
echo “net.ipv4.ip_forward = 1” >>/etc/sysctl.conf #将命令写入到/etc/sysctl.conf文件中
sysctl -p #加载内核
sysctl net.ipv4.ip_forward #再次查看路由是否开启
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- LeetCode practice and self-comprehension record (1)
- Introduction to Network Layer Protocols
- 错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
- selenium学习
- 618, you may be able to wake up a little bit
- Mina断线重连
- Browser Storage WebStorage
- DevOps流程demo(实操记录)
- Native JS takes you to understand the implementation and use of array methods
- H5 的浏览器存储
猜你喜欢

NAT experiment

Growth: IT Operations Trends Report

input detailed file upload

Introduction to Network Layer Protocols

Mina's long and short connections

The cocos interview answers you are looking for are all here!

Successful indie developers deal with failure & imposters

Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"

Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive

单臂路由实验和三层交换机实验
随机推荐
Network Troubleshooting Basics - Study Notes
Logical volume creation
CIPU, what impact does it have on the cloud computing industry?
Tencent greetings function SCF - entry instructions
In-depth Zabbix user guide - from the green boy
Xiaodu Xiaodu is here!
wc, grep, tar, vi/vim
The highlight moment of operation and maintenance starts with intelligence
King power volume LinkSLA, realize operations engineer is happy fishing
vs2017关于函数命名方面的注意事项
User and user group management, file permission management
人人AI(吴恩达系列)
Cloud Computing Basics - Study Notes
Programmers should understand I/O this way
DevOps流程demo(实操记录)
Q 2020, the latest senior interview Laya soul, do you know?
sql server duplicate values are counted after
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
disabledDate 日期选择器 datePicker
618, you may be able to wake up a little bit