1794 database config_error ai_generated true

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

ERROR 1794 (HY000): Slave is not configured or failed to initialize properly. You must at least set --server-id to enable either a master or a slave.

ID: database/mysql-replica-lag-binlog-not-purged

其他格式: JSON · Markdown 中文 · English
95%修复率
85%置信度
1证据数
2023-09-15首次发现

版本兼容性

版本状态引入弃用备注
MySQL 8.0 active
MySQL 5.7 active
MariaDB 10.5 active

根因分析

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

English

MySQL replication slave fails to start because the server-id is not set or is set to 0, which is required for replication to function.

generic

官方文档

https://dev.mysql.com/doc/refman/8.0/en/replication-options.html#option_mysqld_server-id

解决方案

  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.

无效尝试

常见但无效的做法:

  1. Restarting the MySQL service without changing configuration 95% 失败

    The server-id remains 0 or unset after restart; the error persists.

  2. Setting server-id to 0 explicitly in my.cnf 90% 失败

    MySQL ignores server-id=0 and still requires a positive integer value.

  3. Resetting replication with RESET SLAVE without fixing server-id 85% 失败

    RESET SLAVE clears replication state but does not change the server-id; error returns on next START SLAVE.