#!/bin/bashmysql
#DESCRIPTION 源碼安裝mysql5.1.73c++
#NOTICE 安裝前須要將源碼包放在和腳本一樣的路徑sql
## env settingapi
BASEDIR=/home/mysqlbash
DATADIR=/home/data/mysqlide
PIDFILE=/home/mysql/mysql.pidserver
## mysql base env installip
yum install gcc gcc-c++ cmake ncurses-devel -y源碼
yum groupinstall base "Development Tools" -yit
## create user
groupadd mysql
useradd -r -g mysql mysql
## source package unzip
` -d mysql ` || mkdir mysql && rm -rf mysql && mkdir mysql
tar zxvf mysql-5.1.73.tar.gz -C mysql
mv ./mysql/mysql-5.1.73/* ./mysql/
cd mysql
## mysql install
./configure --prefix=$BASEDIR --datadir=$DATADIR --with-mysqld-user=mysql --with-charset=utf8 --with-extra-charsets=all
make
make install
mkdir -p $DATADIR
chown -R mysql:mysql $BASEDIR
chown -R mysql:mysql $DATADIR
## mysql initial
./scripts/mysql_install_db --datadir=$DATADIR --user=mysql
cp ./support-files/mysql.server /etc/init.d/mysqld
rm -f /etc/my.cnf
cp support-files/my-large.cnf /etc/my.cnf
chmod 755 /etc/init.d/mysqld
sed -inr "s#^basedir=#basedir=$BASEDIR#g" /etc/init.d/mysqld
sed -inr "s#^datadir=#datadir=$DATADIR#g" /etc/init.d/mysqld
sed -inr "s#^pid_file=#pid_file=$PIDFILE#g" /etc/init.d/mysqld
sed -i "/\[mysqld\]/abasedir=$BASEDIR" /etc/my.cnf
sed -i "/\[mysqld\]/adatadir=$DATADIR" /etc/my.cnf
sed -i "/\[mysqld\]/apid_file=$PIDFILE" /etc/my.cnf
## mysql environment variable
export PATH=$PATH:/home/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile
## service start and enanble
chkconfig mysqld on
/etc/init.d/mysqld start