#!/bin/bash basedir='/usr/local/mysql' datadir='/data/mysqldata' softdir='/opt' user='mysql' group='mysql' cmakedir='https://lnamp-web-server.googlecode.com/files' cmakefile='cmake-2.8.6' bisondir='http://ftp.gnu.org/gnu/bison' bisonfile='bison-3.0' logs=/tmp/install`date +%F`.log echo "`date +%F` beginning !" >>$logs #create mysql datadir if [ ! -d $datadir ];then mkdir -p /data/mysqldata #create innodb binlog relay dir mkdir $datadir/innodb_data mkdir $datadir/binlog mkdir $datadir/tmpdir mkdir $datadir/relaylog fi #create mysql basedir if [ ! -d $basedir ];then mkdir -p /usr/local/mysql fi #create group user grep $group /etc/group if [ $? != 0 ];then groupadd mysql echo "Group $group add successed!" >>$logs else echo "Group $group already exists!" >>$logs fi grep $user /etc/passwd if [ $? != 0 ];then useradd -g $group $user echo "User $user added" >>$logs else echo "User $user exists" >>$logs fi #grant owner to mysql chown -R $user:$group $basedir chown -R $user:$group $datadir #install depened software yum install -y gcc gcc-* autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* #install camke if [ $? = 0 ];then cd $softdir #fetch soft #wget $cmakedir/$camkefile.tar.gz if [ -f $cmakefile.tar.gz ];then tar -zvxf $cmakefile.tar.gz cd $softdir/$cmakefile #make cmake ./bootstrap if [ $? = 0 ];then gmake && gmake install if [ $? = 0 ];then echo "Cmake install successed" >>$logs else echo "gmake && gmake install failed!" >>$logs exit 1 fi else echo "bootstrap failed !" >>$logs exit 1 fi else echo "Downloads Cmake from google-code failed" >>$logs exit 1 fi fi #install bison if [ $? = 0 ];then cd $softdir #fetch soft wget $bisondir/$bisonfile.tar.gz if [ $? = 0 ];then tar -zvxf $bisonfile.tar.gz cd $softdir/$bisonfile #configure ./configure if [ $? = 0 ];then make && make install if [ $? = 0 ];then echo "bison installed successed" >>$logs else echo "bison make or make install failed" >>$logs exit 1 fi else echo "configure failed ,retry!" >>$logs exit 1 fi else echo "Downloads bsion failed ,check the website!" >>$logs exit 1 fi fi #install mysql5.6.xx mysqlfile=`find /opt -name 'mysql-*.tar.gz' |awk -F'/' '{print $3}'` mysqldir=`find /opt -name 'mysql-*.tar.gz' |awk -F'/' '{print $3}'|cut -d. -f1,2,3` cd $softdir tar zvxf $mysqlfile if [ ! -z $mysqldir ];then cd $mysqldir #use cmake configure the mysql cmake . -DCMAKE_INSTALL_PREFIX=$basedir -DMYSQL_DATADIR=$datadir -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=$datadir/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci if [ $? = 0 ]; then echo "camke mysql successed!">>$logs make && make install if [ $? = 0 ];then echo "mysql install finished ">>$logs else echo "make or make install failed !" >>$logs exit 1 fi else echo "cmake failed ! Retry!" >>$logs exit 1 fi else echo "check the mysqldir if not exists!" >>$logs exit 1 fi #copy the start scripts startup=/etc/init.d/mysqld cp $basedir/support-files/mysql.server $startup if [ $? = 0 ];then chmod +x $startup else echo "$startup not exists" >>logs exit 1 fi #set auto startup while server started chkconfig mysqld on chown -R $user:$group $basedir echo "`date +%F` install successed" >>logs