alibaba/canal · error · CanalParseException

command : show variables like 'server_id' has an error! pls

Error message

command : show variables like 'server_id' has an error! pls check. you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation

What it means

findServerId() queries `show variables like 'server_id'`; if the result field list is empty, Canal assumes the account lacks the privilege to read the variable and throws CanalParseException instructing the operator to grant SUPER / REPLICATION CLIENT. An empty result set here almost always means the session cannot see the variable.

Source

Thrown at parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/MysqlEventParser.java:655

                        startSearchBinlogFile.indexOf(".") + 1);
                    String binlogFileNameSuffix = String.format("%06d", nextBinlogSeqNum);
                    startSearchBinlogFile = binlogFileNamePrefix + binlogFileNameSuffix;
                }
            }
        }
        // 找不到
        return null;
    }

    /**
     * 查询当前db的serverId信息
     */
    private Long findServerId(MysqlConnection mysqlConnection) {
        try {
            ResultSetPacket packet = mysqlConnection.query("show variables like 'server_id'");
            List<String> fields = packet.getFieldValues();
            if (CollectionUtils.isEmpty(fields)) {
                throw new CanalParseException("command : show variables like 'server_id' has an error! pls check. you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation");
            }
            return Long.valueOf(fields.get(1));
        } catch (IOException e) {
            throw new CanalParseException("command : show variables like 'server_id' has an error!", e);
        }
    }

    /**
     * 查询当前的binlog位置
     */
    private EntryPosition findEndPosition(MysqlConnection mysqlConnection) {
        String showSql = "show master status";
        try {
            if (mysqlConnection.atLeastMySQL84()) {
                // 8.4新语法
                showSql = "show binary log status";
            } else if (multiStreamEnable) {
                // 兼容polardb-x的多流binlog

View on GitHub (pinned to 87be50e876)

Solutions

  1. Grant privileges: `GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';` (add SUPER if your MySQL version requires it for variables).
  2. Verify as the canal user: `SHOW VARIABLES LIKE 'server_id';` returns a row.
  3. On MySQL 8.x, ensure the account has PROCESS privilege if variable visibility is restricted.

Example fix

GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT, SUPER ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: confirm the user can read server_id
ResultSetPacket rs = connection.query("show variables like 'server_id'");
if (rs == null || CollectionUtils.isEmpty(rs.getFieldValues())) {
    throw new IllegalStateException("Cannot read server_id; grant REPLICATION CLIENT/SUPER to the canal user.");
}

Prevention

When it happens

Trigger: The canal DB user runs `show variables like 'server_id'` and gets no rows — the variable is hidden because the account lacks PROCESS/SUPER/REPLICATION CLIENT privileges, or the server is configured to restrict variable visibility.

Common situations: Fresh canal setup where the DB user was granted only minimal privileges; connecting to a hardened/cloud MySQL where variable access is restricted; the user was created without REPLICATION CLIENT.

Related errors


AI-assisted analysis of alibaba/canal@87be50e876 (2026-08-14). Data as JSON: /api/errors/5dd333b31019d02f. Report an issue: GitHub.