MySQL Setup

验证:未记录
适用版本
未记录
验证范围
尚未登记验证记录。

本文缩写(英文全称与中文含义)
缩写 英文全称/名称 中文含义
HA High Availability 高可用
K8S Kubernetes 容器编排平台;8 表示 K 与 s 之间的八个字母
SQL Structured Query Language 结构化查询语言
VM Virtual Machine 虚拟机
https://dev.mysql.com/doc/refman/8.4/en/installing.html
https://dev.mysql.com/doc/refman/8.4/en/data-directory-initialization.html
https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html
https://dev.mysql.com/doc/refman/8.4/en/mysqld.html

1. Linux VM With systemd#

install packages:
    mysql-server or distribution package

directories:
    datadir
    log dir
    socket dir

config file:
    /etc/my.cnf
    /etc/mysql/my.cnf
    /etc/mysql/mysql.conf.d/mysqld.cnf

users/secrets:
    root or administrative account password
    application accounts created after bootstrap

systemd:
    systemctl enable mysqld
    systemctl start mysqld
    systemctl status mysqld

logs:
    journalctl -u mysqld
    mysqld error log

常见初始化动作:

mysqld --initialize
mysqld --initialize-insecure
mysql_secure_installation
note:
    initialize-insecure creates an initial data directory without a root password
    production usually prefers the secure initialization path

2. Docker#

单容器初始化密码只用于独立开发环境;生产密码不写镜像,持久数据卷与账号权限另行管理。

local dev:
    use official mysql image or a pinned image tag

compose example:
    mount a persistent volume for datadir
    pass root password and initial database only for dev

persistent volume:
    keep /var/lib/mysql outside container lifecycle

security notes:
    do not bake passwords into image
    do not publish MySQL port to the public internet without protection

本地隔离学习命令;密码文件由秘密系统投递或使用 openssl rand 创建,权限 600,禁止提交 Git:

export MYSQL_PASSWORD_FILE=/secure/mysql-root-password
export MYSQL_IMAGE=REPLACE_APPROVED_MYSQL_IMAGE_AT_DIGEST
docker run --name mysql8 -e MYSQL_ROOT_PASSWORD_FILE=/run/secrets/root-password -v "$MYSQL_PASSWORD_FILE:/run/secrets/root-password:ro" -e MYSQL_DATABASE=shop -p 127.0.0.1:3306:3306 -v mysql8-data:/var/lib/mysql -d "$MYSQL_IMAGE"

3. K8S With Helm#

chart options:
    evaluate community chart vs vendor-supported chart carefully

install commands:
    pin version and set persistence, resources, auth, and backups

values that matter:
    persistence
    primary resources
    replica count
    auth / secrets
    backup hook or sidecar

network policy / service:
    restrict MySQL access to application namespaces only

4. High Availability#

HA architecture:
    primary + replica
    orchestrator / group replication / managed service

failover behavior:
    document read/write endpoint behavior
    verify application reconnect logic

quorum/cluster notes:
    understand who decides primary
    understand how writes are blocked during failover

backup is not HA:
    backup restores data
    HA keeps service running

5. Operations#

rolling restart:
    verify client reconnect handling

upgrade:
    test on a clone first
    verify SQL mode, auth plugin, and character set changes

useful commands:
    mysqladmin ping
    mysqladmin status
    mysqladmin processlist
    SHOW VARIABLES LIKE 'version%';

完整生产实操#

部署、权限、故障与独立恢复提供本模块选定路径的分步实现和验收,补充本页安装参考。

搜索文档

输入关键词,搜索所有文档。

↑ ↓ 选择 · Enter 打开 · Esc 关闭