Docker安装与启动MySQL5.7(完全照我的步骤一定没问题)
很久没更新博客了,最近在准备实习生春招,面了好多公司,也凉了好多公司,太难了呀
1.确保自己的Linux虚拟机上有Docker环境
首先来安装Docker:
(1)使用yum源安装
yum -y install docker
(2)启动docker
systemctl start docker
(3)查看docker服务状态
systemctl status docker
(4)配置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://3huzqv5x.mirror.aliyuncs.com"] } EOF
(5)重启Docker
sudo systemctl daemon-reload
sudo systemctl restart docker
2.使用Docker安装MySQL5.7
(1)下载 MySQL5.7 镜像
docker pull mysql:5.7
(2)启动容器
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
(3)修改配置文件
vi /mydata/mysql/conf/my.cnf
在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
(4)重启
docker restart mysql
(5)进入MySQL5.7容器
docker exec -it mysql /bin/bash
(6)查看是否成功修改
cat /etc/mysql/my.cnf
7)在本地使用Navicat工具测试连接
大功告成~