# RDB 校验和不匹配：期望 0x<hex> 但得到 0x<hex>

- **ID:** `redis/rdb-checksum-mismatch`
- **领域:** redis
- **类别:** data_error
- **错误码:** `ERM`
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

磁盘上的 RDB 文件已损坏或被截断，导致其校验和与 Redis 加载时计算的值不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Redis 6.2.0 | active | — | — |
| Redis 7.0.0 | active | — | — |
| Redis 7.2.0 | active | — | — |

## 解决方案

1. ```
   Restore from a recent backup RDB file: copy the backup to the dump directory and restart Redis. Example: cp /backup/dump.rdb /var/lib/redis/dump.rdb; systemctl restart redis.
   ```
2. ```
   Use redis-check-rdb to repair the file: run redis-check-rdb /var/lib/redis/dump.rdb to fix minor corruption. If unrecoverable, use AOF file as fallback if enabled.
   ```
3. ```
   Enable AOF persistence alongside RDB to reduce reliance on RDB. Set appendonly yes in redis.conf and restart.
   ```

## 无效尝试

- **** — Redis will fail to load the same corrupted RDB file again, causing repeated crashes or startup failures. (95% 失败率)
- **** — RDB files are binary and have a complex structure; manual editing almost always results in further corruption. (99% 失败率)
- **** — Deleting the RDB file causes total data loss; it is only acceptable if backups exist. (50% 失败率)
