centos7二进制安装mysql5.6.50脚本

#/bin/bash
DIR=/usr/local/src
NAME="mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz"
FILE=$(echo $NAME|sed -r 's/(.*).tar.gz/\1/')
FULL_NAME=${DIR}/${NAME}
DATA_DIR="/data/mysql"
LINK="https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.6/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz"

. /etc/init.d/functions
echo -e "\e[1;31m 下载依赖\e[0m"
yum -y install autoconf libaio-devel net-tools vim wget gcc gcc-c++ lrzsz &>/dev/null

if [ -h /usr/local/mysql ];then
    action "mysql已经安装" false
    exit 3
elif [ ! -f $FULL_NAME ];then 
    cd $DIR
    echo -e "\e[1;31m下载软件包...\e[0m"
    wget $LINK 
    echo -e "\e[1;31m解压中...\e[0m"
    tar xf $FULL_NAME -C /usr/local/src &>/dev/null
else
    echo -e "\e[1;31m解压中...\e[0m"
    tar xf $FULL_NAME -C /usr/local/src &>/dev/null
    ln -s /usr/local/src/$FILE /usr/local/mysql 
fi

echo -e "\e[1;31m安装中...\e[0m"

#创建用户mysql
id mysql &>/dev/null && usermod -u306 -md /data/mysql -s /sbin/nologin mysql &>/dev/null || useradd -r -u306 -d /data/mysql -s /sbin/nologin mysql


chown -R mysql.mysql /usr/local/mysql/*

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld

cat > /etc/my.cnf <\\_
[mysqld]
user=mysql
datadir=/data/mysql
basedir=/usr/local/mysql
port=3306
socket=/data/mysql/mysql.sock
symbolic-links=0
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
EOF

cat >> /etc/profile.d/path.sh </dev/null

cat >/lib/systemd/system/mysqld.service </dev/null
systemctl restart mysqld && ss -lnt|awk -F":| +" '/3306/{print $5}' && action "启动成功" || action "失败" false

#安全加固初始化 设置root密码123456 不允许远程登录 
#echo -e "\ny\n123456\n123456\ny\ny\ny\ny\n"|/usr/local/mysql/bin/mysql_secure_installation &>/dev/null

你可能感兴趣的:(centos7二进制安装mysql5.6.50脚本)