#!/bin/bash
###################################
#fuction  zabbix-server envirorment 
#created by AL  2018/05/01
####################################

install_path=`pwd`

###lib install
yum install -y gcc gcc-c++  ncurses-devel  curl-devel  cmake wget

## create user and group

groupadd mysql -g 502
useradd -s /sbin/nologin -M mysql -u 502 -g mysql




###initalize
cp -f  ${install_path}/conf/ld.so.conf  /etc/ld.so.conf

ldconfig


##install zlib1.2.8
cd ${install_path}/files
tar zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install


###install mysql
cd ${install_path}/files
tar zxf  mysql-5.6.36.tar.gz
cd mysql-5.6.36

cmake  -DCMAKE_INSTALL_PREFIX=/opt/mysql/ \
-DMYSQL_UNIX_ADDR=/opt/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_INNODB_MEMCACHED=1 \
-DWITH_DEBUG=OFF \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF \
-DMYSQL_DATADIR=/opt/mysql/var \
-DMYSQL_TCP_PORT=3306  


make
make install

cp support-files/mysql.server /etc/init.d/mysqld
chmod +x  /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on

cd /opt/mysql/

/opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/var
mkdir /opt/mysql/tmp
chown -R mysql.mysql tmp
chmod 755 tmp

rm -f /etc/my.cnf
cp -f ${install_path}/conf/my.cnf  ./

echo "PATH=/opt/mysql/bin:$PATH" >> /etc/profile
source /etc/profile
service mysqld start




if [ $? == 0 ];then
echo "##################"  
echo -e "\033[40;32m install success \033[0m"
echo "###################"


  
 else 
  echo "##############"
 echo -e "\033[40;31m error \033[0m"
 echo "############" 
 fi




















