在 Raspberry Pi 上安装并配置密码,以访问 MariaDB 的远程连接
MariaDB 由一些最初开发 MySQL 的原始开发人员管理。他们担心甲骨文收购MySQL后会存在一些隐患。 MariaDB 保持了与 MySQL 的高度兼容性,并使用了新的存储引擎 Aria。
安装MriaDB
sudo apt-get install mariadb-server
只需静静等待安装完成即可。系统会询问您是否要继续。输入 Y 继续。安装完成后,您可以通过以下命令连接MariaDB
sudo mysql
出现以下消息表示您已经连接到MariaDB
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.1.38-MariaDB-0+deb9u1 Raspbian 9.0
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)]>
配置密码访问
默认情况下,MariaDB没有配置密码access users ,安装后,所以如果需要远程连接时,无法建立连接。因此,您必须首先为root用户设置密码。首先通过上一步的命令连接到MariaDB,输入以下短语更改密码
use mysql;
UPDATE user SET password=password('password') WHERE user='root';
UPDATE user SET plugin='mysql_native_password' WHERE user = 'root';
flush privileges;
exit
上述执行完成后,重启服务
sudo systemctl restart mariadb
重启完成后尝试密码登录MariaDB并确认是否更改成功
mysql -u root -p
回车使用上面给出的密码,您可以看到与第一步完成安装后登录时相同的屏幕。
配置 MariaDB 进行远程连接
MariaDB 默认情况下仅监听此 IP 地址。目前,无法从外部连接到 Raspberry Pi 上的 MariaDB。
首先使用命令打开配置文件
nano /etc/mysql/
打开文件后有以下内容:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address =
bind-address 表示只监控该IP。在该行前面添加 # 将其注释掉,因为此 MariaDB 侦听所有 IP。
目前,远程计算机连接MariaDB时,会提示“xxx.xxx.xxx无权连接此MariaDB服务器”。另外,使用上一步中的 mysql 命令连接到 MariaDB。输入以下命令:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
--格式如下
GRANT ALL PRIVILEGES ON *.* TO 'user'@'remoteip' IDENTIFIED BY 'password' WITH GRANT OPTION;
--更新权限
FLUSH PRIVILEGES;
现在您可以从外部连接到 Raspberry Pi 上的 MariaDB。
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。