Files
nexus/wiki/sources/mysql-mariadb-数据库详细信息.md
2026-04-22 04:03:04 +08:00

82 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "MySQL MariaDB 数据库详细信息"
type: source
tags: [database, mariadb, mysql, nas]
date: 2026-04-14
---
## Source File
- [[raw/Home Office/MySQL MariaDB 数据库详细信息.md]]
## Summary (用中文描述)
- 核心主题MariaDB/MySQL 数据库的访问配置信息及远程访问用户创建流程
- 问题域NAS 上的 MariaDB 数据库内网/公网访问配置、用户权限管理
- 方法/机制:通过 socket 本地登录创建远程访问用户,使用 `CREATE USER``GRANT` 语句配置权限
- 结论/价值:提供完整的 MariaDB 远程访问配置指南,解决新安装 MariaDB 后只能本地 localhost 访问的问题
## Key Claims (用中文描述)
- 新安装的 MariaDB 默认只有 `root@localhost` 账户,无法从外部机器连接
- 远程访问需要创建 `username@%` 格式的用户(`%` 表示允许任意主机)
- Socket 登录是本地管理员访问的安全方式,可绕过网络认证
## Key Quotes
> "你的 MariaDB 只有 `root@localhost`,并没有 `root@%` 或你要连接用的用户账号" — MariaDB 权限诊断核心问题
> "CREATE USER 'shenwei'@'%' IDENTIFIED BY '!Abcde12345';" — 允许任意主机远程访问的用户创建命令
## Key Concepts
- [[Socket 登录]]:通过 Unix socket 文件进行本地认证,无需网络连接
- [[用户权限]]Host+User 组合决定访问权限,`%` 表示任意主机
## Key Entities
- [[MariaDB]]开源关系型数据库Synology NAS 上通过 Docker 部署
- [[群晖 NAS]]MariaDB 数据库的宿主机IP: 192.168.3.17
- [[shenwei]]:数据库用户名
## Connections
- [[群晖 NAS]] ← hosts ← [[MariaDB]]
- [[MariaDB]] ← configured_by ← Socket 登录
## Contradictions
- 无冲突
## 访问配置摘要
### 内网访问
| 项目 | 值 |
|------|-----|
| IP | 192.168.3.17 |
| Port | 3307 |
| Username | shenwei |
| Password | !Abcde12345 |
| Root | root / !Abcde12345 |
### 公网访问
| 项目 | 值 |
|------|-----|
| Domain | mysql.ishenwei.online |
| Port | 63307 |
| Username | shenwei |
| Password | !Abcde12345 |
### Socket 登录命令
```bash
sudo mysql -u root -p -S /run/mysqld/mysqld10.sock
```
### 创建远程访问用户
```sql
CREATE USER 'shenwei'@'%' IDENTIFIED BY '!Abcde12345';
GRANT ALL PRIVILEGES ON *.* TO 'shenwei'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
```
### 查看当前用户列表
```sql
select host, user from mysql.user;
```
## Related Sources
- [[Docker卷]] — Docker卷备份中使用 mysqldump 进行数据库一致性备份
- [[ubuntu服务器通过rsync实现日常增量备份]] — 包含数据库增量备份策略