MySQL 8.0.20 installation and configuration tutorial under Docker

MySQL 8.0.20 installation and configuration tutorial under Docker

Docker installs MySQL version 8.0.20 for your reference. The specific contents are as follows

The first step is to pull down the image

docker pull mysql:8.0.20

Step 2: Start the mirror

docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.20

Check whether the startup is successful

docker ps -a

After the third step is successfully started, enter the container and copy the configuration file to the host.

docker cp mysql:/etc/mysql /mnt/sda1/mysql8.0.20

Copy the container's /etc/mysql directory to the host directory /mnt/sda1/mysql8.0.20

Step 4: Delete the mysql container and recreate it

Stop the container first

docker stop mysql

Delete the container again

docker rm mysql

Step 5: Start MySQL, mount the configuration file, and persist the data to the host

The startup script file name is mysql8.0.20.sh

#!/bin/sh
docker run \
-p 3306:3306 \
--name mysql \
--privileged=true \
--restart unless-stopped \
-v /mnt/sda1/mysql8.0.20/mysql:/etc/mysql \
-v /mnt/sda1/mysql8.0.20/logs:/logs \
-v /mnt/sda1/mysql8.0.20/data:/var/lib/mysql \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:8.0.20

Command Explanation:

-p port mapping

--privileged=true Mount file permission settings

--restart unless-stopped Set the container to automatically restart after booting

-v /mnt/sda1/mysql8.0.20/mysql:/etc/mysql mount configuration file

-v /mnt/sda1/mysql8.0.20/logs:/logs \ Mount log

-v /mnt/sda1/mysql8.0.20/data:/var/lib/mysql \ mount the data file to the host for persistence.

-v /etc/localtime:/etc/localtime Container time is synchronized with the host machine

-e MYSQL_ROOT_PASSWORD=123456 Set password

-d mysql:8.0.20 background start,mysql

Step 6 : Execute the script to start the image

sh mysql8.0.20.sh

docker ps -a to see if it is started successfully

Navicat connects to mysql to view the version number

You are done ---- mounted data files and configuration files

Congratulations on the successful installation.

If you want to modify the configuration information of MySQL, just modify the mounted configuration file.

Remember to restart after modification

Stop mysql

docker stop mysql

Start mysql

docker start mysql

Wonderful topic sharing:

MySQL different versions installation tutorial

MySQL 5.7 installation tutorials for various versions

MySQL 5.6 installation tutorials for various versions

mysql8.0 installation tutorials for various versions

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to modify the mysql configuration file under docker
  • Detailed explanation of custom configuration of docker official mysql image
  • Install and run a MySQL instance on Docker
  • Docker starts MySQL configuration implementation process

<<:  Vue implements three-dimensional column chart based on echarts

>>:  Detailed tutorial on how to deploy Springboot project using Nginx on the server (jar package)

Recommend

Detailed tutorial on VMware installation of Linux CentOS 7.7 system

How to install Linux CentOS 7.7 system in Vmware,...

CSS3 border effects

What is CSS# CSS (abbreviation of Cascading Style...

How to solve the error "ERROR 1045 (28000)" when logging in to MySQL

Today, I logged into the server and prepared to m...

How to print highlighted code in nodejs console

Preface When the code runs and an error occurs, w...

Bootstrap 3.0 study notes page layout

This time we will mainly learn about layout, whic...

Example verification MySQL | update field with the same value will record binlog

1. Introduction A few days ago, a development col...

Solution to mysql error code 1064

If the words in the sql statement conflict with t...

CSS shadow animation optimization tips

This technique comes from this article - How to a...

A thorough analysis of HTML special characters

A Thorough Analysis of HTML (14) Special Characte...

Detailed explanation of the usage and differences of MySQL views and indexes

MySQL Views Simply put, a MySQL view is a shortcu...

Top 10 Js Image Processing Libraries

Table of contents introduce 1. Pica 2. Lena.js 3....

Mysql tree-structured database table design

Table of contents Preface 1. Basic Data 2. Inheri...

Super detailed basic JavaScript syntax rules

Table of contents 01 JavaScript (abbreviated as: ...