当前位置:网站首页>After docker is deployed, mysql cannot connect
After docker is deployed, mysql cannot connect
2022-08-05 06:45:00 【User Nickname 23】
1. Create instance command
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. View the launched instance docker ps
3. The port 3306 of the host is mapped here, I have opened the port 
4. Connect on the host machine
#This error is like mysql does not exist, check if mysql is started
#mysql has been started, and the port is not occupied
5. It has been tested in the container, mysql can be connected normally; try to open the root user to access from any host
5.1, enter the container, and connect to mysql
docker exec -it c_mysql bash
mysql -uroot -p123456
5.2. Open the root user to all hosts to access
mysql> grant all privileges on . to [email protected]'%'; #Authorization
mysql> flush privileges; #Refresh the privilege table
6. Run the connection test again in the host
#Still not working!!!
7. I went to Baidu and thought that the host's routing was not enabled. Let's try it.
#Come back and find that the problem lies in the host, because if you want to use the mysql command, you must have /usr/This command is available in the bin/ directory.But I installed mysql in docker, so the host cannot use mysql to connect to the docker database. The error reported when using the remote tool navicat to connect should be that the root user is not enabled, and any host can access it.Since the above has been opened, I now test that navicat can be connected remotely
8. The above mentioned a host routing problem. If we do not open the routing, the host will be isolated from the container instance network, so it is necessary to open it.
8.1. Check if the route is open
sysctl net.ipv4.ip_forward
#The return value of 1 means the route is enabled, and 0 means it is not enabled
8.2, enable the route
echo “net.ipv4.ip_forward = 1” >>/etc/sysctl.conf#Write the command to the /etc/sysctl.conf file
sysctl -p #Load the kernel
sysctl net.ipv4.ip_forward #Check whether the route is enabled again
Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- input详解之文件上传
- 关于Antd的Affix突然不好用了,或者Window的scroll监听不好用了
- document.querySelector()方法
- Seven Ways to Center a Box Horizontally and Vertically
- DevOps process demo (practical record)
- Cloud Computing Basics - Study Notes
- 系统基础-学习笔记(一些命令记录)
- Mina disconnects and reconnects
- [ingress]-ingress exposes services using tcp port
- May I ask how to read the binlog of the two tables of hologres through flink sql, and then how to join?
猜你喜欢

淘宝客APP带自营商城本地生活CPS外卖优惠电影票话费更新渠道跟单生活特权V3

白鹭egret添加新页面教程,如何添加新页面

HelloWorld

超简单的白鹭egret项目添加图片详细教程

农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1

Vim tutorial: vimtutor

深夜小酌,50道经典SQL题,真香~

Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images

Q 2020, the latest senior interview Laya soul, do you know?

uniapp打包次数限制怎么办?只需两步就能解决
随机推荐
媒体查询、rem移动端适配
selenium学习
vs2017关于函数命名方面的注意事项
Alibaba Cloud Video on Demand
人人AI(吴恩达系列)
Cocos Creator Mini Game Case "Stick Soldier"
uniapp打包次数限制怎么办?只需两步就能解决
数组&的运算
设置文本向两边居中展示
VRRP overview and experiment
Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
## 简讲protobuf-从原理到使用
Problems encountered in installing Yolo3 target detection module in Autoware
Take you in-depth understanding of cookies
DevOps - Understanding Learning
Network Troubleshooting Basics - Study Notes
错误记录集锦(遇到则记下)
【FAQ】CCAPI兼容EOS相机列表(2022年8月 更新)
LaTeX使用frame制作PPT图片没有标号
Collision, character controller, Cloth components (cloth), joints in the Unity physics engine