#-----------------------------CentOS 5.x版本升级Mysql ------------------
#! /bin/sh
#1.关闭selinux
cp -rp /etc/selinux/config /etc/selinux/config.bak
setenforce 0
sed -i ‘7s/enforcing/disabled/‘ /etc/selinux/config
#2.显示selinux的状态 Permissive为关闭
getenforce
#3.判断系统的版本
if [ "$(uname -i)" = i386 ]; then
# 如果服务器是32位,那么运行如下命令
echo "开始下载第三方remi库 i386"
wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
else
## 如果是64位的 那么运行以下命令
echo "下载第三方remi库 X64"
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
fi
#4.修改remi.repo的配置文件 如果只想升级到php5.4.x,那么就把[remi]部分的enabled改为1
#如果想升级到php5.5.x,那么就把[remi]和[remi-php55]部分的enabled都改为1
cp -rp /etc/yum.repos.d/remi.repo /etc/yum.repos.d/remi.repo.bak
sed -i ‘9s/enabled=0/enabled=1/‘ /etc/yum.repos.d/remi.repo
sed -i ‘18s/enabled=0/enabled=1/‘ /etc/yum.repos.d/remi.repo
sed -i ‘7s/^#//‘ /etc/yum.repos.d/remi.repo
sed -i ‘8s/^/#&/‘ /etc/yum.repos.d/remi.repo
sed -i ‘15s/^#//‘ /etc/yum.repos.d/remi.repo
sed -i ‘16s/^/#&/‘ /etc/yum.repos.d/remi.repo
#修改下面epel.repo的配置文件信息 不然会报错
cp -rp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
sed -i ‘3s/^#//‘ /etc/yum.repos.d/epel.repo
sed -i ‘12s/^#//‘ /etc/yum.repos.d/epel.repo
sed -i ‘21s/^#//‘ /etc/yum.repos.d/epel.repo
sed -i ‘4s/^/#&/‘ /etc/yum.repos.d/epel.repo
sed -i ‘13s/^/#&/‘ /etc/yum.repos.d/epel.repo
sed -i ‘22s/^/#&/‘ /etc/yum.repos.d/epel.repo
#5.查看系统是不是安装了mysql 卸载之前的mysql版本
yum list mysql
yum remove mysql mysql-server -y
#6. 安装最新的mysql
echo "正在安装新版本的Mysql Please Wait"
yum --enablerepo=remi install mysql mysql-sercver --skip-broken -y
#7.修改mysql的配置信息
sed -i ‘3a default-character-set = utf8‘ /etc/my.cnf
#8. 开启防火墙3306端口
sed -i ‘10a -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT ‘ /etc/sysconfig/iptables
#9.重启Mysql
chkconfig --add mysqld
service mysqld restart