Synology NAS 上支持的第三方包中有开源的数据库系统 MariaDB 可以安装使用,但安装完成后,默认是不能进行远程访问的远程。本文简单的记录如何配置可以在局域网中进行远程访问。
操作步骤
通过 SSH 远程登录到 NAS 中,找到 Mariadb 的安装目录, 默认应该是 /usr/local/mariadb10 (安装的是 MariaDB 10)。进入 bin 目录中:
cd /usr/local/mariadb10/bin
你会看到在该目录中有客户端应用 - mysql。 执行 mysql 启动客户端:
./mysql -u root -p
输入在 NAS 的 Web 管理界面设置的 root 密码。 登录成功后,系统显示 MariaDB 的提示符, 类似如下:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.3.21-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)]>
执行以下 SQL 语句,先查看已有用户
SELECT User, Host FROM mysql.user;
一般会输出
+-------------+-----------+
| User | Host |
+-------------+-----------+
| PUBLIC | |
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
4 rows in set (0.133 sec)
-
为
root
用户添加新的主机权限:
如果您希望保留现有的root@localhost
用户,并允许root
用户从10.%%.%%.%%
网络连接,您可以创建一个新的用户条目:CREATE USER 'root'@'10.%%.%%.%%' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.%%.%%.%%' WITH GRANT OPTION; FLUSH PRIVILEGES;
请将
your_password
替换为您希望设置的密码。 -
更改现有
root
用户的主机:
如果您希望root
用户能够从10.%%.%%.%%
网络连接,而不再从localhost
连接,您可以更新现有用户的主机:RENAME USER 'root'@'localhost' TO 'root'@'10.%%.%%.%%'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.%%.%%.%%' WITH GRANT OPTION; FLUSH PRIVILEGES;
然后就可以用 10.x.x.x的主机使用root链接数据库了.