Docker use tutorial related series catalog
table of Contents
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
Run mysql mirror
docker run -d --name mysql57 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.7
-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
Verify connection
Successfully connected through the Navicat client
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
2. Enter mysql and verify that you are prompted to log in, indicating that you have come in
3. Enter the account password:
mysql -uroot -p
show databases;
4. Switch the database to mysql
use mysql
5. Query the user table user
select user,host from user;
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.