#!/bin/bash
#***************************
#* copyleft huihui 2015-08-11
#*****************************
#* email: huihui@qq.com
#* version:v0.1
#*****************************
while true
do
echo -e"
#######################################
A 安装 mysql服务
B 编辑 mysql服务
C 开启 mysql服务
D 关闭mysql服务
E 卸载 mysql服务
Q 退出 mysql 服务
#########################################
"
read -p "please input [ABCDEQ]: " i
install(){
echo "install mysql"
yum install gcc gcc-c++ ncurses-devel bison openssl-devel zlib-devel cmake make -y
cd ~
tar zxvf mysql-5.5.12.tar.gz
cd ~/mysql-5.5.12
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all
make && make install &> /dev/null
}
edit(){
sed -i '$a PATH=$PATH:$HOME/bin:/usr/local/mysql/bin' ~/.bash_profile
source ~/.bash_profile
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
chmod +x /etc/init.d/mysqld
useradd -M -s /sbin/nologin mysql
cd /usr/local/mysql
chown -R root .
chown -R mysql /usr/local/mysql/data
cd /usr/local/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
}
start(){
echo "start mysql"
/etc/init.d/mysqld start
}
stop(){
echo "stop mysql"
/etc/init.d/mysqld stop
}
remove(){
echo "remove mysql"
rm -fr /usr/local/mysql
}
case "$i" in
A|a)
install
;;
B|b)
edit
;;
C|c)
start
;;
D|d)
stop
;;
E|e)
remove
;;
Q|q)
exit
;;
*)
echo "input [ABCDEQ],follow the rule"
esac
done