Hide MySQL password setup console windows
This commit is contained in:
@@ -244,7 +244,8 @@ def configure_mysql_weak_password_policy(
|
||||
) -> None:
|
||||
on_output("正在连接 MySQL,并永久启用 6 位弱密码策略...")
|
||||
variables_result: subprocess.CompletedProcess[str] | None = None
|
||||
for attempt in range(max(attempts, 1)):
|
||||
total_attempts = max(attempts, 1)
|
||||
for attempt in range(total_attempts):
|
||||
variables_result = _run_mysql_sql(
|
||||
mysql_executable,
|
||||
"SHOW VARIABLES LIKE 'validate_password%';",
|
||||
@@ -252,7 +253,12 @@ def configure_mysql_weak_password_policy(
|
||||
)
|
||||
if variables_result.returncode == 0:
|
||||
break
|
||||
if attempt + 1 < max(attempts, 1):
|
||||
error_text = f"{variables_result.stderr}\n{variables_result.stdout}".lower()
|
||||
if "access denied" in error_text or "error 1045" in error_text:
|
||||
break
|
||||
if attempt + 1 < total_attempts:
|
||||
if attempt == 0 or (attempt + 1) % 5 == 0:
|
||||
on_output(f"MySQL 服务尚未就绪,正在后台重试({attempt + 1}/{total_attempts})...")
|
||||
time.sleep(retry_delay)
|
||||
|
||||
assert variables_result is not None
|
||||
@@ -493,6 +499,7 @@ def _read_install_log_tail(log_path: Path, max_lines: int = 20) -> str:
|
||||
def _run_mysql_sql(mysql_executable: Path, sql: str, password: str) -> subprocess.CompletedProcess[str]:
|
||||
environment = os.environ.copy()
|
||||
environment["MYSQL_PWD"] = password
|
||||
creation_flags = getattr(subprocess, "CREATE_NO_WINDOW", 0) if os.name == "nt" else 0
|
||||
return subprocess.run(
|
||||
[
|
||||
str(mysql_executable),
|
||||
@@ -508,6 +515,7 @@ def _run_mysql_sql(mysql_executable: Path, sql: str, password: str) -> subproces
|
||||
timeout=15,
|
||||
shell=False,
|
||||
env=environment,
|
||||
creationflags=creation_flags,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user