1. 通过docker命令下载mysql5.7镜像
mysql5.7前期准备
在Linux虚拟机上创建一个文件夹用来持久化数据库的数据配置以及日志,Redis的启动配置文件和数据
mkdir /var/mydata
cd /var/mydata/
mkdir mysql/conf
mkdir mysql/log
mkdir mysql/data
touch mysql/conf/my.cnf
docker run \
--name mysql-5.7 \
--restart always \
-p 3306:3306 \
-v /var/mydata/mysql/log:/var/log/mysql \
-v /var/mydata/mysql/conf/my.cnf:/etc/mysql/my.cnf \
-v /var/mydata/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="123456" \
-d mysql:5.7
2. 通过docker命令下载mysql8.0镜像
mysql8.0前期准备
cd /var/mydata/mysql/
mkdir 8.0
cd 8.0/
mkdir conf data log
cd conf/
touch my.cnf
执行命令启用docker
docker run \
--name mysql-8.0 \
--restart always \
-p 3307:3306 \
-v /var/mydata/mysql/8.0/log:/var/log/mysql \
-v /var/mydata/mysql/8.0/conf/my.cnf:/etc/mysql/my.cnf \
-v /var/mydata/mysql/8.0/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="123456" \
-d mysql:8.0
远程mysql(linux,docker中),需要设置远程访问权限
docker exec -it mysql-8.0 /bin/sh
#进入到mysql
mysql -uroot -p
# 修改加密规则(非必须)
alter user 'root'@'%' identified by '123456' password expire never;
# 更新用户的密码
alter user 'root'@'%' identified with mysql_native_password by '123456';
# 刷新权限
flush privileges;
# 重置密码(==非必须==)
alter user 'root'@'%' identified by '123456';
3. 通过docker命令下载redis镜像
redis前期准备
mkdir /var/mydata/redis/
cd /var/mydata/redis/
mkdir conf data
cd conf/
touch redis.conf
执行命令启用docker
docker run \
--name redis \
--restart always \
-p 6379:6379 \
-v /var/mydata/redis/data:/data \
-v /var/mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf
#启用redis适用/etc/redis/redis.conf配置文件启用redis
用命令客户端进入
docker exec -it redis redis-cli
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
"b"
127.0.0.1:6379>
用客户端工具链接查看
```
```
本文永久更新地址:
https://www.fenxiangbe.com/p/在docker上安装MySQL和Redis.html
标签:mydata,Redis,MySQL,redis,conf,mysql,var,docker From: https://www.cnblogs.com/fenxiangbe/p/17252912.html