一、安装MariaDB
1.访问网址
2. ①选择服务器系统
②选择服务器系统版本
③选择将要安装的MariaDB版本(如图)
3. 在服务器运行
vim /etc/yum.repos.d/MariaDB.repo
把以下代码复制进该文件并保存。
这是CentOS的自定义存储库条目。将其复制并粘贴到/etc/yum.repos.d/下的文件中(建议将文件命名为MariaDB.repo或类似的名称)
# MariaDB 10.5 CentOS repository list - created 2021-07-06 07:11 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1 #是解决被告知的dnf错误的方法
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
如图:
4.安装并启动MariaDB
sudo dnf install MariaDB-server
sudo systemctl start mariadb
二、配置MariaDB
1. 启动MariaDB服务
service mysql start
2.配置MariaDB
mysql_secure_installation
2.1 Enter current password for root (enter for none): //输入当前密码,初次安装没有密码,直接回车
2.2 Switch to unix_socket authentication [Y/n] n //询问是否使用'unix_socket'进行身份验证:n
2.3 Change the root password? [Y/n] y //为root设置密码:y
New password: //输入密码
Re-enter new password: //再次输入密码
2.4 Remove anonymous users? [Y/n] y //是否移除匿名用户,这个随意,建议删除:y
2.5 Disallow root login remotely? [Y/n] n //拒绝用户远程登录,这个建议开启:n
2.6 Remove test database and access to it? [Y/n] n //删除test库,可以保留:n
2.7 Reload privilege tables now? [Y/n] y //重新加载权限表:y
3.进入MariaDB控制台
mysql -u root -p
4.赋予root用户远程连接权限
grant all privileges on *.* to 'root'@'%' identified by 'root密码';
5.刷新权限
flush privileges;
6.测试远程连接