Refine MySQL status messaging and SQL page copy
This commit is contained in:
+1
-1
@@ -108,7 +108,7 @@ docker compose down -v
|
|||||||
- 直接调用 Compose 内 API 查询 MySQL 主表 `mobilemodels.mm_device_catalog`
|
- 直接调用 Compose 内 API 查询 MySQL 主表 `mobilemodels.mm_device_catalog`
|
||||||
- 服务端先将输入归一化为 `alias_norm`
|
- 服务端先将输入归一化为 `alias_norm`
|
||||||
- 页面展示实际执行的 SQL、返回结果和 JSON
|
- 页面展示实际执行的 SQL、返回结果和 JSON
|
||||||
- 页面同时展示只读连接信息,便于第三方联调
|
- 页面同时展示只读连接参数,便于核对配置
|
||||||
|
|
||||||
### 索引查询
|
### 索引查询
|
||||||
|
|
||||||
|
|||||||
+22
-2
@@ -214,6 +214,20 @@ def run_command(args: list[str]) -> subprocess.CompletedProcess[str]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def sanitize_mysql_message(message: str, host: str | None = None, port: str | None = None) -> str:
|
||||||
|
lines = [line.strip() for line in str(message or "").splitlines() if line.strip()]
|
||||||
|
filtered = [line for line in lines if not line.startswith("WARNING:")]
|
||||||
|
text = "\n".join(filtered or lines)
|
||||||
|
host_text = host or os.environ.get("MYSQL_HOST", "mysql")
|
||||||
|
port_text = port or os.environ.get("MYSQL_PORT", "3306")
|
||||||
|
|
||||||
|
if "Can't connect to server on" in text or "Can't connect to MySQL server on" in text:
|
||||||
|
return f"MySQL 当前无法连接: {host_text}:{port_text}"
|
||||||
|
if "Access denied" in text:
|
||||||
|
return f"MySQL 账号或密码无效: {host_text}:{port_text}"
|
||||||
|
return text or f"MySQL 当前无法连接: {host_text}:{port_text}"
|
||||||
|
|
||||||
|
|
||||||
def normalize_text(text: str) -> str:
|
def normalize_text(text: str) -> str:
|
||||||
return NORMALIZE_RE.sub("", (text or "").lower())
|
return NORMALIZE_RE.sub("", (text or "").lower())
|
||||||
|
|
||||||
@@ -255,7 +269,9 @@ def run_mysql_query(sql: str, database: str | None = None) -> list[dict[str, str
|
|||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
message = proc.stderr.strip() or proc.stdout.strip() or f"mysql exited with {proc.returncode}"
|
message = sanitize_mysql_message(
|
||||||
|
proc.stderr.strip() or proc.stdout.strip() or f"mysql exited with {proc.returncode}"
|
||||||
|
)
|
||||||
raise RuntimeError(message)
|
raise RuntimeError(message)
|
||||||
|
|
||||||
lines = [line for line in proc.stdout.splitlines() if line.strip()]
|
lines = [line for line in proc.stdout.splitlines() if line.strip()]
|
||||||
@@ -369,7 +385,11 @@ def get_status_payload() -> dict[str, object]:
|
|||||||
mysql_ready = True
|
mysql_ready = True
|
||||||
mysql_status = mysql_proc.stdout.strip() or "MySQL ready"
|
mysql_status = mysql_proc.stdout.strip() or "MySQL ready"
|
||||||
else:
|
else:
|
||||||
mysql_status = mysql_proc.stderr.strip() or mysql_proc.stdout.strip() or "MySQL unavailable"
|
mysql_status = sanitize_mysql_message(
|
||||||
|
mysql_proc.stderr.strip() or mysql_proc.stdout.strip() or "MySQL unavailable",
|
||||||
|
host=mysql_host,
|
||||||
|
port=mysql_port,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
mysql_status = "MySQL auto load disabled"
|
mysql_status = "MySQL auto load disabled"
|
||||||
|
|
||||||
|
|||||||
@@ -570,14 +570,13 @@
|
|||||||
<div class="helper-box">
|
<div class="helper-box">
|
||||||
<ul>
|
<ul>
|
||||||
<li>输入客户端原始上报值,服务端会先归一化为 <code>alias_norm</code>,再查询 MySQL。</li>
|
<li>输入客户端原始上报值,服务端会先归一化为 <code>alias_norm</code>,再查询 MySQL。</li>
|
||||||
<li>当前读链路使用只读账号,便于模拟第三方直接查库的效果。</li>
|
<li>当前读链路使用只读账号,便于核对 SQL 查询结果与连接配置。</li>
|
||||||
<li>推荐新接入优先对接 `mm_device_catalog`,兼容链路再使用视图。</li>
|
<li>推荐新接入优先对接 `mm_device_catalog`,兼容链路再使用视图。</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="helper-box">
|
<div class="helper-box">
|
||||||
<p class="helper-title">只读连接信息</p>
|
<p class="helper-title">只读连接参数</p>
|
||||||
<p>可直接用于第三方连库联调。</p>
|
|
||||||
<div id="sqlReadonlyInfo" class="credential-grid">
|
<div id="sqlReadonlyInfo" class="credential-grid">
|
||||||
<div class="credential-item">
|
<div class="credential-item">
|
||||||
<span class="credential-label">Host</span>
|
<span class="credential-label">Host</span>
|
||||||
@@ -1634,8 +1633,8 @@ LIMIT 20;</pre>
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
sqlReadonlyInfoEl.innerHTML = `
|
sqlReadonlyInfoEl.innerHTML = `
|
||||||
<div class="credential-item">
|
<div class="credential-item">
|
||||||
<span class="credential-label">只读连接信息</span>
|
<span class="credential-label">只读连接参数</span>
|
||||||
<p class="credential-value">${escapeHtml(err.message || String(err))}</p>
|
<p class="credential-value">暂时无法读取连接参数</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user