当前位置:网站首页>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
边栏推荐
- OSPF basic content
- JMM 最最最核心的概念:Happens-before 原则
- Research Report on solar battery charger industry - market status analysis and development prospect forecast
- 2022-06-10 工作记录--JS-获取到某一日期N天后的日期
- cat写多行内容到文件
- O (n) complexity hand tear sorting interview questions | an article will help you understand counting sorting
- [postgraduate entrance examination English] prepare for 2023, learn list9 words
- 2022年高处安装、维护、拆除考试模拟100题及模拟考试
- Common sense of resolution
- Recommended movies: Northeast tiger, licorice pizza
猜你喜欢
![[untitled]](/img/ed/847e678e5a652da74d04722bbd99ff.jpg)
[untitled]

2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)

Spark 离线开发框架设计与实现

Programmers become gods by digging holes in one year, carrying flags in five years and becoming gods in ten years

【Mongodb】READ_ ME_ TO_ RECOVER_ YOUR_ Data, the database is deleted maliciously

2022-06-10 工作记录--JS-获取到某一日期N天后的日期

【武汉大学】考研初试复试资料分享
![[postgraduate entrance examination English] prepare for 2023, learn list8 words](/img/25/d1f2c2b4c0958d381db87e5ef96df9.jpg)
[postgraduate entrance examination English] prepare for 2023, learn list8 words

动态菜单,自动对齐

Chapter 10 project communication management
随机推荐
Principles of Ethernet port mirroring, link aggregation and VLAN Technology
Servlet
China solar thermal market trend report, technical dynamic innovation and market forecast
Envoy obtain the real IP address of the client
CDN principle
MySQL + JSON = King fried!!
Idea close global search box
Solution to the login error of tangdou people
Basic principles of spanning tree protocol
【軟件工程】期末重點
【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除
AttacKG: Constructing Technique Knowledge Graph from Cyber Threat Intelligence Reports代码复现
Can AI chat robots replace manual customer service?
别再乱用了,这才是 @Validated 和 @Valid 的真正区别!!!
问题求解——嵌套列表
Tetris
Learn more about the practical application of sentinel
Rip protocol of dynamic routing protocol
CDN principle
Combine pod identity in aks and secret in CSI driver mount key vault