# 错误 1794 (HY000): 从库未正确配置或初始化失败。您必须至少设置 --server-id 以启用主库或从库。

- **ID:** `database/mysql-replica-lag-binlog-not-purged`
- **领域:** database
- **类别:** config_error
- **错误码:** `1794`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

MySQL 复制从库无法启动，因为未设置 server-id 或设置为 0，而复制功能要求必须设置该参数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MySQL 8.0 | active | — | — |
| MySQL 5.7 | active | — | — |
| MariaDB 10.5 | active | — | — |

## 解决方案

1. ```
   Set server-id to a unique positive integer (e.g., 1) in my.cnf under [mysqld] section, then restart MySQL:
[mysqld]
server-id=1
   ```
2. ```
   If MySQL is already running, set server-id dynamically (requires restart for full effect, but can be set at runtime in MySQL 8.0+):
SET GLOBAL server_id = 1;
Then restart the service.
   ```

## 无效尝试

- **Restarting the MySQL service without changing configuration** — The server-id remains 0 or unset after restart; the error persists. (95% 失败率)
- **Setting server-id to 0 explicitly in my.cnf** — MySQL ignores server-id=0 and still requires a positive integer value. (90% 失败率)
- **Resetting replication with RESET SLAVE without fixing server-id** — RESET SLAVE clears replication state but does not change the server-id; error returns on next START SLAVE. (85% 失败率)
