当前位置:网站首页>[玩转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
参考资料 & 致谢
边栏推荐
- Pytorch common loss function
- 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
- 零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
- 学习探索-函数防抖
- R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ
- MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!
- Word如何显示修改痕迹
- Tensorflow and torch code verify whether CUDA is successfully installed
- Benefit a lot, Android interview questions
- Synchronous development of business and application: strategic suggestions for application modernization
猜你喜欢
How word displays modification traces
[translation] a GPU approach to particle physics
IC设计流程中需要使用到的文件
ROS自定义消息发布订阅示例
CCNP Part 11 BGP (III) (essence)
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
An error occurs when installing MySQL: could not create or access the registry key needed for the
Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion
Spark foundation -scala
Low CPU load and high loadavg processing method
随机推荐
深入分析,Android面试真题解析火爆全网
ZABBIX proxy server and ZABBIX SNMP monitoring
Druid database connection pool details
Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
Tensorflow and torch code verify whether CUDA is successfully installed
面试突击63:MySQL 中如何去重?
R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
JDBC详解
Based on butterfly species recognition
CPU负载很低,loadavg很高处理方法
Dark horse -- redis
MATLAB中deg2rad和rad2deg函数的使用
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
In depth analysis, Android interview real problem analysis is popular all over the network
Analysis of frequent chain breaks in applications using Druid connection pools
Don't miss this underestimated movie because of controversy!
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
Synchronous development of business and application: strategic suggestions for application modernization
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