MariaDB 安装

MariaDB yum源

地址:https://mariadb.org/download/?t=repo-config

选择对应的系统和版本;

image-20221205211601229

CentOS 7 安装 MariaDB 10.6

# 
cat > /etc/yum.repos.d/MariaDB.repo <<EOF
# MariaDB 10.6 CentOS repository list - created 2021-12-22 11:16 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.6/centos7-amd64
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

# 安装
yum install MariaDB-server MariaDB-client -y
systemctl enable mariadb --now
# 启动完之后,可以直接配置 password ,详细请执行:grep pass /var/log/messages
/usr/bin/mysqladmin -u root password 'new-password'


# 首次安装需要进行数据库的配置,命令都和mysql的一样
mysql_secure_installation

Enter current password for root (enter for none):  # 输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车
Set root password? [Y/n]  # 设置密码,y
New password:  # 新密码
Re-enter new password:  # 再次输入密码
Remove anonymous users? [Y/n]  # 移除匿名用户, y
Disallow root login remotely? [Y/n]  # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录
Remove test database and access to it? [Y/n]  # 删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要
Reload privilege tables now? [Y/n]  # 重新加载权限表,y。或者重启服务也许


修改远程登录

[root@mini ~]# mysql -u root -p  # 先通过本地链接进入数据库

MariaDB [(none)]> use mysql;

MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| mini      | root |
+-----------+------+
3 rows in set (0.00 sec)



# 将与主机名相等的字段改为 "%" ,我的主机名为mini,
MariaDB [mysql]> update user set host='%' where host='mini';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)


# 刷新权限表
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)


# 查看mysql版本
MariaDB [mysql]> status