#!/bin/bash
MYSQL_VERSION='mysql-5.5.32-linux2.6-i686'
MYSQL_PACKAGE='mysql-5.5.32-linux2.6-i686.tar.gz'
LIBAIO_PACKAGE='libaio-0.3.106-5.i386.rpm'
LOCK_FILE='wot.lock'
CURRENT_DIR=$(cd "$(dirname $0)"; pwd)
############################################
function isStartSuccess()
{
count=10
isSuccess=0
while [ $count -lt 0 ]
do
count=$(count - 1)
run_status=$(ps -ef | grep -v 'grep' | egrep "bin/mysqld_safe --user=mysql")
if [ "${run_status}X" -eq "X" ];then
echo "check mysql service,please wait..."
else
break
fi
isSuccess=1
sleep 1
done
if [ "${isSuccess}" == 0 ];then
echo "Mysql start success...."
exit 0
else
echo "Mysql start fail...."
exit 1
fi
}
function shutdownMysql()
{
bin/mysqladmin -uroot -proot shutdown >/dev/null 2>&1
pids=$(ps -ef | grep -e "bin/mysqld_safe" | grep -v grep | awk '{print $2}')
for pid in $pids
do
kill -9 $pid
done
pids=$(ps -ef | grep -e "bin/mysqld" | grep -v grep | awk '{print $2}')
for pid in $pids
do
kill -9 $pid
done
pids=$(ps -ef | grep -e "\[mysqld\]" | grep -v grep | awk '{print $2}')
for pid in $pids
do
kill -9 $pid
done
}
###############################################
#check libaio lib
isExistLibaio=$(rpm -qa | grep libaio)
if [ "${isExistLibaio}X" == "X" ];then
echo "Libaio library is not install,we will install it,please wait."
rpm -ivh $CURRENT_DIR/$LIBAIO_PACKAGE
fi
if [ -e "$CURRENT_DIR/$MYSQL_VERSION/$LOCK_FILE" ];then
echo starting mysql,please waiting...
cd "$CURRENT_DIR/$MYSQL_VERSION"
#start mysql
shutdownMysql
sleep 5
/bin/bash "bin/mysqld_safe" --user=mysql &
isStartSuccess
fi
echo "Mysql first install to you PC.please wait..."
rm -fr $CURRENT_DIR/$MYSQL_VERSION
tar -zxf "$CURRENT_DIR/$MYSQL_PACKAGE"
echo starting mysql,please waiting...
cd "$CURRENT_DIR/$MYSQL_VERSION"
#modify perm
chmod -R 744 bin
chmod -R 744 scripts
#check mysql folder
if [ -e /usr/local/mysql ];then
echo "Other Mysql is installed.please uninstall it and remove /usr/local/mysql"
exit 1
else
rm -fr /usr/local/mysql >/dev/null 2>&1
ln -s "$CURRENT_DIR/$MYSQL_VERSION" /usr/local/mysql
fi
#check mysql user and group
groupid=`grep 'mysql' /etc/group|awk -F : '{print $3}'`
if [ ! -z $groupid ] ;then
echo "Mysql group is exist."
else
groupadd mysql
fi
userid=`grep 'mysql' /etc/passwd|awk -F : '{print $3}'`
if [ ! -z $userid ] ;then
echo "Mysql user is exist."
else
useradd -g mysql mysql
fi
#check my.cnf
if [ -e /etc/my.cnf ] ;then
cp /etc/my.cnf /etc/my.cnf.other
fi
cp "$CURRENT_DIR/$MYSQL_VERSION/support-files/my-large.cnf" /etc/my.cnf
#modify mysql perm
chown -R mysql:mysql "$CURRENT_DIR/$MYSQL_VERSION"
chmod -R 744 bin
#install mysql script
/bin/bash "scripts/mysql_install_db" --user=mysql
shutdownMysql
bin/mysqld_safe &
sleep 5
#modify root password
bin/mysqladmin -uroot password root
shutdownMysql
bin/mysqld_safe --user=mysql&
sleep 5
#import sql data
if [ -e "$CURRENT_DIR/platform_core.sql" ];then
echo "Import platform_core.sql,please wait..."
bin/mysql -uroot -proot -hlocalhost<"$CURRENT_DIR/platform_core.sql"
fi
#start mysql
shutdownMysql
sleep 5
/bin/bash "bin/mysqld_safe" --user=mysql&
#lock mysql
touch $LOCK_FILE
isStartSuccess
实施的步骤
1.解压包
2.初始化数据库脚本
3.修改密码
4.导入sql语句
5.启动mysql