1. Install docker
1.Install docker
1) Use an account with administrator rights to install and enter the installation command:
yum -y install docker.io 或 apt-get install -y docker.io
2) What you install using the above command may not be the latest version of docker. To install the latest version of docker, enter the command:
curl -s https://get.docker.com | sh
2. Start docker and use the command:
service docker start 或systemctl start docker.service
3. To check the docker version, use the command:
docker version
4. To delete docker, use the command:
yum -y remove docker-engine
5. Docker is set to start automatically after booting, use the command:
systemctl enable docker
2. MySQL installation and deployment
1. To view available MySQL, use the command:
docker search mysql
2. Pull the docker image and install it, using the command:
docker pull mysql:8.0
3. To view the running status of the container, use the command:
docker container ls
4. To list the running containers, use the command:
docker ps
Remarks: docker ps [OPTIONS] description:
- -a: Display all containers, including those that are not running.
- -f: Filter the displayed content according to the condition.
- –format: Specifies the template file for the return value.
- -l: Show recently created containers.
- -n: List the last n containers created.
- --no-trunc: Do not truncate output.
- -q: Quiet mode, only display the container number.
- -s: Display the total file size.
5. Install MySQL and create an administrator account and password for MySQL. Use the command:
docker run -itd --name mysql8.0 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root1234 mysql:8.0 --lower_case_table_names=1 --max_connections=10000;
Remark:
lower_case_table_names=1: ignore case;
max_connections: maximum number of connections;
–name: Specify a name for the container, here named mysql8.0
-e: configuration information, where the login password of the root user of mysql is configured
-p: port mapping, where port 3306 of the host is mapped to port 3306 of the container
-d: Run the container in the background and return the container ID;
6. Log in to the container
You need to start the container before logging in to the container: docker start container id
Log in to the container: docker exec -it container id /bin/bash
7. Log in to mysql
Enter the container and log in to MySQL from the container: mysql -uroot -proot1234
8. Set up remote connection
Set according to MySQL version
(1) To set up a remote connection in MySQL 5.7, use the command:
use mysql;
grant all privileges on *.* to 'root'@'%' identified by 'root1234' with option;#Set up remote connection
Flush privileges;#Refresh privileges
(2) To set up a remote connection for MySQL version 8.0 or above, use the command:
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';#Set up remote connection
Flush privileges;#Refresh privileges
9. Set the mysql database in docker to start automatically at boot:
docker update mysql8.0 --restart=always 容器id