Centos7一键编译搭建Mysql脚本

function install_mysql(){
    MYSQL_BASE=/usr/local/mysql

    cd $TMP_DIR
        file="mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz"
    if [ ! -f $file ]; then
        echo "File not found!"
        yum install -y wget && wget -c wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz;
        echo "下载完成,正在解压.......";
        tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
        mv mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
        cd /usr/local/mysql
        #exit 0
    fi

    echo "创建用户组"
    userdel mysql;
    groupadd mysql;
    useradd -r -g mysql mysql;
    mkdir -p  /data/mysql;
    chown mysql:mysql -R /data/mysql;

cd /etc
echo "写入配置文件"
cat > my.cnf < MYSQL信息 <========="
echo " 数据库版本 : 5.7.37           "
echo " 数据库密码 : [email protected]        "
echo " 数据库端口 : 3306             "
echo " BASEDIR目录: /usr/local/mysql "
echo " DATADIR目录: /data/mysql      "
}
install_mysql

你可能感兴趣的:(shellcentos7)