欢迎来到代码驿站!

Mysql

当前位置:首页 > 数据库 > Mysql

Centos7安装 mysql5.6.29 shell脚本

时间:2020-12-28 11:36:07|栏目:Mysql|点击:

本文实例为大家分享了mysql5.6.29的shell脚本,供大家参考,具体内容如下

创建脚本mysql.sh,直接运行sh mysql.sh

#!/bin/bash
if [ -d /software ] ;then
  cd /software
else
  mkdir /software && cd /software
fi

#is exist command ,if not,yum install
is_exist() {
  which $1
  if [ $? -ne 0 ] ;then
     yum -y install $1
  fi
}

#dolownad the mysql install package,if exist,check the md5sum,if correct,tar;else rm and download
if [ -f mysql-5.6.29.tar.gz ] ;then
  mysql_md5=`md5sum mysql-5.6.29.tar.gz | cut -d " " -f 1 `
  mysql_md5_true="aaa21c6450adee3a1894fd1710f02bf5"
  if [ "$mysql_md5" = "$mysql_md5_true" ] ;then
    tar -zxvf mysql-5.6.29.tar.gz
  else
    rm -rf mysql-5.6.29.tar.gz
    rm -rf mysql-5.6.29
  fi
else
  is_exist wget
  wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.29.tar.gz
  tar -zxvf mysql-5.6.29.tar.gz
fi

#see the yum source is use
yum cleanup
yum makecache

#install the depend package
yum -y install gcc make cmake ncurses-devel libxml2-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel

#add mysql group and user
is_user_mysql=`cat /etc/passwd |awk -F ":" '{print $1}' |grep mysql`
is_group_mysql=`cat /etc/group |awk -F ":" '{print $1}' |grep mysql`

if [ "$is_group_mysql" != "mysql" ] ;then
  groupadd mysql
fi
if [ "$is_user_mysql" != "mysql" ] ;then
   useradd -r -s /sbin/nologin -g mysql mysql
fi

#compile and install
cd mysql-5.6.29
cmake .
make && make install

chown -R mysql.mysql /usr/local/mysql

#init database
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

#copy the important file to /etc
#cp /usr/local/mysql/my.cnf /etc/my.cnf

sed -i 's/\# basedir \= ...../basedir \= \/usr\/local\/mysql/g' /usr/local/mysql/my.cnf
sed -i 's/\# port = ...../port = 3306/g' /usr/local/mysql/my.cnf
sed -i 's/\# datadir \= ...../datadir \= \/usr\/local\/mysql\/data/g' /usr/local/mysql/my.cnf
sed -i '/\[mysqld\]/a\log-error=\/usr\/local\/mysql\/log\/error.log' /usr/local/mysql/my.cnf
#sed -i '/\[mysqld\]/a\log=\/usr\/local\/mysql\/log\/log' /usr/local/mysql/my.cnf
#sed -i '/\[mysqld\]/a\log-slow-queries=\/usr\/local\/mysql\/log\/slowquery.log' /usr/local/mysql/my.cnf
sed -i '/\[mysqld\]/a\long_query_time=2' /usr/local/mysql/my.cnf
sed -i '/\[mysqld\]/a\pid-file=\/usr\/local\/mysql\/data\/mysql.pid' /usr/local/mysql/my.cnf
sed -i '/\[mysqld\]/a\character-set-server=utf8' /usr/local/mysql/my.cnf

echo "[client] " >> /usr/local/mysql/my.cnf
echo "socket = /var/lib/mysql/mysql.sock" >>/usr/local/mysql/my.cnf

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
#use database
/usr/local/mysql/bin/mysqld_safe --user=mysql &

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

`ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock`
#start the service
service mysqld restart

#import environment
PATH=$PATH:/usr/local/mysql/bin
echo "export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile"
source /etc/profile

上一篇:mysql优化取随机数据慢的方法

栏    目:Mysql

下一篇:mysql 5.7.17 以及workbench安装配置图文教程

本文标题:Centos7安装 mysql5.6.29 shell脚本

本文地址:http://www.codeinn.net/misctech/37492.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有