58 lines
2.3 KiB
PowerShell
58 lines
2.3 KiB
PowerShell
# MySQL 数据库初始化脚本
|
||
# 使用方法: .\init-mysql.ps1
|
||
|
||
$MYSQL_HOST = "101.132.182.216"
|
||
$MYSQL_PORT = "3306"
|
||
$MYSQL_USER = "sc_root"
|
||
$MYSQL_PASSWORD = "Shsc#$@2024#@!"
|
||
|
||
Write-Host "正在初始化 MySQL 数据库..." -ForegroundColor Yellow
|
||
Write-Host "服务器: ${MYSQL_HOST}:${MYSQL_PORT}" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 读取 SQL 文件内容
|
||
$sqlContent = Get-Content -Path "init-database.sql" -Raw
|
||
|
||
# 将 SQL 内容分割成单独的语句
|
||
$statements = $sqlContent -split ";"
|
||
|
||
Write-Host "准备执行 SQL 语句..." -ForegroundColor Yellow
|
||
|
||
# 使用 .NET MySQL 连接器(如果可用)或提供手动执行说明
|
||
Write-Host ""
|
||
Write-Host "请选择执行方式:" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "1. 如果你有 MySQL 命令行工具,请执行:" -ForegroundColor Cyan
|
||
Write-Host " mysql -h $MYSQL_HOST -P $MYSQL_PORT -u $MYSQL_USER -p" -ForegroundColor White
|
||
Write-Host " 然后手动复制执行 init-database.sql 的内容" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "2. 或者使用 MySQL Workbench / Navicat:" -ForegroundColor Cyan
|
||
Write-Host " - 连接到: ${MYSQL_HOST}:${MYSQL_PORT}" -ForegroundColor White
|
||
Write-Host " - 用户名: $MYSQL_USER" -ForegroundColor White
|
||
Write-Host " - 密码: $MYSQL_PASSWORD" -ForegroundColor White
|
||
Write-Host " - 打开并执行 init-database.sql" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "3. 或者复制以下 SQL 到 MySQL 客户端执行:" -ForegroundColor Cyan
|
||
Write-Host "----------------------------------------" -ForegroundColor DarkGray
|
||
Write-Host $sqlContent -ForegroundColor White
|
||
Write-Host "----------------------------------------" -ForegroundColor DarkGray
|
||
Write-Host ""
|
||
|
||
$choice = Read-Host "数据库初始化完成后,按 Enter 继续部署 API 容器..."
|
||
|
||
Write-Host ""
|
||
Write-Host "正在部署 API 容器..." -ForegroundColor Yellow
|
||
docker-compose down
|
||
docker-compose up --build -d
|
||
|
||
if ($LASTEXITCODE -eq 0) {
|
||
Write-Host ""
|
||
Write-Host "部署完成!" -ForegroundColor Green
|
||
Write-Host "API 地址: http://localhost:5000" -ForegroundColor Cyan
|
||
Write-Host "Swagger: http://localhost:5000/swagger" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
Write-Host "查看日志: docker logs petwash-api -f" -ForegroundColor Yellow
|
||
} else {
|
||
Write-Host "部署失败" -ForegroundColor Red
|
||
}
|