mysql5.5.25 自动化脚本安装

#####mysql5.5.25 自动化脚本安装

#!/bin/bash
#创作日期:2013.7.26
#Mysql install directory and configuration files.******
MYSQL_DIR="/data/software"
DATA_DIR="/data/mysql/3306/data"
BASE_DIR="/usr/local/mysql"
echo "please input mysql version:"
read  VERSION

echo "Your mysql version is mysql-$VERSION.tar.gz"

if [ -e "$MYSQL_DIR/mysql-$VERSION.tar.gz" ]
    then
echo "Please waitting..."
sleep 3
#Install mysql package dependent.
yum -y install gcc gcc-c++ gcc-g77 autoconf automake openssl zlib* fiex** libxml* \
ncurses-devel libmcrypt* libtool-ltdl-devel* && \
#Install cmake.
echo "The system is bing installed cmake,please waitting..."
sleep 3
tar -zxvf $MYSQL_DIR/cmake-2.8.8.tar.gz -C $MYSQL_DIR && \
cd $MYSQL_DIR/cmake-2.8.8 && \
./configure \
--prefix=/usr/local/cmake && \
make && make install && \
#creating mysql account and group.
/usr/sbin/groupadd mysql && \
/usr/sbin/useradd -s /sbin/nologin -g mysql -M mysql && \
#Install mysql.
tar -zxvf $MYSQL_DIR/mysql-$VERSION.tar.gz -C $MYSQL_DIR 
cd $MYSQL_DIR/mysql-$VERSION  
echo "PATH=$PATH:/usr/local/cmake/bin" >> /etc/profile && source /etc/profile
cmake \
$MYSQL_DIR/mysql-$VERSION  
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \  
-DYSQL_TCP_PORT=3306 \
-DMYSQL_DATADIR=$DATA_DIR \  
-DMYSQL_UNIX_ADDR=/data/mysql/3306/mysql.sock \  
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \  
-DDEFAULT_CHARSET=utf8 \  
-DDEFAULT_COLLATION=utf8_general_ci \  
-DEXTRA_CHARSETS=all \
-DWITH_DEBUG=0
make && make install

mkdir -p $DATA_DIR
mkdir -p `dirname $DATA_DIR`/binlog
mkdir -p `dirname $DATA_DIR`/relaylog
cp $MYSQL_DIR/mysql-$VERSION/support-files/my-small.cnf.sh `dirname $DATA_DIR`/my.cnf
cp $MYSQL_DIR/mysql-$VERSION/support-files/mysql.server.sh /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i 's/^basedir=/basedir=\/usr\/local\/mysql/' /etc/init.d/mysqld 
sed -i 's/^datadir=/datadir=\/data\/mysql\/3306/' /etc/init.d/mysqld 
sed -i 's/`@HOSTNAME@`/DB148/' /etc/init.d/mysqld
sh /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=$DATA_DIR  &&
/etc/init.d/mysqld start
    else 
echo "Your input mysql version  is not in $MYSQL_DIR"
fi
OpsNotes wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!