Resume MySQL setup without reinstalling server
This commit is contained in:
@@ -244,6 +244,7 @@ def configure_mysql_weak_password_policy(
|
||||
) -> None:
|
||||
on_output("正在连接 MySQL,并永久启用 6 位弱密码策略...")
|
||||
variables_result: subprocess.CompletedProcess[str] | None = None
|
||||
active_password = initial_password
|
||||
total_attempts = max(attempts, 1)
|
||||
for attempt in range(total_attempts):
|
||||
variables_result = _run_mysql_sql(
|
||||
@@ -255,6 +256,15 @@ def configure_mysql_weak_password_policy(
|
||||
break
|
||||
error_text = f"{variables_result.stderr}\n{variables_result.stdout}".lower()
|
||||
if "access denied" in error_text or "error 1045" in error_text:
|
||||
configured_result = _run_mysql_sql(
|
||||
mysql_executable,
|
||||
"SHOW VARIABLES LIKE 'validate_password%';",
|
||||
final_password,
|
||||
)
|
||||
if configured_result.returncode == 0:
|
||||
variables_result = configured_result
|
||||
active_password = final_password
|
||||
on_output("检测到 root 已使用默认密码,继续校验弱密码策略...")
|
||||
break
|
||||
if attempt + 1 < total_attempts:
|
||||
if attempt == 0 or (attempt + 1) % 5 == 0:
|
||||
@@ -296,7 +306,7 @@ def configure_mysql_weak_password_policy(
|
||||
configure_result = _run_mysql_sql(
|
||||
mysql_executable,
|
||||
";\n".join(statements) + ";\n",
|
||||
initial_password,
|
||||
active_password,
|
||||
)
|
||||
if configure_result.returncode != 0:
|
||||
detail = _process_error(configure_result)
|
||||
@@ -318,6 +328,11 @@ def install_mysql(
|
||||
open_url = opener or urllib.request.urlopen
|
||||
install_log = Path(log_path) if log_path is not None else default_mysql_install_log_path()
|
||||
server_install_log = install_log.with_name("mysql-server-install.log")
|
||||
existing_executable = find_mysql_executable()
|
||||
if existing_executable is not None:
|
||||
on_output(f"检测到已安装的 MySQL,跳过 Server 安装: {existing_executable}")
|
||||
configure_mysql_weak_password_policy(existing_executable, on_output)
|
||||
return existing_executable
|
||||
console = find_mysql_installer_console()
|
||||
if console is None:
|
||||
install_log.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user