mysql5.x安装脚本

  直接贴出来:

#!/bin/bash
#linux安装mysql服务分两种安装方法:
#①源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错;
#②使用官方编译好的二进制文件安装,优点是安装速度快,安装步骤简单,缺点是安装包很大,300M左右
MYSQL_PACKET="/home/tools"
MYSQL_REPO="5.6"
MYSQL_VERSION="5.6.34"
MYSQL_BASEDIR="/usr/local/mysql"
MYSQL_DATADIR="/home/sqldata/mysql"
MYSQL_SOCKET="/tmp/mysql.sock"
YELLOW_COLOR='\E[1;33m'
RED_COLOR='\E[1;31m'
RES='\E[0m'
function yellow(){
[ $# -ne ] && exit
echo -e "${YELLOW_COLOR}$1${RES}"
}
function red(){
[ $# -ne ] && exit
echo -e "${RED_COLOR}$1${RES}"
}
function BAR(){
i=
str=""
arry=("\\" "|" "/" "-")
while [ $i -le ]
do
let index=i%
if [ $i -le ];then
let color=
let bg=
elif [ $i -le ];then
let color=
let bg=
elif [ $i -le ];then
let color=
let bg=
else
let color=
let bg=
fi
printf " \033[${color};${bg}m%-s\033[0m %d %c\r" "$str" "$i" "${arry[$index]}"
usleep
let i=i+
str+="#"
done
printf "\n"
}
#Check if user is root
function check_user(){
if [ $UID != ];then
echo -e "\033[31m Error: You must be root to run this script, please use root to install\033[0m"
exit
fi
clear
cat <<EOF
---------------------------------------------------------------------------------------------------
|***************A script to auto-compile & install `yellow mysql-${MYSQL_VERSION}` on Redhat/CentOS Linux***************|
--------------------------------------------------------------------------------------------------- EOF
}
function check_env(){
Distrib="${MYSQL_VERSION}"
status1="`mysql --version |awk -F '[ ,]' '{print $6}'`"
if [ "$status1" = "$Distrib" ];then
echo -e "\033[32m Warning: mysql-${MYSQL_VERSION} is already installed! \033[0m"
sleep ;
BAR
echo -e "\033[31m [退出] \033[0m"
exit
else
echo -e "\033[32m Warning: mysql-${MYSQL_VERSION} is not install \033[0m"
echo -e "\033[34m Install mysql-${MYSQL_VERSION},Please input y \033[0m"
read -p "(Please input `yellow y`|`red n`): " installmysql
case "$installmysql" in
y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)
echo -e "\033[34m You will install mysql-${MYSQL_VERSION} \033[0m"
installmysql
;;
n|N)
echo -e "\033[31m [退出] \033[0m"
exit
;;
*)
echo -e "\033[31m INPUT error,You will exit install mysql-${MYSQL_VERSION} \033[0m"
exit
esac
fi
}
function installmysql(){
[ ! -d ${MYSQL_PACKET} ] && mkdir -p ${MYSQL_PACKET}
[ ! -d ${MYSQL_BASEDIR} ] && mkdir -p ${MYSQL_BASEDIR}
[ ! -d ${MYSQL_DATADIR} ] && mkdir -p ${MYSQL_DATADIR}
if [ ! -f ${MYSQL_PACKET}/mysql-${MYSQL_VERSION}.tar.gz ] ;then
echo -e "\033[31m There is without ${MYSQL_PACKET}/mysql-${MYSQL_VERSION}.tar.gz ! \033[0m"
sleep ;
echo -e "\033[32m mysql-${MYSQL_VERSION}.tar.gz is downloading...... \033[0m"
cd ${MYSQL_PACKET} &&\
[ -f mysql-${MYSQL_VERSION} ] || wget http://downloads.mysql.com/archives/mysql-${MYSQL_REPO}/mysql-${MYSQL_VERSION}.tar.gz
#wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
#wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
sleep ;
echo -e "\033[32m Installing mysql-${MYSQL_VERSION},please waiting...... \033[0m"
start_install
else
echo -e "\033[32m Installing mysql-${MYSQL_VERSION},please waiting...... \033[0m"
start_install
fi
} function start_install(){
# 补充部分 Install base tools & packages & library
if [ ! -f epel-release--.noarch.rpm ] ;then
# wget -c http://epel.mirror.net.in/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release--.noarch.rpm
fi
for i in $(rpm -q glibc glibc-static glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libaio readline-devel curl curl-devel libidn libidn-devel autoconf libjpeg libjpeg_devel libpng libpng_devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel gcc gcc-c++ lrzsz ntpdate nmap.x86_64 lsof.x86_64 sysstat.x86_64 glances kernel-devel openssl openssl-devel popt-devel popt-static libnl-devel libicu-devel libevent-devel tree nc make cmake jemalloc pcre pcre-devel pcre-static libzip.x86_64 libzip-devel.x86_64 libevent-devel libool libool-ltdl gd-devel bison vim-enhanced zip unzip patch expect|awk '/not install/ {print $2}')
do
yum -y install $i >/dev/null >&
done
id mysql >/dev/null
[ $? -eq ] && usermod -s /sbin/nologin mysql &>/dev/null || useradd -s /sbin/nologin -M mysql >/dev/null
cd ${MYSQL_PACKET} &&\
tar xf mysql-${MYSQL_VERSION}.tar.gz
cd mysql-${MYSQL_VERSION}
cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_BASEDIR} \
-DMYSQL_DATADIR=${MYSQL_DATADIR} \
-DMYSQL_UNIX_ADDR=${MYSQL_SOCKET} \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_FEDERATED_STORAGE_ENGINE= \
-DWITH_BLACKHOLE_STORAGE_ENGINE= \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE= \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE= \
-DWITH_EMBEDDED_SERVER= \
-DENABLE_DOWNLOADS= \
-DWITH_DEBUG=
sleep ;
make && make install
if [ $? -eq ];then
echo -e "\033[32m mysql-${MYSQL_VERSION} is making successful! \033[0m"
else
echo -e "\033[31m mysql-${MYSQL_VERSION} is making of failure! \033[0m"
exit
fi
#ln -s /usr/local/mysql-5.6./ /usr/local/mysql
\cp support-files/my*.cnf /etc/my.cnf
#初始化和配置数据库
${MYSQL_BASEDIR}/scripts/mysql_install_db --basedir=${MYSQL_BASEDIR} --datadir=${MYSQL_DATADIR} --user=mysql
chown -R mysql.mysql ${MYSQL_BASEDIR}/
\cp support-files/mysql.server /etc/init.d/mysqld
chmod /etc/init.d/mysqld
chkconfig mysqld on && /etc/init.d/mysqld start
grep "/usr/local/mysql/bin/" /etc/profile >/dev/null
if [ $? -ne ];then
echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile && source /etc/profile
else
exit
fi
PID="`netstat -lnpt|grep 330|awk -F '[ /]+' '{print $7}'`"
if [ -z $PID ];then
echo -e "\033[31m mysql-${MYSQL_VERSION} is start failure! \033[0m"
else
BAR
echo -e "\033[32m mysql-${MYSQL_VERSION} is start successful! \033[0m"
fi }
check_user
check_env
上一篇:linux环境下安装tcping工具测试访问超时


下一篇:【2011 Greater New York Regional 】Problem G: Rancher's Gift