# 错误 1698 (28000): 用户 'root'@'localhost' 访问被拒绝

- **ID:** `database/mysql-access-denied-for-root`
- **领域:** database
- **类别:** auth_error
- **错误码:** `1698`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

MySQL 的 'root' 用户配置为通过 'auth_socket' 或 'unix_socket' 插件进行身份验证，这要求客户端通过 Unix 套接字以系统 root 用户身份连接，而不是使用密码。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MySQL 8.0.33 | active | — | — |
| MySQL 8.0.35 | active | — | — |
| MariaDB 10.11.6 | active | — | — |

## 解决方案

1. ```
   Connect using sudo: `sudo mysql -u root`. Then change the authentication plugin: `ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password'; FLUSH PRIVILEGES;`
   ```
2. ```
   Create a new admin user with mysql_native_password: `CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;`
   ```

## 无效尝试

- **** — The command itself fails with the same error because it cannot authenticate as root without the socket plugin. (90% 失败率)
- **** — This disables all authentication, creating a severe security risk. It should only be used temporarily for recovery. (50% 失败率)
