Skip to main content

mysql upgrade through script

You can download the script to execute mysql upgrade

./scriptfilename versionreq --posteasybuild (run easyapache after upgrade)

./scriptfilename versionreq (only do mysql upgrade)






if [ "$(id -u)" != "0" ]; then
echo "You must be root to run this script"
exit 1
fi
#overall backup
mysqldump -A > /root/mysqlbackup.sql
CPANEL_VERSION=$(cat /usr/local/cpanel/version | cut -d. -f2)
CURRENT_VERSION=$(mysql -V |awk '{print $5}' |cut -d. -f1,2)
# Get the target version
if [ -z $1 ] || [[ $1 != '5.0' && $1 != '5.1' && $1 != '5.5' && $1 != '5.6' ]]; then
echo "Please specify a target version: 5.0, 5.1, 5.5, or 5.6"
exit 1
fi
# Check for incompatible versions
if [ $1 == "5.5" ] && [ "$CPANEL_VERSION" -lt 32 ];then
echo "You must be running cPanel 11.32 or higher to upgrade to MySQL 5.5"
exit 1
fi
if [ $1 == "5.1" ] && [ "$CPANEL_VERSION" -gt 42 ];then
echo "This version of MySQL is not supported on 11.44 or higher"
exit 1
fi
if [ $1 == "5.0" ] && [ "$CPANEL_VERSION" -gt 36 ];then
echo "This version of MySQL is not supported on 11.38 or higher"
exit 1
fi
if [ $1 == "5.6" ] && [ "$CURRENT_VERSION" != "5.5" ];then
echo "You must upgrade to MySQL 5.5 before upgrading to 5.6"
exit 1
fi
if [ $1 == "5.6" ] && [ "$CPANEL_VERSION" -lt 42 ];then
echo "You must be running cPanel 11.42 or higher to upgrade to MySQL 5.6"
exit 1
fi
TARGET_VERSION=$1
# This script has only been tested on MySQL 5
if [ "$(echo $CURRENT_VERSION | cut -d. -f1)" != "5" ];then
echo "This script requires MySQL 5"
exit 1
elif [ $CURRENT_VERSION == $TARGET_VERSION ]; then
echo "You are already running MySQL $TARGET_VERSION"
exit 1
fi
# Define our library versions
if [ $CURRENT_VERSION == "5.0" ];then
lib=15
elif [ $CURRENT_VERSION == "5.1" ];then
lib=16
elif [ $CURRENT_VERSION == "5.5" ] || [ $CURRENT_VERSION == "5.6" ];then
lib=18
fi
ARCH=$(uname -p)
if [ $ARCH == x86_64 ];then
libdir=/usr/lib64
else
libdir=/usr/lib
fi
# Copy libaries for old version
echo "Copying libraries for $CURRENT_VERSION ($lib.0.0)"
if [ -f $libdir/libmysqlclient.so.$lib.0.0 ];then
/bin/cp -f $libdir/libmysqlclient.so.$lib.0.0 /root/
else
echo "Missing libmysqlclient.so.$lib.0.0"
exit 1
fi
if [ -f $libdir/libmysqlclient_r.so.$lib.0.0 ];then
/bin/cp -f $libdir/libmysqlclient_r.so.$lib.0.0 /root/
else
echo "Missing $libdir/libmysqlclient_r.so.$lib.0.0"
exit 1
fi
# Fix common issues in my.cnf
echo "Backing up my.cnf to my.cnf.save"
cp -f /etc/my.cnf /etc/my.cnf.save
sed '/safe-show-database/d' -i /etc/my.cnf
sed 's/set-variable\ *\=\ *//g' -i /etc/my.cnf
# Upgrade MySQL
sed '/mysql-version/d' -i /var/cpanel/cpanel.config
echo "mysql-version=$TARGET_VERSION" >> /var/cpanel/cpanel.config
if [ "$CPANEL_VERSION" -lt 36 ];then
rm -fv /etc/mysqlupdisable
/scripts/mysqlup
else
sed '/MySQL[0-5*]/d' -i /var/cpanel/rpm.versions.d/local.versions
/usr/local/cpanel/scripts/check_cpanel_rpms --fix
fi
# Copy back old libraries
/bin/mv -f /root/libmysqlclient.so.$lib.0.0 $libdir
/bin/mv -f /root/libmysqlclient_r.so.$lib.0.0 $libdir
/bin/ln -sf $libdir/libmysqlclient_r.so.$lib.0.0 $libdir/libmysqlclient_r.so.$lib
/bin/ln -sf $libdir/libmysqlclient.so.$lib.0.0 $libdir/libmysqlclient.so.$lib
if [ "$2" == "--posteasybuild" ];then
mkdir /root/apachebackup
cp -a /usr/local/apache/conf /root/apachebackup/conf.$(date +%d-%m-y)
cp -a /usr/local/lib/php.ini /root/apachebackup/php.ini.$(date +%d-%m-y)
touch /root/back/modules_list
php -v >> /root/back/modules_list
php -m >> /root/back/modules_list
httpd -v >> /root/back/modules_list
httpd -M >> /root/back/modules_list
/scripts/easyapache --build
else
echo "Upgrade complete - please run EasyApache"
fi

