MariaDB 10.5.5二进制安装

MariaDB 10.5.5

安装前准备

#CentOS 8 需要安装以下包
dnf -y install libaio ncurses-compat-libs

#CentOS 7 不需要额外安装其他包

#CentOS 6 需要安装以下包
yum -y install libaio

#CentOS 8 如果没有libaio和ncurses-compat-libs包,会提示以下错误,其他版本错误类似
[root@centos82 mysql]#./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

[root@centos82 mysql]#mysql
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

安装操作步骤

#mysql用户组和用户的创建
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql

#压缩包解压到指定目录
tar xvf mariadb-10.5.5-linux-x86_64.tar.gz -C /usr/local

#进入解压缩目录
cd /usr/local

#建立软连接并更改权限
ln -s mariadb-10.5.5-linux-x86_64/ mysql
chown -R root.root /usr/local/mysql/

#准备配置文件
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
socket=/data/mysql/mysql.sock

[mysql]
auto-rehash
prompt="\u@\h [\d]>"

#进入mysql目录
cd mysql

#数据库文件初始化
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql


#环境变量设置
方法1   echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
        . /etc/profile.d/mysql.sh

方法2   ln -s /usr/local/mysql/bin/* /usr/local/bin/

#准备服务脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

#启动mysql
chkconfig --add mysqld
service mysqld start

#修改root登录口令
mysqladmin -uroot password 744123

#登录mysql
mysql -uroot -p744123

一键安装脚本

#!/bin/bash
#
#********************************************************************
#Author:            Wuvikr
#QQ:                744123155
#Date:              2020-09-28
#FileName           MariaDB_Install.sh
#URL:               http://www.wuvikr.com
#Description        The test script
#Copyright (C):     2020 All rights reserved
#********************************************************************
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

pwd1=/usr/local/
pwd2=$pwd1/mysql/
name=mariadb-10.5.5-linux-x86_64

[ -e ${name}.tar.gz ] && tar xf ${name}.tar.gz -C $pwd1 || { echo -e 'e[1;31m压缩包不存在,安装失败!e[0m';exit 3; }

install_mariadb (){

echo -e 'e[1;33m开始安装MariaDB,请稍后...e[0m'

getent passwd mysql || { groupadd -r mysql;useradd -r -g mysql -s /sbin/nologin mysql;echo -e 'e[1;32mmysql用户创建成功成功!e[0m'; }

cd $pwd1

ln -s $name mysql
chown -R root.root $pwd2

cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
socket=/data/mysql/mysql.sock

[mysql]
auto-rehash
prompt="\u@\h [\d]>"
EOF

cd $pwd2

./scripts/mysql_install_db --user=mysql --basedir=$pwd2 --datadir=/data/mysql &> /dev/null && echo -e 'e[1;32m数据库初始化成功!e[0m'

ln -s ${pwd2}bin/* ${pwd1}bin/

cp ${pwd2}support-files/mysql.server /etc/init.d/mysqld

chkconfig --add mysqld
service mysqld start
echo -e 'e[1;32mMariaDB安装成功!e[0m'
}

install_mariadb
原文地址:https://www.cnblogs.com/wuvikr/p/13788576.html