Docker install Mysql and remote access actual combat

Docker use tutorial related series catalog


table of Contents

Pull mysql mirror

Run mysql mirror

Verify connection

What should I do if I can’t access remotely after installation


Pull mysql mirror

docker pull mysql:5.7

 

If you don’t know how to choose the version, please see here: docker common operation mirror command

0

Run mysql mirror

docker run -d --name mysql57 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.7

0

-d 	后台运行容器
-p 3306:3306 	指定端口映射(主机(宿主)端口:容器端口)
--name 	为容器指定一个名称
-e  	设置环境变量
MYSQL_ROOT_PASSWORD=root 	初始密码
mysql:5.7 	镜像名称和版本号

Note: Be sure to add the -p parameter to map the internal port of docker, otherwise it will start the internal port of docker, which cannot be accessed from outside

Check if the container is started

docker ps

0

Verify connection

Successfully connected through the Navicat client

0

0

What should I do if I can’t access remotely after installation

1. Enter the inside of the mysql container

docker exec -it mysql57 bash

0

2. Enter mysql and verify that you are prompted to log in, indicating that you have come in

0

3. Enter the account password:

mysql -uroot -p

0

show databases;

0

4. Switch the database to mysql

use mysql

0

5. Query the user table user

select user,host from user;

0

6. If the host without root in the account table is "%", add a piece of data through the command line. Then it can be accessed through the client.

Guess you like

Origin blog.csdn.net/shi_hong_fei_hei/article/details/114765820