mysql5.6.22安装后执行_自动部署安装mysql-5.6.22

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin

export PATH

# Check if user is root

if [ $(id -u) != "0" ]; then

echo "Error: You must be root to run this script,please use root to install"

exit 1

fi

clear

echo "========================================================================="

echo "A tool to auto-compile & install MysqL 5.6.22 on Redhat/CentOS Linux "

echo "========================================================================="

cur_dir=$(pwd)

#set MysqL root password

echo "==========================="

MysqLrootpwd="root"

echo -e "Please input the root password of MysqL:"

read -p "(Default password: root):" MysqLrootpwd

if [ "$MysqLrootpwd" = "" ]; then

MysqLrootpwd="root"

fi

echo "==========================="

echo "MysqL root password:$MysqLrootpwd"

echo "==========================="

#which MysqL Version do you want to install?

echo "==========================="

isinstallMysqL56="n"

echo "Install MysqL 5.6.22,Please input y"

read -p "(Please input y,n):" isinstallMysqL56

case "$isinstallMysqL56" in

y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)

echo "You will install MysqL 5.6.22"

isinstallMysqL56="y"

;;

*)

echo "INPUT error,You will exit install MysqL 5.6.22"

isinstallMysqL56="n"

exit

esac

get_char()

{

SAVEDSTTY=`stty -g`

stty -echo

stty cbreak

dd if=/dev/tty bs=1 count=1 2> /dev/null

stty -raw

stty echo

stty $SAVEDSTTY

}

echo ""

echo "Press any key to start...or Press Ctrl+c to cancel"

char=`get_char`

# Initialize the installation related content.

function InitInstall()

{

cat /etc/issue

uname -a

MemTotal=`free -m | grep Mem | awk '{print $2}'`

echo -e "\n Memory is: ${MemTotal} MB "

#Set timezone

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#Synchronization time

yum install -y ntp

ntpdate -u pool.ntp.org

date

#Delete Old MysqL program

rpm -qa|grep MysqL

rpm -e MysqL

yum -y remove MysqL-server MysqL MysqL-libs

yum -y remove PHP-MysqL

yum -y install yum-fastestmirror

#yum -y update

#Disable SeLinux

if [ -s /etc/selinux/config ]; then

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

fi

setenforce 0

#Install Compile MysqL related procedures

for packages in make cmake ncurses-devel bison bison-devel libaio-devel gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel net-tools perl-Data-Dumper perl;

do yum -y install $packages; done

}

#Check the MysqL installation file exists,there is no download automatically.

function CheckAndDownloadFiles()

{

echo "============================check files=================================="

if [ "$isinstallMysqL56" = "n" ]; then

if [ -s MysqL-5.6.22.tar.gz ]; then

echo "MysqL-5.6.22.tar.gz [found]"

else

echo "Error: MysqL-5.6.22.tar.gz not found!!!download now......"

wget -c http://dev.MysqL.com/get/Downloads/MysqL-5.6/MysqL-5.6.22.tar.gz

fi

echo "============================check files=================================="

fi

}

#Installation of depend on and optimization options.

function InstallDependsAndOpt()

{

cd $cur_dir

cat >>/etc/security/limits.conf<

* soft nproc 65535

* hard nproc 65535

* soft nofile 65535

* hard nofile 65535

eof

echo "fs.file-max=65535" >> /etc/sysctl.conf

}

#Install MysqL

function InstallMysqL56()

