#!/bin/bash
#User :bobo365
#Date :20160127
USER=`whoami`
if [ "$USER" != ‘root‘ ] ;then
echo "Please use root user,Thanks"
exit
fi
MYSQL_USER=`egrep -i mysql /etc/passwd`
if [ -z "$MYSQL_USER" ] ;then
useradd -r -s /sbin/nologin mysql
else
echo "user mysql was added"
fi
yum install -y vim screen lsof gzip unzip tree ntp curl wget libaio*
wget -O /usr/local/src/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
cd /usr/local/src
tar -zvxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/
chown -R mysql.mysql mysql/
cd mysql/support-files/
cp mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 35 mysql on
cd ../data/..
scripts/mysql_install_db --user=mysql &
mv /etc/my.cnf /etc/my.cnf_bak
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sed -i ‘s/^# basedir = ...../basedir = \/usr\/local\/mysql/g‘ /etc/my.cnf
sed -i ‘s/^# datadir = ...../datadir = \/usr\/local\/mysql\/data/‘ /etc/my.cnf
sed -i ‘s/^# port = ...../port = 3306/‘ /etc/my.cnf
sed -i ‘s/^# socket = ...../socket = \/tmp\/mysql.sock/‘ /etc/my.cnf
chmod 755 /etc/init.d/mysqld
/etc/init.d/mysql start
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
PROC=`ps aux|grep mysql |grep -v grep -c`
PORT=`netstat -lnp|grep 3306`
if [ ! -z "$PORT" ] && [ "$PROC" -ne 0 ] ;then
echo "mysql install and started secussefull"
fi
#mysql -S /tmp/mysql.sock