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

The most common mistakes in HTML tag writing

We better start paying attention, because HTML Po...

Explanation of the basic syntax of Mysql database stored procedures

drop procedure sp_name// Before this, I have told...

jQuery realizes the picture following effect

This article shares the specific code of jQuery t...

What scenarios are not suitable for JS arrow functions?

Table of contents Overview Defining methods on an...

VS2019 connects to mysql8.0 database tutorial with pictures and text

1. First, prepare VS2019 and MySQL database. Both...

Vue implements the magnifying glass effect of tab switching

This article example shares the specific code of ...

MySQL's conceptual understanding of various locks

Optimistic Locking Optimistic locking is mostly i...

VMware virtual machine installation Linux system graphic tutorial

This article shares the specific steps of VMware ...

KVM virtualization installation, deployment and management tutorial

Table of contents 1.kvm deployment 1.1 kvm instal...

Implementation of MySQL index-based stress testing

1. Simulate database data 1-1 Create database and...

How to enable Flash in Windows Server 2016

I recently deployed and tested VMware Horizon, an...

Vue implements scrollable pop-up window effect

This article shares the specific code of Vue to a...

Summary of several principles that should be followed in HTML page output

1. DOCTYPE is indispensable. The browser determin...