#!/bin/bash
if [ -f "/etc/init.d/mysql" ] && [ -d "/usr/local/mysql" ] ;then
echo "软件已安装过"
exit
fi
SOFTDIR="/usr/local/src"
yum install gcc gcc-c++ ncurses-devel glibc-devel make automake autoconf wget -y
wget http://192.168.0.110/cmake-2.8.10.2.tar.gz -P $SOFTDIR
wget http://192.168.0.110/bison-2.7.tar.gz -P $SOFTDIR
wget http://192.168.0.110/Percona-Server-5.5.30-rel30.2.tar.gz -P $SOFTDIR
cd $SOFTDIR/
tar zxf cmake-2.8.10.2.tar.gz
tar zxf bison-2.7.tar.gz
tar zxf Percona-Server-5.5.30-rel30.2.tar.gz
cd $SOFTDIR/cmake-2.8.10.2
./bootstrap
make
make install
cd $SOFTDIR/bison-2.7
./configure
make
make install
cd $SOFTDIR/Percona-Server-5.5.30-rel30.2
CC=gcc CFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -O3" CXX=g++ CXXFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -felide-constructors -fno-rtti -O3"
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_EXTRA_CHARSETS:STRING=all \
    -DWITH_PARTITION_STORAGE_ENGINE:BOOL=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=1 \
    -DINSTALL_LAYOUT:STRING=STANDALONE  \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE:BOOL=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE:BOOL=1 \
    -DWITH_READLINE=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DMYSQL_DATADIR=/var/mysql/data
make
make install
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
ldconfig
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
cd support-files/
cp my-large.cnf /usr/local/mysql/my.cnf
cp mysql.server /etc/init.d/mysql
cd ~
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/usr/local/mysql/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
chmod +x /etc/init.d/mysql
sed -i '/^basedir/ cbasedir=/usr/local/mysql' /etc/init.d/mysql
sed -i '/^datadir/ cdatadir=/var/mysql/data' /etc/init.d/mysql
sed -i '/^#/d;/^$/d;/^\[.*\]$/ i\\n' /usr/local/mysql/my.cnf
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile && . /etc/profile
chkconfig --add mysql
chkconfig mysql on
#mysql启动的时候会先去/etc寻找my.cnf,因为我的my.cnf不在这个目录下,故而删除它,如果不删除启动mysql的时候会报错
rm -rf /etc/my.cnf
service mysql start