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

Solve the problem of Mac Docker x509 certificate

question Recently I needed to log in to a private...

Do you know the weird things in Javascript?

Our veteran predecessors have written countless c...

How to elegantly implement WeChat authorized login in Vue3 project

Table of contents Preface Prepare Implementation ...

HTML page native VIDEO tag hides the download button function

When writing a web project, I encountered an intr...

Description of the hr tag in various browsers

Generally, we rarely meet HR, but once we do, it c...

Create an SSL certificate that can be used in nginx and IIS

Table of contents Creating an SSL Certificate 1. ...

Example of implementing dynamic verification code on a page using JavaScript

introduction: Nowadays, many dynamic verification...

How to allow remote access to open ports in Linux

1. Modify the firewall configuration file # vi /e...

Delegating Privileges in Linux Using Sudo

Introduction to sudo authority delegation su swit...

Use JavaScript to create page effects

11. Use JavaScript to create page effects 11.1 DO...