二进制安装mariadb的脚本

#!/bin/bash
func () {
    release7=`cat /etc/centos-release | grep -o "7\."`
}
PWD=`pwd`
mkdir /app &> /dev/null
useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql &>/dev/null
echo -e "\t用户mysql已创建(#-#)"
echo -e "\t$1正在解包……"
tar xvf $1 -C /usr/local/ &> /dev/null
echo -e "\t$1解包完成!"
cd /usr/local/
ln -s mariadb* mysql &> /dev/null
cd /usr/local/mysql
mkdir /etc/mysql/ &> /dev/null
\cp -f support-files/my-huge.cnf /etc/mysql/my.cnf
sed -i '/^\[mysqld\]/a\datadir = /app/mysqldb\ninnodb_file_per_table = on\nskip_name_resolve = on' /etc/mysql/my.cnf 
scripts/mysql_install_db  --user=mysql --datadir=/app/mysqldb &>/dev/null
if [ $? != 0 ];then
    yum install libaio -y &> /dev/null
    scripts/mysql_install_db  --user=mysql --datadir=/app/mysqldb &>/dev/null
    if [ $? != 0 ];then
        echo -e "\tscripts/mysql_install_db失败!"
        exit 1
    fi
fi
\cp -f support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld &> /dev/null
func 
if [ -n "$release7" ];then
    mkdir /var/log/mariadb/ &>/dev/null
    chown mysql /var/log/mariadb/
    touch /var/log/mariadb/mariadb.log &> /dev/null
    chown mysql /var/log/mariadb/mariadb.log
else
    mkdir -p /var/log/mysql.log
    chown mysql /var/log/mysql.log
    touch /var/log/mysqld.log
    chown mysql:mysql /var/log/mysqld.log
fi
service mysqld start &> /dev/null
if [ $? == 0 ];then
    echo -e "\tmysql服务以启动(#-#)"
fi
echo "PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
echo -e "\t请执行. /etc/profile.d/mysql.sh脚本将‘/usr/local/mysql/bin’添加到PATH变量中!"
echo -e "\t请执行mysql_secure_installation!安全初始化mariadb(#-#)"
cd $PWD
注意:如果操作系统是最小化安装的,可能会由于缺少一些文件,造成安装失败。

你可能感兴趣的:(运维)