当前位置:网站首页> Docker部署Mysql8的实现步骤
Docker部署Mysql8的实现步骤
2022-07-06 20:41:00 【1024问】
一、前置需求
二、部署方法
三、访问测试
一、前置需求1.linux系统
本人用的Centos7
2.安装docker
参考这篇文章
二、部署方法1.拉取mysql8镜像
docker pull mysql:8
2.创建配置文件挂载目录和数据挂载目录
mkdir -p /usr/mysql/conf /usr/mysql/datachmod -R 755 /usr/mysql/
ps:
/home/mysql/config:放mysql配置文件my.conf
/home/mysql/data:放mysql数据
3.创建配置文件
vim /usr/mysql/conf/my.cnf
内容如下
[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.启动容器并挂载目录
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 本机的MySQL配置文件映射到容器的MySQL配置文件
-v /etc/localtime:/etc/localtime:ro 本机时间与数据库时间同步
–restart=always 当重启Docker时会自动启动该容器
-d : 后台运行
-p 端口映射 宿主机端口号:容器端口号
-e 环境参数,MYSQL_ROOT_PASSWORD设置root用户的密码
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.进入mysql创建用户
<1>进入容器
docker exec -it mysql8 /bin/bash
<2>进入mysql
mysql -uroot -p123456
<3>创建用户
我这里创建一个叫 python 的用户
# 创建 python 用户,密码为123456,允许在任意机器上登录CREATE USER 'python'@'%' IDENTIFIED BY '123456';
<4>赋予权限
# 赋予 python 用户在 所有机器上 对 所有数据库和数据表 拥有 所有操作权限GRANT ALL ON *.* TO 'python'@'%';
三、访问测试连接成功
到此这篇关于Docker部署Mysql8的实现步骤的文章就介绍到这了,更多相关Docker部署Mysql8内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- Clock in during winter vacation
- 哈夫曼树基本概念
- Search of linear table
- 存储过程与函数(MySQL)
- 卡尔曼滤波-1
- What is Ba? How about Ba? What is the relationship between Ba and Bi?
- [security attack and Defense] how much do you know about serialization and deserialization?
- Set static IP for raspberry pie
- [safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
- 概率论公式
猜你喜欢
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
[safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
QT 打开文件 使用 QFileDialog 获取文件名称、内容等
Depth analysis of compilation constants, classloader classes, and system class loaders
R data analysis: how to predict Cox model and reproduce high score articles
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
1200.Minimum Absolute Difference
Shangsilicon Valley JVM Chapter 1 class loading subsystem
Set WiFi automatic connection for raspberry pie
随机推荐
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
密码学系列之:在线证书状态协议OCSP详解
Free PHP online decryption tool source code v1.2
Leetcode-02 (linked list question)
[security attack and Defense] how much do you know about serialization and deserialization?
My brave way to line -- elaborate on what happens when the browser enters the URL
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
Restcloud ETL Community Edition June featured Q & A
VHDL implementation of single cycle CPU design
变量、流程控制与游标(MySQL)
Shangsilicon Valley JVM Chapter 1 class loading subsystem
VHDL implementation of arbitrary size matrix multiplication
华为小米互“抄作业”
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
哈夫曼树基本概念
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
SSL证书部署
Lab1 configuration script
Search of linear table