Linux下的软件安装总是每次都有不一样的问题
记录一下执行过程

时效性: 2021年

版本疑云

在阿里云的CentOS7.9上装MariaDB, 发现版本有点奇怪

$ yum info mariadb      
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile
Available Packages
Name       : mariadb
Arch       : x86_64
Epoch       : 1
Version     : 5.5.68
Release     : 1.el7
Size       : 8.8 M
Repo       : base/7/x86_64
Summary     : A community developed branch of MySQL
URL         : http://mariadb.org
License     : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a community developed branch of MySQL.
          : MariaDB is a multi-user, multi-threaded SQL database server.
          : It is a client/server implementation consisting of a server daemon (mysqld)
          : and many different client programs and libraries. The base package
          : contains the standard MariaDB/MySQL client programs and generic MySQL files

上官网查了一下, 这个版本已经完蛋了, 加之现在主流版本用的都是10以上, 这个5.5.68可以说是史前版本

https://mariadb.com/kb/en/mariadb-5568-release-notes/

那么直接上最新版本吧

手动加源

阿里的yum源和中科大的yum源都没有提供最新的MariaDB版本, 需要自己手动添加一个Mariadb的源

vim /etc/yum.repos.d/MariaDB.repo

[mariadb]

name = MariaDB

# URL可替换为想用的版本的URL
baseurl = http://yum.mariadb.org/10.6.4/centos7-amd64/

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

版本URL在这找: http://yum.mariadb.org

重新构建缓存

yum clean all
yum makecache

卸载旧版

systemctl stop mariadb // 或者直接ps找出来kill掉

yum remove mariadb-server mariadb mariadb-libs

yum clean all

找出并删除残留目录

$ find / -name mariadb     
$ find / -name mysql 

安装新版

yum install MariaDB-server MariaDB-client

查看状态

$ systemctl status mariadb
● mariadb.service - MariaDB 10.6.4 database server
  Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
          └─migrated-from-my.cnf-settings.conf
  Active: inactive (dead)
    Docs: man:mariadbd(8)
          https://mariadb.com/kb/en/library/systemd/

说明已经成功装上, 直接启动就行

$ systemctl start mariadb

再次查看状态

$ systemctl status mariadb
● mariadb.service - MariaDB 10.6.4 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Fri 2021-09-17 10:15:34 CST; 3s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 22045 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 22019 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 22017 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 22031 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 13
   Memory: 56.5M
   CGroup: /system.slice/mariadb.service
           └─22031 /usr/sbin/mariadbd

启动成功

此时指定当前用户名可直接无密码登录, 无论是哪个用户

$ mysql -uroot   
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.4-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)]>
➜  ~ mysql -ugamer
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.6.4-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)]>

这在安全性上当然是不行的, 需要进行一些设置

在Mariadb10.6.4, user 已经不是mysql数据库下的表, 而是一个视图, 所以无法直接修改, 设置方法参考官网的手册

https://mariadb.com/kb/en/create-user/

https://mariadb.com/kb/en/set-password/