You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.3 KiB
31 lines
1.3 KiB
param()
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
|
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
throw '请在“以管理员身份运行”的 PowerShell 中执行本脚本。'
|
|
}
|
|
|
|
$oldDataDirectory = 'C:\ProgramData\MySQL\MySQL Server 8.4\Data'
|
|
$newDataDirectory = 'D:\MySQL\MySQL Server 8.4\Data'
|
|
$configurationFile = 'C:\ProgramData\MySQL\MySQL Server 8.4\my.ini'
|
|
|
|
if (-not (Test-Path -LiteralPath $oldDataDirectory)) {
|
|
Write-Host 'C 盘旧数据目录已不存在,无需清理。'
|
|
exit 0
|
|
}
|
|
|
|
$resolvedOld = (Resolve-Path -LiteralPath $oldDataDirectory).Path.TrimEnd('\')
|
|
if ($resolvedOld -ne $oldDataDirectory) {
|
|
throw "旧目录安全校验失败:$resolvedOld"
|
|
}
|
|
if (-not (Test-Path -LiteralPath $newDataDirectory)) {
|
|
throw "D 盘活动数据目录不存在:$newDataDirectory"
|
|
}
|
|
$configuredDataDirectory = (Select-String -LiteralPath $configurationFile -Pattern '^datadir=').Line
|
|
if ($configuredDataDirectory -ne 'datadir=D:/MySQL/MySQL Server 8.4/Data') {
|
|
throw "MySQL 配置未指向 D 盘,拒绝清理:$configuredDataDirectory"
|
|
}
|
|
|
|
Remove-Item -LiteralPath $oldDataDirectory -Recurse -Force
|
|
Write-Host 'C 盘旧 MySQL 数据目录已清理。D 盘活动目录和回退副本均未修改。'
|
|
|