# 错误 1114 (HY000): 表 '/tmp/#sql_xxxx' 已满

- **ID:** `database/mysql-temp-table-full`
- **领域:** database
- **类别:** resource_error
- **错误码:** `1114`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

MySQL 的临时表存储（内存或磁盘）空间不足，通常是由于大型查询创建的临时表超出了 tmp_table_size 或 max_heap_table_size 的限制。

## 版本兼容性

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

## 解决方案

1. ```
   Increase both tmp_table_size and max_heap_table_size in MySQL configuration:
[mysqld]
tmp_table_size = 256M
max_heap_table_size = 256M
Then restart MySQL.
   ```
2. ```
   Optimize the query to avoid large temporary tables, e.g., by adding indexes, using LIMIT, or rewriting JOINs to reduce intermediate result sets.
   ```

## 无效尝试

- **Increasing only tmp_table_size without checking max_heap_table_size** — MySQL uses the smaller of tmp_table_size and max_heap_table_size for in-memory temp tables; both must be increased. (80% 失败率)
- **Deleting files from /tmp directory manually** — Temporary tables are managed by MySQL; manual deletion can cause corruption or errors, and space will not be freed immediately. (90% 失败率)
