docker安装mysql5.7及8.0、redis

一、mysql 

docker run -p 3306:3306 \
           --name mysql-master \
           --privileged=true \
           -v /app/mysql/log:/var/log/mysql \
           -v /app/mysql/data:/var/lib/mysql \
           -v /app/mysql/conf:/etc/mysql \
           -e MYSQL_ROOT_PASSWORD=root \
           -d mysql:5.7;

在/app/mysql/conf下新建my.cnf文件,内容如下,解决中文乱码问题:

[client]
default_character_set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8

重启mysql容器

docker restart mysql

注意:在进入mysql容器内,登录mysql,使用以下命令查看字符编码是否修改成功:

show variables like 'character%';

docker安装mysql5.7及8.0、redis_第1张图片

mysql8安装如下:

docker run \
    -p 3306:3306 \
    -e MYSQL_ROOT_PASSWORD=root  \
    -v /xh/mysql/data:/var/lib/mysql:rw \
    -v /xh/mysql//log:/var/log/mysql:rw \
    -v /xh/mysql/conf/my.cnf:/etc/mysql/my.cnf:rw \
    -v /etc/localtime:/etc/localtime:ro  \
    --name mysql8 \
    --restart=always \
    -d mysql:8.0.30

更改加密方式、刷新权限

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
flush privileges;

 二、redis

docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name redis -v /app/redis/redis.conf:/etc/redis/redis.conf -v /app/redis/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass 1234

redis.conf文件

# bind 127.0.0.1

protected-mode no

port 6379

tcp-backlog 511

requirepass 1234

timeout 0

tcp-keepalive 300

daemonize no

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile ""

databases 30

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir ./

replica-serve-stale-data yes

replica-read-only yes

repl-diskless-sync no

repl-disable-tcp-nodelay no

replica-priority 100

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

appendonly yes

appendfilename "appendonly.aof"

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble yes

lua-time-limit 5000

slowlog-max-len 128

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

stream-node-max-bytes 4096
stream-node-max-entries 100

activerehashing yes

hz 10

dynamic-hz yes

aof-rewrite-incremental-fsync yes

rdb-save-incremental-fsync yes


你可能感兴趣的:(docker,docker,redis)