mysql5.x安装脚本

时间:2022-06-09 23:21:05

  直接贴出来:

#!/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

mysql5.x安装脚本的更多相关文章

  1. MySQL5&period;7安装脚本

    目录结构: install_mysql.sh:安装脚本 my.cnf: MySQL配置文件 mysql--linux-glibc2.-x86_64.tar.gz:MySQL二进制包 以下为目录中的文件 ...

  2. 实战-Mysql5&period;6&period;36脚本编译安装及初始化

    概述 本文为centos7.3自动化编译安装mysql5.3.6的脚本及后续初始化操作,话不多少,直接上脚本. 安装脚本install.py如下: #coding=utf-8 #!/usr/bin/p ...

  3. mysql5&period;7一键安装脚本

    0. 概述 最近鼓捣出了一个mysql安装脚本,将该脚本,mysql的my.cnf文件,mysql的安装包这三个文件放在同一个目录下面,执行sh mysql-auto-install.sh就可以完成m ...

  4. mysql5&period;6安装

    mysql5.6安装 #卸载原有的mysqlyum remove mysql*ls /etc/my.cnf*mv /etc/my.cnf* /tmp/ #安装依赖包yum install make c ...

  5. LAMP最新源码一键安装脚本

    Linux+Apache+MySQL+PHP (脚本可以选择是否安装+Pureftpd+User manager for PureFTPd+phpMyAdmin+memcache),添加虚拟主机请执行 ...

  6. LNMP、LAMP、LANMP一键安装脚本(定期更新)&lbrack;转&rsqb;

    这个脚本是使用shell编写,为了快速在生产环境上部署LNMP/LAMP/LANMP(Linux.Nginx/Tengine.MySQL/MariaDB/Percona.PHP),适用于CentOS/ ...

  7. 自动安装脚本-------------基于LVMP搭建Nagios 监控

    Mysql初始化参数(mysql-5.6.31) /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local ...

  8. MySQL安装脚本0104-亲试ok

    #!/bin/bash export host_ip=192.168.7.79 export password=123456   echo '#1.取master主机ip的后三位作为master的se ...

  9. Linux下安装mysql(示例mysql5&period;6安装)

    1.首先检查你的linux上是否已经安装了mysql rpm -qa|grep mysql 2.如果mysql的版本不是想要的版本.需要把mysql卸载 yum remove mysql mysql- ...

随机推荐

  1. 微信开发之Ngrok环境准备

    一.为什么要使用ngrok? 各位肯定都知道,做微信开发,我们的开发服务器需要和微信服务器做交互,SO,我们需要准备一台放置在公网的服务器,能够使得我们的服务器可以正常访问微信服务器,并且微信服务器也 ...

  2. asp&period;net 将word文档进行编辑并导出一个新的word

    最近做项目,需要多word文档进行编辑并导出一个新的word,在最初的word编辑中留下特定的字符串用来替换,然后在本地生成一个新的word文档,并且不修改服务器中的word文档,这样才能保证服务器中 ...

  3. 使用android studio时提示Unable to access Android SDK add-on list

    这个界面不用管,点击Cancel.到一个界面下边有个”Android SDK Location:“这个选路径的时候选你的android sdk的路径就好了.以后再打开就不会再报这个错了.

  4. Android ViewPager的每个页面的显示与销毁的时机

    大家在用viewPager的时候要创建一个pagerAdapter对象,用于给viewPager设置页面的. viewPager里面有一个container容器. viewPager的容器缓存3个显示 ...

  5. ps -ef &vert;grep 输出的具体含义

    [root@localhost ~]# ps -ef | grep ApacheJetspeed root     18887 18828  0 08:09 pts/0    00:00:00 gre ...

  6. docker技术之安装

    由于工作原因需要使用docker完成集群的搭建,特此记录一下研究的docker技术. 首先简单的介绍一下docker: Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 L ...

  7. CSRF与SSRF区别

    CSRF 攻击者盗用了你的身份,以你的名义发送恶意请求.CSRF能够做的事情包括:以你的名义发送邮件,发消息,盗用你的账号,甚至于购买商品,虚拟货币转账... 发生条件: 1.登录受信任网站A,并在本 ...

  8. WebRTC架构和协议栈-zz

    为了便于理解,我们来看一个最基本的三角形WebRTC架构(图4).在这个架构中,移动电话用“浏览器M”表示,笔记本电脑用“浏览器L”表示,通过Web服务器将它们连接起来.要建立一个实时媒体通讯,两台设 ...

  9. BZOJ1941&colon;&lbrack;SDOI2010&rsqb;Hide and Seek&lpar;K-D Tree&rpar;

    Description 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得非常寂寞,为了消除寂寞感,他决定和他的好朋友giPi(鸡皮)玩一个更加寂寞的游戏- ...

  10. CSS3实现各种表情

    CSS3实现各种表情 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <title></title ...