Files
nexus/raw/Home Office/MySQL MariaDB 数据库详细信息.md

2.6 KiB
Raw Blame History

title, source, author, published, created, description, tags
title source author published created description tags
shenwei
database
mariadb
mysql
nas

#nas #mysql #database #mariadb

Internal Access

IP 192.168.3.17
Port 3307
Username shenwei
Password !Abcde12345
Username root
Password !Abcde12345

Public Access

Domain mysql.ishenwei.online
Port 63307
Username shenwei
Password !Abcde12345
Username root
Password !Abcde12345

MariaDB新安装后需要强制创建一个用户用于远程访问非本机IP访问本机IP访问仅限root用户

进入 MariaDB使用 socket 登陆):

sudo mysql -u root -p -S /run/mysqld/mysqld10.sock

查看 root 主机权限:

select host, user from mysql.user;
shenwei@SHENWEI_DS718:/usr/local/mariadb10/etc/mysql$ sudo mysql -u root -p -S /run/mysqld/mysqld10.sock
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.11.6-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select host, user from mysql.user;
+-----------+-------------+
| Host      | User        |
+-----------+-------------+
|           | PUBLIC      |
| localhost | mariadb.sys |
| localhost | mysql       |
| localhost | root        |
+-----------+-------------+
4 rows in set (0.002 sec)

这里已经看到关键问题了:
你的 MariaDB 只有 root@localhost,并没有 root@% 或你要连接用的用户账号
而从你外部客户端连接失败的最常见原因就是:没有对应的 Host/User 组合 + 缺少权限

你现在的 mysql.user 内容:

|           | PUBLIC      |
| localhost | mariadb.sys |
| localhost | mysql       |
| localhost | root        |

这里唯一能用的账号就是:

  • root@localhost只能从本机 localhost 登录
    这意味着从 Synology Docker、其他机器、同网段的客户端 都不能用 root 连接。

创建一个允许远程访问的用户

CREATE USER 'shenwei'@'%' IDENTIFIED BY '!Abcde12345';
GRANT ALL PRIVILEGES ON *.* TO 'shenwei'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;