#!/bin/sh
#
if_mysql57=$(rpm -qa | grep mysql-community-server-5.7| wc -l)
if [ ${if_mysql57} -eq 1 ];then echo "Mysql has installed.Please check" ; exit ; fi
yum install  http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm  -y
yum install mysql-server mysql  --nogpgcheck -y 
mkdir /data/mysql /data/logs/ -p  && chown mysql:mysql /data/mysql
touch /data/logs/mysqld.log 
chown mysql:mysql /data/logs/mysqld.log
sed -i 's/datadir=.*/datadir=\/data\/mysql/g'  /etc/my.cnf
sed -i 's/socket=.*/socket=\/data\/mysql\/mysql.sock/g'  /etc/my.cnf
sed -i 's/log-error.*/log-error=\/data\/logs\/mysqld.log/g'  /etc/my.cnf
echo '[mysql]' >> /etc/my.cnf
echo 'socket=/data/mysql/mysql.sock' >> /etc/my.cnf
service mysqld start && echo 'Start mysql ok' || echo 'Start mysql failed' 
chkconfig mysqld on && echo 'Enable startup on system '
echo -e "mysql password is : \c" && grep 'temporary password' /data/logs/mysqld.log | awk '{print $NF}' 
echo "Please change password by > ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' ;"  
