当前位置:网站首页>[玩转Linux] [Docker] MySQL安装和配置
[玩转Linux] [Docker] MySQL安装和配置
2022-07-06 11:33:00 【0xYGC】
简介
不建议在docker里运行MySQL数据库软件,仅当测试或数据重要性不高时使用。生产环境推荐安装到KVM
方法 / 步骤
一:安装MySQL
# 查看docker版本
docker -v
--------------------------------------------
[[email protected] /]# docker -v
Docker version 1.13.1, build 7d71120/1.13.1
--------------------------------------------
1.1 搜索查看可用的MySQL
docker search mysql

1.2 拉取MySQL镜像
# 指定版本
docker pull mysql:5.7
#最新版本
docker pull mysql:latest

1.3 查看本地镜像
docker images
--------------------------------------------------------------------------------------------
[[email protected] /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/mysql 5.7 efa50097efbd 7 days ago 462 MB
--------------------------------------------------------------------------------------------
1.4运行容器
默认端口号 5306
注意docker 参数应该排在MySQL参数之前
docker run \
-p 5306:3306 \
--privileged=true \
--name mysql5306 \
-v /docker/mysql5306/conf:/etc/mysql/conf.d \
-v/docker/mysql5306/logs:/logs \
-v/docker/mysql5306/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=useradmin \
-d mysql:5.7
- 运行成功

二: 修改Docker (MySQL)相关配置
找到容器的配置目录
笔者的配置目录/docker/mysql5306/conf
编辑 my.cnf 文件如果没有就创建一个
- 默认配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#数据库默认字符集
character-set-server = utf8mb4
#数据库字符集对应一些排序等规则,注意要和character-set-server对应
collation-server = utf8mb4_general_ci
#设置client连接mysql时的字符集,防止乱码
init_connect=‘SET NAMES utf8mb4‘
#是否对sql语句大小写敏感,1表示不敏感
lower_case_table_names = 1
- 重启容器
docker restart [目标容器id]
三:删除Docker容器
# 查看docker 容器日志,
docker logs ${id}
# 一、查看容器,复制容器id 即container id
docker ps -a
# 二、停止容器
docker stop 你的容器id
# 三、重启容器
docker restart 你的容器id
#三、删除容器
docker rm 容器id
#四、查看镜像,复制镜像id即images id
docker images
#五。删除镜像
docker rmi 镜像id
参考资料 & 致谢
边栏推荐
- R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
- Translation D28 (with AC code POJ 26:the nearest number)
- R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置add参数为不同水平点状条带图添加箱图
- Spark foundation -scala
- Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
- short i =1; i=i+1与short i=1; i+=1的区别
- R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
- R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
- The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
- Simple understanding of MySQL database
猜你喜欢

Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting

RT-Thread 组件 FinSH 使用时遇到的问题

业务与应用同步发展:应用现代化的策略建议

包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链

The list of people who passed the fifth phase of personal ability certification assessment was published

Graffiti intelligence is listed on the dual main board in Hong Kong: market value of 11.2 billion Hong Kong, with an annual revenue of 300 million US dollars

潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe

反射及在运用过程中出现的IllegalAccessException异常

Abstract classes and abstract methods

Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
随机推荐
R language uses rchisq function to generate random numbers that conform to Chi square distribution, and uses plot function to visualize random numbers that conform to Chi square distribution
The nearest library of Qinglong panel
史上超级详细,想找工作的你还不看这份资料就晚了
Modulenotfounderror: no module named 'PIL' solution
[translation] a GPU approach to particle physics
Analysis of frequent chain breaks in applications using Druid connection pools
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
R语言ggplot2可视化:使用ggpubr包的ggdotplot函数可视化点阵图(dot plot)、设置palette参数设置不同水平点阵图数据点和箱图的颜色
C language daily practice - day 22: Zero foundation learning dynamic planning
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the grouped dot strip plot, and set the add parameter to add box plots for different levels of dot strip
数学知识——高斯消元(初等行变换解方程组)代码实现
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
通俗的讲解,带你入门协程
RT-Thread 组件 FinSH 使用时遇到的问题
zabbix 代理服务器 与 zabbix-snmp 监控
Problems encountered in using RT thread component fish
黑马--Redis篇
The list of people who passed the fifth phase of personal ability certification assessment was published