最近装了很多个mysql,最近正好在学习shell,最近刚好有点时间,于是乎就有了下面的东东;
个人觉得写得很粗糙,在这里贴出来,和大家共享一下,热烈欢迎各位批评指正
#!/bin/bash
# Desc: install mysql tarball
# Created by : xzg
# Date: 2011/09/15
PATH=/sbin:/usr/bin:/usr/sbin:/bin:/usr/local/bin
export PATH
MYSQL_DIR=/usr/local/mysql
MYSQL_SRC=/usr/local/src
DATA_DIR=/data/mysql
# check if already installed mysql, if exists ,remove it
rpm -qa | grep mysql
if [ $? -eq 0 ];then
yum remove mysql mysql-server -y
echo ""
echo -e "\033[32m Mysql already removed \033[0m"
echo ""
else
echo -e "\033[32m Mysql does not exist \033[0m"
fi
#check user mysql exists or not
id mysql > /dev/null 2>&1
if [ $? -eq 0 ];then
echo ""
echo -e "\033[31m User mysql exists,now remove it;and add a new acount \033[0m"
/usr/sbin/userdel -r mysql
/usr/sbin/groupadd -g 3306 mysql
/usr/sbin/useradd -u 3306 -g mysql -M -s /sbin/nologin mysql
echo -e "\033[32m User mysql created \033[0m"
else
echo ""
echo -e "\033[31m User mysql does not exists ,now we will create it \033[0m"
/usr/sbin/groupadd -g 3306 mysql
/usr/sbin/useradd -u 3306 -g mysql -M -s /sbin/nologin mysql
echo -e "\033[32m User mysql created \033[0m"
fi
#check development tools requried by mysql
echo -e "\033[31m [ Checking for gcc...... ] \033[0m"
rpm -qa|grep gcc-[0-9] || yum install gcc && echo -e "\033[32m GCC installed \033[0m"
echo -e "\033[31m [ Checking for gcc-c++......] \033[0m"
rpm -qa|grep gcc-c++ || yum install gcc-c++ && echo -e "\033[32m GCC-C++ installed \033[0m"
echo -e "\033[31m [ Checking for bison...... ] \033[0m"
rpm -qa|greo bison || yum install bison && echo -e "\033[32m BISON installed \033[0m"
echo -e "\033[31m [ Checking for ncurses...... ] \033[0m"
rpm -qa|grep ncurses || yum install ncurses && echo -e "\033[32m NCURSES installed \033[0m"
echo -e "\033[31m [ Checking for ncurses-devel...... ] \033[0m"
rpm -qa|grep ncurses-devel || yum install ncurses-devel && echo -e "\033[32m NCURSES-DEVEL installed \033[0m"
#Download and install cmake for mysql 5.5 or newer distribution
cd $MYSQL_SRC
echo -e "\003[32m Beginning download...... \033[0m"
wget
echo -e "\033[31m Download Ended \033[0m"
echo -e "\033[32m Beginning uncompress and install......\033[0m"
tar xzvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make && make install
echo -e "\033[31m Install Ended \033[0m"
#Download and install mysql tarball
cd $MYSQL_SRC
echo -e "\033[32m Beginning download...... \033[0m"
wget http://dev.mysql.com/get/Downloa ... Unix/Database/Mysql
echo -e "\033[31m DownloadE Ended \033[0m"
echo -e "\033[32m Beginning uncompress and install...... \033[0m"
tar xzvf mysql-5.5.15.tar.gz
cd mysql-5.5.15
cmake -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR -DMYSQL_DATADIR=$DATA_DIR/data -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWTIH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306
make && make install
echo -e "\033[31m Install Ended \033[0m"
# now configure you installation
mkdir -p $DATA_DIR/data
mkdir -p $DATA_DIR/log
chown -R mysql:mysql $DATA_DIR
chmod -R 755 $DATA_DIR
# use my-medium.cnf as my.cnf
cp support-files/my-medium.cnf /etc/my.cnf
#initialized database
$MYSQL_DIR/scripts/mysql_install_db --user=mysql --basedir=$MYSQL_DIR --datadir=$DATA_DIR/data
# use mysql.server as mysqld
cp suppor-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
# set mysql as system service and start when system boot
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
# create soft links
cd /usr/local/bin
ln -s /usr/local/mysql/bin/mysql mysql &&
ln -s /usr/local/mysql/bin/mysqldump mysqldump &&
ln -s /usr/local/mysql/bin/mysqladmin mysqladmin
echo -e "\033[31m You have installed mysql successfull "
echo -e "\033[32m END END END END \033[0M"
阅读(2779) | 评论(4) | 转发(0) |