MySQL服务安装之二:二进制方式一键安装脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL服务安装之二:二进制方式一键安装脚本相关的知识,希望对你有一定的参考价值。


#!/bin/bash
#User        :bobo365
#Date        :20160127

USER=`whoami`
if [ "$USER" != ‘root‘ ] ;then
       echo "Please use root user,Thanks"
       exit
fi

mysql_USER=`egrep -i mysql /etc/passwd`
if [ -z "$MYSQL_USER" ] ;then
               useradd -r -s /sbin/nologin mysql
       else
               echo "user mysql was added"
fi

yum install -y vim screen lsof gzip unzip tree ntp curl wget libaio*

wget -O /usr/local/src/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

cd /usr/local/src
tar -zvxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql

cd /usr/local/
chown -R mysql.mysql mysql/
cd mysql/support-files/
cp mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 35 mysql on
cd ../data/..
scripts/mysql_install_db --user=mysql &

mv /etc/my.cnf /etc/my.cnf_bak
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sed -i ‘s/^# basedir = ...../basedir = \/usr\/local\/mysql/g‘ /etc/my.cnf
sed -i ‘s/^# datadir = ...../datadir = \/usr\/local\/mysql\/data/‘ /etc/my.cnf
sed -i ‘s/^# port = ...../port = 3306/‘ /etc/my.cnf
sed -i ‘s/^# socket = ...../socket = \/tmp\/mysql.sock/‘ /etc/my.cnf

chmod 755 /etc/init.d/mysqld
/etc/init.d/mysql start
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

PROC=`ps aux|grep mysql |grep -v grep -c`
PORT=`netstat -lnp|grep 3306`
if [ ! -z "$PORT" ] && [ "$PROC" -ne 0 ]  ;then
       echo "mysql install and started secussefull"
fi

#mysql -S /tmp/mysql.sock


本文出自 “bobo365的运维之路” 博客,请务必保留此出处http://bobo365.blog.51cto.com/1035992/1738876

以上是关于MySQL服务安装之二:二进制方式一键安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

一键安装mysql-5.X二进制包的脚本

一键安装mysql5.7和mysql8.0二进制包的脚本

MySQL服务安装之一:一键安装脚本

mysql 8.0 windows一键安装脚本

怎么写个windows脚本一键启动mysql服务

4步搞定MySQL安装部署(附MySQL一键式部署脚本)