Centos下yum安装MariaDB

Centos7下使用yum方式安装MariaDB

版本

1
2
3
CentOS Linux release 7.9.2009 (Core)

Server version: 10.5.9-MariaDB MariaDB Server

安装

其实教程一搜一大堆,不过很多都是互相抄,还有就是年代比较久远,有条件还是直接官网看搭建说明吧

删除MySQL和MariaDB

卸载当前服务器上的mysql和mariadb

MySQL:rpm -qa |grep mysql | xargs rpm -e --nodeps
yum remove mysql mysql-server mysql-libs

MariaDB:rpm -qa | grep mariadb | xargs rpm -e --nodeps
大写再来一遍:rpm -qa | grep MariaDB | xargs rpm -e --nodeps

创建repo

官网教程

在/etc/yum.repos.d/ 目录下创建MariaDB.repo 文件,网上很多教程说用中科大的yum源,反正我是遇到了很多的坑,最后还是换成了官网的
中科大的:

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

官网:

1
2
3
4
5
6
7
# MariaDB 10.5 CentOS repository list - created 2021-03-23 02:45 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安装配置

yum -y install MariaDB-server MariaDB-client

等待安装完成

1
2
3
4
#启动服务
systemctl start mariadb
#设置开机启动
systemctl enable mariadb

结束之后开始安全配置:
直接敲:mysql_secure_installation
会让你设置root密码,是否允许远程登录,是否删除test库等等,根据需要自己选吧

安装后配置

首先是字符集配置,默认是latin1,为了方便还是改成utf8吧
修改配置文件:vim /etc/my.cnf.d/server.cnf(改之前先备份)
在mysqld栏添加:

1
2
3
4
5
init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

保存,重启systemctl restart mariadb

MariaDB操作

作为MySQL的开源分支,操作上无缝对接MySQL
进控制台:mysql -uroot -p输入密码

1
2
3
4
5
6
7
8
9
10
11
[root@QA ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.9-MariaDB MariaDB Server

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)]>

建用户:create user tester@localhost identified by 'yourpw';
赋权限:grant all privileges on *.* to tester@'%' identified by 'yourpw';

遇到的坑

切yum源到中科大,出现系统未注册

想切换到中科大的yum源,更改了/etc/yum.repo.d/CentOS-Base.repo

1
2
3
4
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-Base.repo

更改之后,yum clean all,yum makecache都执行了,然后安装个wget都直接失败,报下面这个:
This system is not registered with an entitlement server. You can use subscription-manager to regist

解决办法:
删了安装好的yum,重新下载那三个基础的yum文件,重新安装,再切yum源到163或者ali的

卸载:rpm -qa | grep yum | xargs rpm -e
下载安装三个基础文件:

下载地址
直接搜这仨:

1
2
3
yum-3.4.3-168.el7.centos.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch

下载完成后上传到服务器,到文件夹位置执行:rpm -ivh yum-* yum安装完成,后面就切163的源吧。。。wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
别忘了yum clean all和yum makecache

GPG密钥失败

yum -y install MariaDB-server MariaDB-client 这步安装时候,读取repo配置,有校验GPG Key这步骤,按照官网的死活没过得去,一直提示密钥失败,临时解决办法很简单,直接关掉校验gpgcheck=0

彻底的解决办法,试了网上很多,没有一个成功的

1
2
3
rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
rpm --import https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

有空再研究吧…

文章目录
  1. 版本
  2. 安装
    1. 删除MySQL和MariaDB
    2. 创建repo
    3. 安装配置
    4. 安装后配置
    5. MariaDB操作
  3. 遇到的坑
    1. 切yum源到中科大,出现系统未注册
    2. GPG密钥失败
|