1. 安装

1.1. 卸载默认的源

版本太低,没法用

首先检查一下是否存在以前的安装包:
rpm -qa | grep mariadbyum list installed | grep mariadb

如果存在,则卸载:
rpm -e mariadb-libs-5.5.64-1.el7.x86_64yum remove mariadb-libs.x86_64

1.2. 添加Maria源

编辑文件/etc/yum.repos.d/mariadb.repo添加Maria源
vim /etc/yum.repos.d/mariadb.repo

1
2
3
4
5
[mariadb]
name = MariaDB
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.11/centos7-amd64/
gpgkey = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

或者使用

1
2
3
4
5
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.11/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

清除并重建yum缓存:

1
yum clean all && yum makecache

引用

1.3. 安装

1
2
3
4
5
6
7
yum -y install mariadb-server mariadb # centos7 安装

systemctl enable mariadb #设置开机启动
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB

2. 默认配置

MARIADB安装后,默认是没有密码的。

2.1. 初始化

执行命令mariadb-secure-installation,初始化包括了设置密码和远程连接等,很方便,不用在手动初始化一波早期版本使用mysql_secure_installation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root]$ /usr/bin/mysql_secure_installation
#输入root(mysql)的密码。默认没有,直接回车
Enter current password for root (enter for none):
#是否切换到unix套接字身份验证[Y/n]
Switch to unix_socket authentication [Y/n] n
#是否设置root密码
Change the root password? [Y/n]
#如果选Y,就输入2次密码
New password:
Re-enter new password:
#是否删除匿名用户?(就是空用户),建议删除
Remove anonymous users? [Y/n]
#是否不允许远程root登录
Disallow root login remotely? [Y/n] n
#是否删除test数据库
Remove test database and access to it? [Y/n] n
#是否加载权限使之生效
Reload privilege tables now? [Y/n] y

如果执行命令的时候出现错误
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

需要查看是否启动了mysqld,执行mysqld_safe,这个命令不会自己退出,需要手动退出(要不然新开一个页面吧)

1
2
3
[root@Kewen-Office-PC init.d]# mysqld_safe
240923 18:05:01 mysqld_safe Logging to '/var/lib/mysql/Kewen-Office-PC.err'.
240923 18:05:01 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql

可能跟我的centos装在wsl中没有systemctl有关

2.2. 设置远程连接

正常初始化的时候可以直接设置远程连接

2.2.1. 首先进入MySQL

1
mysql -u root -p

2.2.2. 然后添加用户远程访问权限

1
2
3
4
5
6
7
-- 注:<root>是登陆数据库的用户,<Password>是登陆数据库的密码,*就是意味着任何来源任何主机
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Password';
GRANT ALL ON *.* to root@'192.168.1.4' IDENTIFIED BY 'your-root-password'; -- @后面的是指定白名单的ip
GRANT ALL ON *.* to root@'192.168.1.4' ; -- 如果没有密码则不用填,

-- 刷新使之生效
FLUSH PRIVILEGES;

2.2.3. 最后退出MySQL重启MariaDB

1
service mariadb restart