当前位置:网站首页>Connect mysql detailed graphic operations in ECs docker (all)
Connect mysql detailed graphic operations in ECs docker (all)
2022-07-27 02:04:00 【Menon research monk】
Catalog
Preface
On the cloud server through docker Built mysql
The local navicat Connect mysql This error always occurs when
The questions are as follows
2003 - Can’t connect to MySQL server on 'xxx'(10060)
The screenshot is as follows :
For this question , Maybe some details are missing ( There's always this , Check one operation by one )
The following articles are built from zero mysql
And through navicat Connect mysql Graphic operation of
1. install mysql
On the server through docker install mysql
install mysql 5.7 Mirror image :sudo docker pull mysql:5.7
After pulling the image , You can check whether the image is installed docker images
Create an instance and start :
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7
Description of the code module :
- -p Map ports , Put it linux Of 3306 Port and port mysql Inside the container 3306 Port mapping
- -v For mounting (etc For profile ,log For log files ,lib For profile )
Put it mysql The files inside the container are mounted to linux in , Every change will be in linux Show , Instead of going inside the container to check
-e initialization 123456 User password

Modify the configuration file :( It is mainly about the modification of configuration files in coding format )
Because the container has mapped files to linux in , stay linux Just modify it
The specific command is as follows :vim /mydata/mysql/conf/my.conf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
Look at the docker Medium mysql Is there a mapping :
adopt docker exec -it mysql /bin/bash Into the container , And check the files in the container 
After confirming that the mapping is successful , adopt docker restart mysql Containers id
2. Open remote connection
Default mysql You can't connect remotely
Through the top docker Once in the container
Sign in mysql:mysql -u root -p
The password for 123456, The password is docker install mysql Configured 
Open remote connection :ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; ,( The password is 123456, Yes, then connect remotely mysql Password )
Refresh effective :FLUSH PRIVILEGES;
Look again :select host,user,plugin,authentication_string from mysql.user;

You can see root Authorized by the host by %, That is, remote access has been enabled
3. A firewall
You can open a port to map out or directly close the firewall
See my previous article for specific firewall knowledge points :
- ubuntu: Explain firewall configuration in detail ( whole )
- linux The firewall command firewall、iptable As well as detailed interpretation of port number ( whole )
If only one firewall port is enabled :( That is to say 3306mysql The port of )
Check the open port number :firewall-cmd --list-ports
Permanently open one 3306 Port number :firewall-cmd --zone=public --add-port=3306/tcp --permanent
service iptables restart :firewall-cmd --reload
Check whether the port number is enabled again :firewall-cmd --list-ports
The screenshot is as follows :
Another way is to close it directly
Or simply close the firewall :systemctl stop firewalld.service
Check the status of the firewall :systemctl status firewalld.service

4. Inbound rules
The security rules of ECS need to configure inbound rules
See the description of its official website for specific servers ,( I am Huawei cloud server ): Configure security group rules
Configure inbound rules as follows :

After the configuration is successful
stay linux You can check whether the port number is open through the command line , adopt lsof、netstat
The specific use method is lsof -i Check whether the port is open ,netstat Provide network related information of the host , It can be done by netstat -anp
General order :netstat -anp | grep 3306
The screenshot is as follows :( This configuration indicates that the port mapping has been successful )
5. Connect mysql
navicat Connect mysql
ip The address is server instead of docker Of , The account password is mysql Instead of the server
In the local ping ip Can the address be communicated
roughly ip For the elasticity of ECS ip Address instead of private address ( Ensure communication )

边栏推荐
- Web services (02) - Web server middleware
- Acwing 1057. stock trading IV
- PHP processing tree and infinite processing
- R分数复现 R-precision评估指标定量 文本生成图像R分数定量实验全流程复现(R-precision)定量评价实验踩坑避坑流程
- Shell (13) Three Musketeers
- [translation] explicit and implicit batch in tensorrt
- Summary and review of key points of digital image processing
- In regular expressions (?: pattern), (?! pattern), (? < =pattern) and (?
- 力扣获取第二大的成绩
- Talking about server virtualization & hyper convergence & Storage
猜你喜欢

Virtualization technology KVM

Text to image论文精读DF-GAN:A Simple and Effective Baseline for Text-to-Image Synthesis一种简单有效的文本生成图像基准模型

Shell script - automatically deploy DNS services

虚拟化技术KVM

Use of shell (11) brackets

Shell course summary

无线传感器网络(双语)复习

mysql优化概论

MySQL single table query exercise

Text to image论文精读SSA-GAN:基于语义空间感知的文本图像生成 Text to Image Generation with Semantic-Spatial Aware GAN
随机推荐
Shell (13) Three Musketeers
(hdu1588) Gauss Fibonacci (sum of matrix fast power + bisection matrix proportional sequence)
Talking about server virtualization & hyper convergence & Storage
【CANN训练营】走进媒体数据处理(下)
Harmonyos image processing application development live broadcast notes
FID指标复现踩坑避坑 文本生成图像FID定量实验全流程复现(Fréchet Inception Distance )定量评价实验踩坑避坑流程
系统动力学专拓考试重点总结
分库与分表
Docter的安装和基础操作
指针常量与常量指针详细讲解
Identify artifact MX yolov3
MySQL view
PHP processing tree and infinite processing
Shell script - automatically deploy DNS services
Text to image论文精读GR-GAN:逐步细化文本到图像生成 GRADUAL REFINEMENT TEXT-TO-IMAGE GENERATION
You can understand the detailed introduction and understanding of inheritance
Summary of key points of system dynamics specialized examination
索引失效原理讲解及其常见情况
Removal and addition of reference types in template and generic programming
MySQL存储过程函数