本文最先发布在: https://www.itcoder.tech/posts/how-to-i ... ntu-20-04/
MariaDB 是一个开源的关系型数据库管理系统,向后兼容,可替代 MySQL。
MariaDB是由 MySQL 的一些原开发者和很多社区成员共同开发的。
这篇指南将会讲解如何在 Ubuntu 20.04 上安装和保护 MariaDB。
一、前提条件
我们假设你拥有 Ubuntu 服务器的管理权限,或者以 root 身份 或者以拥有 sudo 权限的用户身份登录系统。
二、在 Ubuntu 上安装 MariaDB
在写作的时候,Ubuntu 软件源仓库中的 MariaDB 最新版是 10.3。想要安装它,运行下面的命令:
代码: 全选
sudo apt update
sudo apt install mariadb-server
代码: 全选
sudo systemctl status mariadb
代码: 全选
...
MariaDB 服务器有一个脚本叫做
代码: 全选
mysql_secure_installation
不带参数运行脚本:
<!--ad-->
代码: 全选
sudo mysql_secure_installation
代码: 全选
Enter current password for root (enter for none):
在下一个提示中,你会被问到是否 MySQL root 用户设置密码:
代码: 全选
Set root password? [Y/n] n
代码: 全选
n
代码: 全选
auth_socket
下一步,你将会被要求移除匿名用户,限制 root 用户访问本地机器,移除测试数据库,并且重新加载权限表。对于所有的问题,你应该回答
代码: 全选
Y
代码: 全选
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
想要在终端命令行和 MariaDB 服务器进行交互,使用
代码: 全选
mysql
代码: 全选
mariadb
这个
代码: 全选
auth_socket
代码: 全选
localhost
想要以 root 用户名登录 MariaDB 服务器,输入:
代码: 全选
sudo mysql
代码: 全选
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 61
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04
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)]> Bye
第一个是将鉴权方法从
代码: 全选
auth_socket
代码: 全选
mysql_native_password
代码: 全选
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
FLUSH PRIVILEGES;
代码: 全选
GRANT ALL PRIVILEGES ON [i].[/i] TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';
五、总结
我们已经向你展示了如何在 Ubuntu 20.04 上安装 MariaDB。现在你的数据库服务器已经上线,并且正在运行。下一步,你可以去学习如何管理 MariaDB 用户账号和数据。