树莓派安装数据库
树莓派上安装mysql-server显示没有可用的包,偶然间发现可以使用在MariaDB来实现mysql数据库,因为这个MariaDB完全兼容mysql,并且使用了一个新的存储引擎Aria。
安装MriaDB
sudo apt-get install mariadb-server
y
等待安装,安装完成之后使用以下命令进入数据库
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是没有密码的,需要配置密码进行以后的访问:
注:password 换成你要用的新密码。
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
重启完成后,进行登录。
mysql -u root -p
输入你设置的密码进行登录
配置MariaDB可远程连接
MariaDB默认只监听了127.0.0.1/localhost,这时无法从外部访问树莓派上MariaDB数据库。
修改配置文件
vi /etc/mysql/mariadb.conf.d/50-server.cnf
打开文件后有一段如下的内容:
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
将bind-address = 127.0.0.1这一行注释起来,使MariaDB监听所有的IP。
登陆数据库进行以下操作:
注:user是你在外部想登陆数据库时的账户,ip可以是你外部访问时用的IP,也可以是 % 代表所有的ip,password代表外部访问时用的密码。
GRANT ALL PRIVILEGES ON *.* TO 'user'@'ip' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
至此可从外部连接到树莓派上的MariaDB了
如果您觉得 本篇文章对你有帮助,欢迎给予我们一定的捐助来维持项目的长期发展,谢谢。