当前位置:网站首页>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 )

边栏推荐
- count(*)为什么很慢
- Linux deployment MySQL
- uuid和索引建立规则
- 三范式,约束,部分关键字区别,
- [reprint] NVIDIA hardware and the accuracy mode supported by each hardware
- mysql的安装
- Introduction to network - Introduction to Enterprise Networking & basic knowledge of network
- Shell script - backup, update and rollback of files
- B - Bomb HDU - 5934
- MySQL multi table query
猜你喜欢
随机推荐
IS指标复现 文本生成图像IS分数定量实验全流程复现 Inception Score定量评价实验踩坑避坑流程
--Project summary
Application of load balancing
mysql存储引擎及其区别
深度学习过程中笔记(待完善)
Removal and addition of reference types in template and generic programming
Domain name analysis and DNS configuration installation
MySQL索引
科学计算库 —— Matplotlib
识别神器Mx-yolov3
Shell (8) cycle
[daily question] 565. Array nesting
负载均衡的运用
Enumerated valueof() method stepping on the pit
The bottom implementation of string container
mysql优化概论
D - Difference HDU - 5936
小项目——开机自连校园网
C language foundation Gobang, very easy to understand, detailed explanation, easy to use
索引失效原理讲解及其常见情况







![[untitled]](/img/2a/53327cd39db7871fa780ed599420d0.png)

