当前位置:网站首页>docker安装mysql-简单无坑
docker安装mysql-简单无坑
2022-06-24 19:41:00 【秃了也弱了。】
文章目录
1.切换root用户
2.下载镜像文件
docker pull mysql:5.7
3.创建实例并启动
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
出现一长串的id即表示mysql启动成功
【端口映射与文件挂载】
参数说明
-p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口
-name:容器名称
-v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂载到主机
-v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
-v /mydata/mysql/data:/var/lib/mysql/:将配置文件夹挂载到主机
-e MYSQL_ROOT_PASSWORD=root:初始化 root 用户的密码
-d是后台启动
每个docker都是一个linux系统,所以启动容器时需要将docker的端口映射到linux主机的端口
-v:将linux本地文件与docker的指定文件绑定,修改本地文件会同步docker文件,修改配置就方便多了
4.MySQL 配置
由于使用-v /mydata/mysql/conf:/etc/mysql,将本地conf目录与docker的配置目录绑定,只需要修改linux本地配置即可。
vi /mydata/mysql/conf/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
docker restart mysql 重启mysql
5.提示:解决 MySQL 连接慢的问题
在配置文件中加入如下,并重启 mysql
[mysqld]
skip-name-resolve
解释: skip-name-resolve:跳过域名解析
6.通过容器的 mysql 命令行工具连接
docker exec -it mysql mysql -uroot -proot
7.设置远程访问
grant all privileges on . to ‘root’@‘%’ identified by ‘root’ with grant option; flush privileges;
8.用navicat连接看看吧
默认root用户密码为root
边栏推荐
- Feign project construction
- 详细了解Redis的八种数据类型及应用场景分析
- Solve the problem of non secure websites requesting localhost to report CORS after chrome94
- STP spanning tree protocol Foundation
- Vulnhub Vegeta: 1
- Principle of IP routing
- Certificate photo processing
- [QT] QT event handling
- Virtual private network foundation
- China Sky Lantern market trend report, technical dynamic innovation and market forecast
猜你喜欢

环境配置 | VS2017配置OpenMesh源码和环境

【文本数据挖掘】中文命名实体识别:HMM模型+BiLSTM_CRF模型(Pytorch)【调研与实验分析】

vulnhub Vegeta: 1

详细了解Redis的八种数据类型及应用场景分析

Learn more about the practical application of sentinel

Principles of Ethernet port mirroring, link aggregation and VLAN Technology
![[postgraduate entrance examination English] prepare for 2023, learn list8 words](/img/25/d1f2c2b4c0958d381db87e5ef96df9.jpg)
[postgraduate entrance examination English] prepare for 2023, learn list8 words

See how sparksql supports enterprise data warehouse

Learn more about redis' eight data types and application scenario analysis

JWT(Json Web Token)
随机推荐
In the era of full programming, should I give up this road?
EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段
Combine pod identity in aks and secret in CSI driver mount key vault
加分利器 不负所托 | 知道创宇获攻防演练防守方感谢信!
Memory alignment of structures
Data communication and physical network
倍加福(P+F)R2000修改雷达IP
Cat write multiline content to file
Code farmers should also understand the IPv4 subnet division of point networks
[postgraduate entrance examination English] prepare for 2023, learn list8 words
Leetcode algorithm refers to offer II 027 Palindrome linked list
证件照处理
【武汉大学】考研初试复试资料分享
AttacKG: Constructing Technique Knowledge Graph from Cyber Threat Intelligence Reports代码复现
Heavyweight! Fada is listed as a "specialized and new" enterprise
[Software Engineering] key points at the end of the period
【nvm】
The difference between get and post
Learning bit segment (1)
JWT(Json Web Token)