Docker安装Mysql5.7.31

Docker安装Mysql5.7.31

创建MySQL安装目录

mkdir -p /opt/mysql/{data,conf,logs}

创建my.cnf

tee /opt/mysql/conf/my.cnf <<EOF
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
# 设置3306端口
port = 3306
# 允许最大连接数
max_connections=1000
# innodb的dml操作的行级锁的等待时间
innodb_lock_wait_timeout=500
# 设置mysql服务端默认字符集
character-set-server=utf8mb4
# 默认创建新数据的新建排序规则
collation-server=utf8mb4_general_ci
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 缓存大小
sort_buffer_size=256MB
# 大小写敏感配置项0为敏感,1为不敏感
lower_case_table_names=1
# 选择正8区
default-time-zone='+8:00'
[client]
# mysql默认字符集
default-character-set=utf8mb4
[mysql]
# mysql默认字符集
default-character-set=utf8
EOF

创建mysql5.7.31-docker-compose.yaml

tee /opt/mysql/mysql5.7.31-docker-compose.yaml <<EOF
version: '3.3'
services:
  mysql-app:
    image: 'mysql:5.7.31'
    container_name: 'mysql5.7.31'
    restart: always
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: root  # root用户的密码
      MYSQL_ROOT_HOST: '%'       # 访问权限
      MYSQL_USER: dev            # 创建新用户
      MYSQL_PASSWORD: dev        # 新用户的密码
    volumes:
      - '/etc/localtime:/etc/localtime:ro'   # 同步宿主机日期时间到容器
      - '/opt/mysql/data:/var/lib/mysql'     # 数据目录
      - '/opt/mysql/conf/my.cnf:/etc/my.cnf' # 配置文件
      - '/opt/mysql/conf:/etc/mysql/conf.d'  # 挂载配置文件目录
      - '/opt/mysql/logs:/logs'
    command: [
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_general_ci',
        '--max_connections=3000',
        '--default-authentication-plugin=mysql_native_password'
    ]
    # default-authentication-plugin=mysql_native_password mysql5为mysql_native_password, 支持较好, mysql8为默认为caching_sha2_password, 部分旧软件不支持;
EOF

安装部署

docker-compose -f /opt/mysql/mysql5.7.31-docker-compose.yaml pull
docker-compose -f /opt/mysql/mysql5.7.31-docker-compose.yaml up -d

创建数据库、创建用户、用户授权数据库所有权限

create database databasir;
-- create user dev@'%' identified by 'dev';
grant all privileges on databasir.* to dev;

引用 Reference

Kubernetes 1.25.4版本安装
kubeasz安装kubernetes1.25.5
CentOS8搭建nfs服务
k8s一键安装redis单机版
k8s一键安装mysql8单机版
Docker制作springboot运行应用镜像
k8s部署springboot应用
zookeeper集群安装
Nginx日志切割
Elasticsearch单机版本安装
Elasticsearch集群安装
springboot集成prometheus+grafana
安装Docker及学习
RabbitMQ集群安装
Docker安装Mysql5.7.31

你可能感兴趣的:(mysql,linux,docker,数据库)