当前位置:网站首页>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
边栏推荐
- EPICS记录参考2--EPICS过程数据库概念
- Leetcode algorithm The first common node of two linked lists
- 【nvm】
- STP spanning tree protocol Foundation
- 面试害怕被问MySQL相关问题 ?这份三万字精华总结 + 面试100 问,吊打面试官完全够了
- Memory alignment of structures
- [QT] QT event handling
- EPICS記錄參考3 -- 所有記錄都有的字段
- Virtual private network foundation
- Layer 2 and layer 3 forwarding principle based on VLAN
猜你喜欢
See how sparksql supports enterprise level data warehouse

Solution to the login error of tangdou people
![[untitled]](/img/ed/847e678e5a652da74d04722bbd99ff.jpg)
[untitled]

Chapter 10 project communication management
![[personal experiment report]](/img/04/c9e1bee19bff9d55b73c531f7b17f4.png)
[personal experiment report]

大厂面试必问:如何解决TCP可靠传输问题?8张图带你详细学习

The difference between interceptor and filter

Recommended movies: Northeast tiger, licorice pizza

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

Virtual private network foundation
随机推荐
Research Report on market evaluation and investment direction of Chinese dermatology drugs (2022 Edition)
EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段
ThreadLocal memory leak
OSPF basic content
[untitled]
High level application of SQL statements in MySQL database (I)
问题求解——嵌套列表
加分利器 不负所托 | 知道创宇获攻防演练防守方感谢信!
ACL (access control list) basic chapter - Super interesting learning network
Research Report on market supply and demand and strategy of ceiling power supply device industry in China
Servlet
Chapter 10 project stakeholder management
Can AI chat robots replace manual customer service?
Combine pod identity in aks and secret in CSI driver mount key vault
Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)
docker安装redis-简单而无坑
Learn more about the practical application of sentinel
Parental delegation mechanism
Solve the problem of non secure websites requesting localhost to report CORS after chrome94
Certificate photo processing