免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2615 | 回复: 5
打印 上一主题 下一主题

求指点:mysql5.5安装脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-09-16 12:11 |只看该作者 |倒序浏览
最近在学习shell脚本,而且最近装了不少mysql,所以想写个脚本练习下,测试过,可以正常安装mysql。
但总体来说,写得应该不怎么样,恳求各位大神指点

#!/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

rmp -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 http://www.cmake.org//files/v2.8/cmake-2.8.4.tar.gz
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"

论坛徽章:
0
2 [报告]
发表于 2011-09-16 13:04 |只看该作者
rmp -qa | grep mysql ????

论坛徽章:
0
3 [报告]
发表于 2011-09-16 13:16 |只看该作者
那个是检查系统中是否安装过mysql的rpm包

论坛徽章:
0
4 [报告]
发表于 2011-09-16 13:19 |只看该作者
二楼是说拼写问题,呵呵
支持下~

论坛徽章:
0
5 [报告]
发表于 2011-09-16 14:17 |只看该作者
回复 4# shplpy


    嗯嗯,望各位多多指点

论坛徽章:
0
6 [报告]
发表于 2011-09-16 14:42 |只看该作者
挺好
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP