#!/bin/bash # ============================================================ # 业务数据库账号与附加库 # 由 MySQL 容器 docker-entrypoint-initdb.d 在首次启动时执行。 # # 为什么用 .sh 而不是 .sql: # MySQL 官方镜像的 initdb 脚本无法在 SQL 里读环境变量, # 而账号口令必须从 .env 注入,不能写死在仓库里。 # ============================================================ set -euo pipefail if [ -z "${MYSQL_APP_PASSWORD:-}" ]; then echo "[initdb] 错误:未设置 MYSQL_APP_PASSWORD" >&2 exit 1 fi mysql --protocol=socket -uroot -p"${MYSQL_ROOT_PASSWORD}" <