{

echo "============================Install MysqL 5.6.22=================================="

cd $cur_dir

#Backup old my.cnf

#rm -f /etc/my.cnf

if [ -s /etc/my.cnf ]; then

mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak

fi

#MysqL directory configuration

mkdir -p /opt/MysqL-5.6.22

ln -s /opt/MysqL-5.6.22 /opt/MysqL

if [ -d /data ] && [ -d /log ];then

ln -s /data /opt/MysqL/data

ln -s /log /opt/MysqL/log

mkdir -p /opt/MysqL/run

else

mkdir -p /opt/MysqL/{data,log,run}

fi

groupadd MysqL

useradd -s /sbin/nologin -M -g MysqL MysqL

if [ -d /data ] && [ -d /log ];then

chown -R MysqL.MysqL /opt/MysqL

chown -R MysqL.MysqL /data

chown -R MysqL.MysqL /log

fi

tar zxf MysqL-5.6.22.tar.gz

cd MysqL-5.6.22/

mkdir source_downloads

if [ -s gmock-1.6.0.zip ];then

cp ../gmock-1.6.0.zip source_downloads

fi

# CFLAGS="-O3 -g -fno-exceptions -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"

# CXX=g++

# CXXFLAGS="-O3 -g -fno-exceptions -fno-rtti -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"

# export CFLAGS CXX CXXFLAGS

cmake \

-DCMAKE_INSTALL_PREFIX=/opt/MysqL \

-DMysqL_DATADIR=/opt/MysqL/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

-DWITH_SSL=system \

-DWITH_ZLIB=system \

-DMysqL_UNIX_ADDR=/opt/MysqL/run/MysqL.sock \

-DMysqL_TCP_PORT=3306 \

-DMysqL_USER=MysqL \

-DENABLE_DOWNLOADS=1 \

-DWITH_DEBUG=0

make -j `cat /proc/cpuinfo | grep processor| wc -l` && make install

if [ -s ../my_defaults.cnf ]; then

echo "MysqL user-defined config is [found]"

cp ../my_defaults.cnf /etc/my.cnf

else

cp support-files/my-default.cnf /etc/my.cnf

fi

/opt/MysqL/scripts/MysqL_install_db --defaults-file=/etc/my.cnf --basedir=/opt/MysqL --datadir=/opt/MysqL/data --user=MysqL --explicit_defaults_for_timestamp

cp support-files/MysqL.server /etc/init.d/MysqL

chmod 755 /etc/init.d/MysqL

chkconfig --add MysqL

chkconfig MysqL on

cat > /etc/ld.so.conf.d/MysqL.conf<

/opt/MysqL/lib

EOF

ldconfig

ln -s /opt/MysqL/lib/MysqL /usr/lib/MysqL

ln -s /opt/MysqL/include/MysqL /usr/include/MysqL

if [ -d "/proc/vz" ];then

ulimit -s unlimited

fi

/etc/init.d/MysqL start

# ln -s /opt/MysqL/bin/MysqL /usr/bin/MysqL

# ln -s /opt/MysqL/bin/MysqLdump /usr/bin/MysqLdump

# ln -s /opt/MysqL/bin/myisamchk /usr/bin/myisamchk

# ln -s /opt/MysqL/bin/MysqLd_safe /usr/bin/MysqLd_safe

cat > /etc/profile.d/MysqL.sh <

PATH=/opt/MysqL/bin:\$PATH

export PATH

EOF

source /etc/profile

/opt/MysqL/bin/MysqLadmin -u root password $MysqLrootpwd

cat > /tmp/MysqL_sec_script<

use MysqL;

update user set password=password('$MysqLrootpwd') where user='root';

delete from user where not (user='root') ;

delete from user where user='root' and password='';

drop database test;

DROP USER ''@'%';

flush privileges;

EOF

/opt/MysqL/bin/MysqL -u root -p$MysqLrootpwd -h localhost < /tmp/MysqL_sec_script

rm -f /tmp/MysqL_sec_script

source /etc/profile

/etc/init.d/MysqL restart

#/etc/init.d/MysqL stop

echo "============================MysqL 5.6.22 install completed========================="

}

function CheckInstall()

{

echo "===================================== Check install ==================================="

clear

isMysqL=""

echo "Checking..."

if [ -s /opt/MysqL/bin/MysqL ] && [ -s /opt/MysqL/bin/MysqLd_safe ] && [ -s /etc/my.cnf ]; then

echo "MysqL: OK"

isMysqL="ok"

else

echo "Error: /opt/MysqL not found!!!MysqL install Failed."

fi

if [ "$isMysqL" = "ok" ]; then

echo "Install MysqL 5.6.22 completed! enjoy it."

echo "========================================================================="

netstat -ntl

else

echo "Sorry,Failed to install MysqL!"

echo "You can tail /root/MysqL-install.log from your server."

fi

}

#The installation log

InitInstall 2>&1 | tee /root/MysqL-install.log

CheckAndDownloadFiles 2>&1 | tee -a /root/MysqL-install.log

InstallDependsAndOpt 2>&1 | tee -a /root/MysqL-install.log

InstallMysqL56 2>&1 | tee -a /root/MysqL-install.log

CheckInstall 2>&1 | tee -a /root/MysqL-install.log

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值