shell安装mysql5.7

#/bin/bash
# mysql install for linux 
# date: 2017-03-03 Author:Zhengwei OS:CentOS6 mysql:5.7.14 
# copy to linux 

# if /usr/local/mysql  exists
d=`date +%Y%m%d`
if [ -e /usr/local/mysql ]
   then
    mv /usr/local/mysql mysql'$d'.bak
    #rm -rf mysql*
fi

if [ -d /opt/mysql ]
    then
    echo "mysql is exists!"     
        rm -rf /opt
        mkdir -p /opt/mysql
fi


if [ -f /tools/mysql*tar.gz ]
   then
     cd /opt/mysql/
     tar -zxvf /tools/mysql*tar.gz
     mv mysql-5.7.14-linux-glibc2.5-x86_64/ mysql-5.7.14
   else
      echo "the mysql install package is not exists"
fi

cd /usr/local/
ln -s /opt/mysql/mysql-5.7.14 /usr/local/mysql


# create mysql user
user=mysql
group=mysql

#create group if not exists  
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd $group
    echo "$group create successful!!"
else
    echo "$group  group is exists!"     
fi

#create user if not exists  
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd -M -g $group -s /sbin/nologin -d /usr/local/mysql $user
    echo "$user create successful!!"
     mysqlpath='export PATH=/usr/local/mysql/bin:$PATH'
     echo $mysqlpath  >> /root/.bash_profile
     source /root/.bash_profile
else
    echo "$user user is exists!"
fi

#create dirctory
#d=`date +%Y%m%d`
if [ -d /data ]
then
    echo "data is exists"
    cd  /
    mv  data data"$d".bak
    mkdir -p /data/mysql
    mkdir -p /data/mysql/mysql_3306
    cd /data/mysql/mysql_3306/
    mkdir data
    mkdir logs
    mkdir tmp
    chown -R mysql:mysql /data/mysql/mysql_3306
 else
    mkdir -p /data/mysql
    mkdir -p /data/mysql/mysql_3306
    cd /data/mysql/mysql_3306/
    mkdir data
    mkdir logs
    mkdir tmp
    chown -R mysql:mysql /data/mysql/mysql_3306

fi

#my.cnf

cd /usr/local/mysql/
./bin/mysqld --initialize


if [ -f /usr/local/mysql/support-files/mysql.server ]
   then
   rm -f /etc/init.d/mysql/mysql.server
   cp  /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
else
   cp  /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

fi

if [ -f /usr/local/mysql/support-files/mysql.server ]
   then
    service mysql restart
    echo "mysql start successful"
else
    echo "mysql start failed"
fi

# print password

p1=`sed -n '/temporary password/p'  /data/mysql/mysql_3306/data/error.log|awk -F ':' '{print $4}'`
echo "your password is:$p1"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值