#!/bin/bash
yum -y install libaio perl-Data-Dumper
yum -y install vim
yum -y install gcc gcc-c++ wget autoconf net-tools lrzsz curl policycoreutils openssh-server openssh-clients postfix
DIR='/usr/local'
NAME='mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz'
FULL_NAME=${DIR}/${NAME}
DATE_DIR='/data/mysql'
if [ -f ${FULL_NAME} ];then
echo "mysql_5.6.34压缩二进制包存在,将进行下面操作..."
else
echo "mysql_5.6.34压缩二进制包不存在,无法下面操作,退出"
exit 3
fi

if [ -h /usr/local/mysql ];then
echo "Mysql已经安装过,退出"
exit 3
else
tar -xvf $DIR/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz -C /usr/local/src
ln -sv $DIR/src/mysql-5.6.34-linux-glibc2.5-x86_64 $DIR/mysql
if [ $? -eq 0 ];then
echo "创建软连接成功"
else
echo "软连接创建失败,退出!"
fi
if id mysql;then
echo "mysql 用户已经存在,跳过创建此用户"
else
useradd -r -s /sbin/nologin mysql
fi
if id mysql;then
chown -R mysql.mysql /usr/local/mysql/*
if [ ! -d /data/mysql ];then
mkdir /data/mysql -p && chown -R mysql.mysql /data
cd /usr/local/mysql/
./scripts/mysql_install_db --uesr=mysql --datadir=/data/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
cp ${DIR}/my.cnf /etc/my.cnf
ln -sv /usr/local/mysql/bin/mysql /usr/bin/mysql
/etc/init.d/mysql start
chkconfig --add mysqld
else
echo "mysql数据库已经存在"
exit 3
fi
fi
fi