Comments

Popular posts from this blog

How to tweak linux server harddisk using hdparm

hdparm switches explained http://manpages.ubuntu.com/manpages/intrepid/man8/hdparm.8.html   First of all you have to install hdparm in linux. apt-get install hdparm #hdparm /dev/sda /dev/sda: readonly = 0 (off) readahead = 120 (on) geometry = 8850/255/63, sectors = 142182912, start = 0 Hard disk Performance Information # hdparm -tT /dev/hda /dev/hdd: Timing cached reads: 496 MB in 2.00 seconds = 247.42 MB/sec Timing buffered disk reads: 60 MB in 3.03 seconds = 19.81 MB/sec Hard drive set to low, slow settings # hdparm -cuda /dev/hda /dev/hda: IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 0 (off) readahead = 256 (on) Use below tweaks to increase disk read write performance. For sda drive ~]# hdparm -a 2048 /dev/sda /dev/sda: setting fs readahead to 2048 readahead = 2048 (on) For sdb drive [root@439298a ~]# hdparm -a 2048 /dev/sdb /dev/sdb: setting fs readahead to 2048 readahead = 2048 (on) ]# echo “anticipatory” >...

Modsecurity block rule for XMLRPC and wp-login attack

SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000134  <Locationmatch "/wp-login.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000135,msg:'ip address blocked for 5 minutes, more than 10 login attempts in 3 minutes.'"  SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.bf_counter=0,id:5000136"  SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:5000137"  SecRule ip:bf_counter "@gt 10" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=300,setvar:ip.bf_counter=0"  </Locationmatch>  SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000234  <Locationmatch "/xmlrpc.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000235,msg:'ip address blocked for 5 m...

RAID

Check the Raid installed lspci | grep RAID     Software Raid ============== Linux Support For Software RAID Currently, Linux supports the following RAID levels (quoting from the man page): LINEAR RAID0 (striping) RAID1 (mirroring) RAID4 RAID5 RAID6 RAID10 MULTIPATH, and FAULTY. MULTIPATH is not a Software RAID mechanism, but does involve multiple devices: each device is a path to one common physical storage device. FAULTY is also not true RAID, and it only involves one device. It provides a layer over a true device that can be used to inject faults. Install mdadm Type the following command under RHEL / CentOS / Fedora Linux: # yum install mdadm Type the following command under Debian / Ubuntu Linux: # apt-get update && apt-get install mdadm How Do I Create RAID1 Using mdadm? Type the following command to create RAID1 using /dev/sdc1 and /dev/sdd1 (20GB size each). First run fdisk on /dev/sdc and /dev/sdd with " Softwa...