在树莓派上配置MariaDB

在树莓派上配置MariaDB

前言

MariaDB是由本来开发MySQL的一些原始开发者领导,他们担忧Oracle收购MySQL后会有一些隐患。MariaDB与MySQL保持这高度兼容性,并使用了一个新的存储引擎Aria。mysql

安装MriaDB

sudo apt-get install mariadb-server

静静的等待安装完成便可,中间会询问是否继续,输入Y继续便可。安装完成后就能够经过一下命令链接到MariaDBsql

sudo mysql

出现以下讯息表示已成功链接到MariaDB了bash

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安装好后都没有配置访问用户的密码,所以若是须要远程链接时会没法链接。所以须要先對root用户设置密码。首先透过上一步中的命令链接至MariaDB,输入以下语句进行密码的修改less

use mysql; 
UPDATE user SET password=password('password') WHERE user='root'; 
UPDATE user SET plugin='mysql_native_password' WHERE user = 'root'; 
flush privileges; 
exit

以上执行完成后,重启服务this

sudo systemctl restart mariadb

重启完成后,试用密码进行mariadb登陆,验证是否修改为功rest

mysql -u root -p

输入上面设置的密码就能够看到第一步安装完成登陆时同样的画面了。code

配置MariaDB可远程链接

MariaDB默认只监听了127.0.0.1这个IP地址,这个时候是没法从外部链接到树莓派上MariaDB。
先使用一下命令打开配置文件server

nano /etc/mysql/mariadb.conf.d/50-server.cnf

打开文件后有一段以下的内容:ip

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address            = 127.0.0.1

bind-address表示只监听了127.0.0.1这个IP,将这一行的前面加上# 将这一行注释起来,这样MariaDB就监听了全部的IP。
此时从外部的电脑链接MariaDB会提示"xxx.xxx.xxx is not allowed to connect to this MariaDB Server"。一样使用上一步中的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;

至此可从外部链接到树莓派上的MariaDB了

相关文章
相关标签/搜索