偷得浮生 偷得浮生

记录精彩的人生

目录
mysql5.6二进制部署脚本
/  

mysql5.6二进制部署脚本

#!/bin/bash
#
#********************************************************************
#Author:zhangzhuo
#QQ: 1191400158
#Date: 2021-01-28
#FileName:install_online_mysql5.6_for_centos.sh
#URL: https://www.zhangzhuo.ltd
#Description:The test script
#Copyright (C): 2021 All rights reserved
#********************************************************************
. /etc/init.d/functions

DIR=`pwd`
URL=https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.6/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz
NAME=`echo $URL | grep -Eo '[^/]+$'`
DIRNAME=`echo $NAME | sed -rn 's/(.*).tar.*/\1/p'`
DATA_DIR=/data/mysql
FULL_NAME=${DIR}/${NAME}


install_mysql_wget(){
rpm -q wget &>/dev/null || yum install -y wget
yum install -y -q libaio perl-Data-Dumper autoconf
if [ -f ${FULL_NAME} ];then
    action "安装文件已经存在不需要下载"
else
    action "安装文件不存在开始下载" false
    wget $URL || { action "下载失败,异常退出" false;exit 10; }
fi
}

install_mysql_user(){
if id mysql &>/dev/null;then
    action "MYSQL用户已经存在,无需从新创建!"
else  
    useradd -r -s /sbin/nologin -d $DATA_DIR mysql
    action "mysql用户创建成功"
fi
}

install_mysql_datadir(){ 
if [ -d $DATA_DIR ];then
    action "${DATA_DIR}目录已经存在,无需从新创建!"
    chown mysql: $DATA_DIR
else
    mkdir -p $DATA_DIR
    chown mysql: $DATA_DIR
fi
}

install_mysql_my(){
cat <<EOF >/etc/my.cnf
[mysqld]
datadir=$DATA_DIR
socket=$DATA_DIR/mysql.sock
innodb_file_per_table = no
skip_name_resolve = no
[client]
port=3306
socket=$DATA_DIR/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=$DATA_DIR/mysql.sock
EOF
action "配置文件配置完成"
}



install_mysql(){
if [ -e /usr/local/mysql ];then
    action "mysql已经安装" false
    exit
else
    tar -xf $FULL_NAME -C /usr/local
    cd /usr/local/
    ln -s $DIRNAME mysql
    chown -R root: /usr/local/mysql
    install_mysql_my
    cd /usr/local/mysql
    ./scripts/mysql_install_db --datadir=$DATA_DIR --user=mysql &>/dev/null
    echo "PATH=/usr/local/mysql/bin":'$PATH' >/etc/profile.d/mysql.sh
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chkconfig --add mysqld
    service mysqld start
    source /etc/profile.d/mysql.sh
    mysqladmin ping && action "服务启动成功" || action "服务启动失败请检查" false
fi
}

install_mysql_wget
install_mysql_user
install_mysql_datadir
install_mysql