【mysql】mysql5.6 小版本升级

mysql 5.6 小版本升级步骤参考以下脚本。

需要停机时间。

如果对数据要求较高,在升级前需要提前进行备份操作。

#!/bin/bash
#
# 5.6.40之下的版本升级为5.6.40
# 需要先切换到对应实例,即加载该实例的环境变量
# 公共变量
v_5640_package_dir="/opt/software/mybase5640"
v_sleep_time_after_start=5
# 检查命令是否执行成功
function check_command(){
if [ ! $? == 0 ];then
    echo "命令执行失败,请检查!"
    exit 1
fi
}
cd /tmp
check_command
# 检查5.6.40安装包是否存在
if [ ! -d ${v_5640_package_dir} ]; then
    echo "${v_5640_package_dir}安装包不存在!"
    exit 1
else
    echo "check 5.6.40 package---------------ok ok !!"
fi
# 检查当前实例
v_check_alive=`mysql -uroot -e "select 1" &>/dev/null;echo $?`
if [ ! ${v_check_alive} == 0 ];then
    echo "实例非活动!"
    exit 1
else
    echo "check instance alive----------------ok ok !!"
fi
 
# 检查库当前版本
v_curr_version=`mysql -uroot -e "select version()" |tail -1`
v_big_version=${v_curr_version:0:3}
v_small_version=${v_curr_version:4:2}
if [ ! ${v_big_version} == "5.6"  -o  ! ${v_small_version} -lt 40 ]; then
    echo "当前数据库版本不对---${v_curr_version}"
    exit 1
else
    echo "check mysql version--${v_curr_version}----ok ok !!"
fi
# 关闭当前实例
echo  "当前shutdown参数:"`mysql -u root  -e 'show variables like "%innodb_fast_shutdown%"'`
mysql -u root  --execute="SET GLOBAL innodb_fast_shutdown=0"
v_curr_fast_shut=`mysql -u root  -e 'show variables like "%innodb_fast_shutdown%";' |tail -1 |awk '{print $2}'`
echo $v_curr_fast_shut
if [ ! $v_curr_fast_shut == 0 ];then
    echo "fast_shutdown参数错误---------${v_curr_fast_shut}"
    exit 1
fi
mysqladmin -uroot shutdown
v_check_stop=`mysql -uroot -e "select 1" &>/dev/null;echo $?`
if [  ${v_check_stop} == 0 ];then
    echo "实例未关闭!"
    exit 1
else
    echo "instance stoped----------------ok ok !!"
fi
 
# 目录操作
cd $MYSQL_HOME
mv bin bin_bak
check_command
mv lib  lib_bak
check_command
mv scripts  scripts_bak
check_command
mv share share_bak
check_command
mv support-files  support-files_bak
check_command
cp -R ${v_5640_package_dir}/bin ./
check_command
cp -R ${v_5640_package_dir}/lib ./
check_command
cp -R ${v_5640_package_dir}/scripts ./
check_command
cp -R ${v_5640_package_dir}/share ./
check_command
cp -R ${v_5640_package_dir}/support-files ./
check_command
# 启动mysql
nohup mysqld_safe > /dev/null 2>&1 &
for i in {1..5}
do
sleep ${v_sleep_time_after_start}
v_check_start=`mysql -uroot -e "select 1"  &>/dev/null;echo $?`
if [ $i == 5 ];then
    echo "实例启动失败!"
    exit 1
fi
if [ ! ${v_check_start} == 0 ];then
    echo "实例启动检查次数---${i}!"
else
    echo "check start----------------ok ok !!"
    break
fi
done
# 运行升级脚本
mysql_upgrade -u root
# 重启MYSQL
mysqladmin -uroot shutdown
nohup mysqld_safe > /dev/null 2>&1 &
sleep ${v_sleep_time_after_start}
# 打印当前版本
echo "当前版本为:"
echo `mysql -uroot -e "select version()" |tail -1`

 

你可能感兴趣的:(mysql)