当前位置:网站首页>Implementation steps of docker deploying mysql8

Implementation steps of docker deploying mysql8

2022-07-07 03:44:00 1024 questions

Catalog

One 、 Pre demand

Two 、 Deployment method

3、 ... and 、 Access test

One 、 Pre demand

1.linux System

I use the Centos7

2. install docker

Refer to this article

Two 、 Deployment method

1. Pull mysql8 Mirror image

docker pull mysql:8

2. Create profile mount directory and data mount directory

mkdir -p /usr/mysql/conf /usr/mysql/datachmod -R 755 /usr/mysql/

ps:
/home/mysql/config: discharge mysql The configuration file my.conf
/home/mysql/data: discharge mysql data

3. create profile

vim /usr/mysql/conf/my.cnf

The contents are as follows

[client]#socket = /usr/mysql/mysqld.sockdefault-character-set = utf8mb4[mysqld]#pid-file = /var/run/mysqld/mysqld.pid#socket = /var/run/mysqld/mysqld.sock#datadir = /var/lib/mysql#socket = /usr/mysql/mysqld.sock#pid-file = /usr/mysql/mysqld.piddatadir = /usr/mysql/datacharacter_set_server = utf8mb4collation_server = utf8mb4_binsecure-file-priv= NULL# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Custom config should go here!includedir /etc/mysql/conf.d/

4. Start the container and mount the directory

docker run --name mysql8 --restart=always -v /usr/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /usr/mysql/data:/var/lib/mysql -v /etc/localtime:/etc/localtime:ro -p 4706:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8

ps:
-v /usr/mysql/conf/my.cnf:/etc/mysql/my.cnf Native MySQL The configuration file is mapped to the container MySQL The configuration file
-v /etc/localtime:/etc/localtime:ro The local time is synchronized with the database time
–restart=always When restarting Docker The container will be started automatically
-d : Background operation
-p Port mapping Host port number : Container port number
-e Environmental parameters ,MYSQL_ROOT_PASSWORD Set up root User's password
docker run -p 60306:3306 -e MYSQL_ROOT_PASSWORD=123 -v /etc/my.cnf:/etc/mysql/my.cnf:rw -v /etc/localtime:/etc/localtime:ro --name mysql8 --restart=always -dit mysql

5. Get into mysql Create user

<1> Into the container

docker exec -it mysql8 /bin/bash

<2> Get into mysql

mysql -uroot -p123456

<3> Create user

I'll create one here called python Users of

# establish python user , The password for 123456, Allow login on any machine CREATE USER 'python'@'%' IDENTIFIED BY '123456';

<4> To give permission

# give python The user is in On all machines Yes All databases and data tables Have All operation rights GRANT ALL ON *.* TO 'python'@'%'; 3、 ... and 、 Access test

Successful connection

This is about Docker Deploy Mysql8 This is the end of the article on the implementation steps of , More about Docker Deploy Mysql8 Please search the previous articles of software development network or continue to browse the relevant articles below. I hope you will support software development network more in the future !


原网站

版权声明
本文为[1024 questions]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207062041168130.html