The first step: first install docker and docker-compose
See my other article for installation steps https://blog.csdn.net/qq_37557563/article/details/109747026
Step 2: Create a docker-compose-service/mysql folder under the root directory. The docker-compose-service file is where I will store all the installed containers in the future.
Create a new docker-compose.yml folder
version: '3'
services:
mysql:
image: mysql
restart: always
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M;
ports:
- 3306:3306
volumes:
- /root/docker-compose-service/mysql/data:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
The default database is that the account is root
Modify the password by yourself MYSQL_ROOT_PASSWORD
Save
Enter into the mysql folder. Command to start mysql: docker-compose up -d (Start the container command, be sure to execute this command under the directory where the container needs to be started. It will start all the containers under this directory)
The command to stop the mysql container is: docker-compsoe down
Use the docker command to see if the mysql container has started docker ps
Navicat link mysql
It may appear that the link is not up. First confirm whether the ip address is correct
If the ip address and account password are correct, then the firewall is not turned off
systemctl stop firewalld
Go and try if you can connect