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