docker-compose 安装部署 mysql

2023-02-18 16:17:42 浏览数 (1)

配置准备

docker 和 docker-compose 安装

https://cloud.tencent.com/developer/article/2219506

创建 mysql主目录

代码语言:javascript复制
mkdir /usr/local/mysql
cd /usr/local/mysql

创建 mysql 的子目录

代码语言:javascript复制
mkdir conf data logs

conf 下 my.conf 配置文件

代码语言:javascript复制
[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
 
[mysqld]
skip-grant-tables
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names=1

sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
 
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci

max_connections = 1000

net_read_timeout=3600
net_write_timeout=3600

部署容器

创建 docker-compose.yml 文件

代码语言:javascript复制
version: '3.1'
services:
  db:
    image: mysql:5.7 #mysql版本
    volumes:
      - ./data/db:/var/lib/mysql
      - ./conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
    restart: always
    ports:
      - 13306:3306
    environment:
      MYSQL_ROOT_PASSWORD: 123abc #访问密码
      secure_file_priv:

启动容器

代码语言:javascript复制
cd /usr/local/mysql
docker-compose up -d

0 人点赞