Docker安装

安装docker参考安装Docker&Compose

#创建mysql数据卷地址
mkdir -p /opt/server/mysql && cd /opt/server/mysql
#创建docker-compose.yml文件,把密码`MYSQL_ROOT_PASSWORD`项修改下
sudo tee docker-compose.yml <<-'EOF'
version: '3.1'
services:
  db:
    image: biarms/mysql:5.7.30-linux-arm64v8
    restart: always
    container_name: mysql
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=123456
    command:
      --default-authentication-plugin=mysql_native_password
      --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=0
    ports:
      - 3306:3306
    volumes:
      - ./data:/var/lib/mysql
EOF

#启动mysql up->启动 -d 以守护方式运行
docker-compose -f docker-compose.yml up -d

Ubuntu系统直接安装

sudo apt-get update
sudo apt-get install mysql-server
#设置账号密码
sudo mysql_secure_installation utility
#开启自启
sudo systemctl enable mysql
#重启
sudo systemctl restart mysql
#连接mysql
mysql -uroot -p

CentOS 7

安装rpm

yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

安装MySQL

yum -y install mysql-community-server

启动

systemctl start  mysqld.service

查看状态

 systemctl status mysqld.service

查看密码

grep "password" /var/log/mysqld.log

arm64架构

version: '3.1'
services:
  db:
    image: mysql/mysql-server:8.0.22-1.1.18
    restart: always
    container_name: mysql
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=123456
    command:
      --default-authentication-plugin=mysql_native_password
      --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=0
    ports:
      - 3306:3306
    volumes:
      - ./data:/var/lib/mysql
version: '3.1'
services:
  db:
    image: biarms/mysql:5.7.30-linux-arm64v8
    restart: always
    container_name: mysql
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=123456
    command:
      --default-authentication-plugin=mysql_native_password
      --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=0
    ports:
      - 3306:3306
    volumes:
      - /etc/my.cnf:/etc/mysql/my.cnf
      - ./data:/var/lib/mysql

安装主从

Docker 安装 Mysql 主从