Chinaunix首页 | 论坛 | 博客
  • 博客访问: 669067
  • 博文数量: 112
  • 博客积分: 3889
  • 博客等级: 少校
  • 技术积分: 1448
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-19 16:35
个人简介

追求卓越,成功就会在不经意间追上你

文章分类

全部博文(112)

文章存档

2015年(1)

2014年(2)

2013年(1)

2012年(16)

2011年(86)

2010年(6)

分类: Python/Ruby

2011-09-16 14:56:22

最近装了很多个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"

阅读(2555) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

xiaozhenggang2011-09-21 16:06:54

我只是陈述下事实,嘿嘿

林生20102011-09-21 09:00:21

xiaozhenggang: 你现在是大神了嘛.....
哈哈 哥哥是菜鸟来着 别高估哥

xiaozhenggang2011-09-21 08:25:44

林生2010: 好久没看过这些东东,一看就有点头晕.....
你现在是大神了嘛

林生20102011-09-20 17:44:29

好久没看过这些东东,一看就有点头晕