Centos7编译安装mysql脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7编译安装mysql脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash # mysqld install scripts # display Progress Progress () { b=‘‘ i=0 while [ $i -le 100 ] do printf "$*:[ %-50s ]%d%%\r" $b $i sleep 0.001 i=`expr 2 + $i` b=#$b done echo } # if Centos Version Centos_version=$(cat /etc/redhat-release|awk ‘{print $4}‘|cut -b1) wget -o /dev/null -O /etc/yum.repos.d/Centos-Base.repo /http://mirrors.aliyun.com/repo/Centos-${Centos_version}.repo yum makecache Progress Centos Download sed -i ‘s/^SELINUX=.*/SELINUX=disabled/g‘ /etc/selinux/config;iptables -F setenforce 0 rpm -e --nodeps mysql* CPU_NUMBERS=`cat /proc/cpuinfo|grep processor|wc -l` COMPUTER_MEM=`free -m|grep Mem|awk ‘{print $2}‘` MYSQL_MEM=`expr $COMPUTER_MEM - $COMPUTER_MEM / 4` COLOR_GREEN="\033[32m" COLOR_RED="\033[31m" COLOR_BULE="\033[34m" COLOR_YELLOW="\033[33m" COLOR_PURPLE="\033[35m" COLOR_END="\033[0m" sleep 0.05;echo "==================================================";echo;echo sleep 0.05;echo -e "Mysql 5.7.16 on $COLOR_GREEN Centos7_`uname -m` $COLOR_END" sleep 0.05;echo -e "Your computer is $COLOR_GREEN $CPU_NUMBERS $COLOR_END processes,Mysql Memory is ${COLOR_GREEN}${MYSQL_MEM}M${COLOR_END}" sleep 0.05;echo -e "${COLOR_RED}Your will input mysql‘s root password and mysql‘s memory${COLOR_END}";echo;echo sleep 0.05;echo "==================================================" # are you sure install read -n1 -t30 -p "Are you sure setup[y/n]?: " answer case $answer in "y" | "Y" ) echo;echo "Start setup.....";sleep 2;; "n" | "N" ) echo;echo -e "${COLOR_RED}Cancel setup......${COLOR_END}" exit 0 ;; "") echo;echo -e "${COLOR_PURPLE}Over time!!!!!${COLOR_END}" exit 0 ;; *) echo;echo -e "${COLOR_RED}Error input parameter......${COLOR_END}" exit 1 ;; esac # check if user is root if [ $(id -u) != "0" ];then echo "$COLOR_RED Sorry:You must be root to run this script!${COLOR_END}" exit 1 fi # useradd mysql GROUP_NAME=mysql USER_NAME=mysql if [ -z $(cat /etc/passwd|awk -F: "{print $1}"|grep -w "$USER_NAME") -a -z $(cat /etc/group|awk -F: "{print $1}"|grep -w "$GROUP_NAME") ] then useradd -s /sbin/nologin -M -U $USER_NAME 2> /dev/null if (( $? == "0" )) then echo -e "$COLOR_GREEN group $GROUP_NAME add sucessfully!${COLOR_END}" fi else echo -e "${COLOR_PURPLE}User $USER_NAME is exsits! ${COLOR_END}" fi for i in make gcc gcc-c++ bison-devel ncurses-devel perl perl-devel wget do yum -y -q install $i > /dev/null echo -e "${COLOR_PURPLE}$i ${COLOR_GREEN}Install ok${COLOR_END}" done # download cmake >= 2.8 CMAKE_VERSION=cmake-3.4.3 rm -rf /tmp/cmake* if [ -z $(which cmake) ] then wget -c --no-check-certificate -q https://cmake.org/files/v3.4/${CMAKE_VERSION}.tar.gz -P /tmp if [ $? == "0" ] then Progress Cmake Download echo -e "${COLOR_GREEN}Cmake Download sucessfully!${COLOR_END}" else echo -e "${COLOR_RED}Cmake Download failed!${COLOR_END}" exit 0 fi tar -zxf /tmp/${CMAKE_VERSION}.tar.gz -C /tmp/ > /dev/null cd /tmp/${CMAKE_VERSION} ./bootstrap > /dev/null make && make install echo $? else echo -e "${COLOR_PURPLE}Cmake is exsits ${COLOR_END}" fi # download boost_1.61 BOOST_VERSION=1.61.0 BOOST_VER="boost_1_61_0" for i in bzip2 gcc bzip2-devel bzip2-libs python-devel perl-Data-Dumper do yum install -q -y $i > /dev/null echo -e "${COLOR_PURPLE}$i ${COLOR_GREEN}install OK${COLOR_END}" done wget -c --no-check-certificate -q https://nchc.dl.sourceforge.net/project/boost/boost/${BOOST_VERSION}/${BOOST_VER}.tar.bz2 -P /tmp if [ $? == "0" ] then Progress Boost Download echo -e "${COLOR_GREEN}Boost Download sucessfully!${COLOR_END}" echo -e "${COLOR_GREEN}Decompression ${BOOST_VER}.tar.bz2${COLOR_END}" cd /tmp;tar -jxf ${BOOST_VER}.tar.bz2 cd ${BOOST_VER} echo `pwd` ./bootstrap.sh 2> /dev/null ./b2 install 2> /dev/null else echo -e "${COLOR_RED}Boost Download failed!${COLOR_END}" exit 0 fi # Download mysql rm -rf /tmp/mysql-5.* MYSQL_VERSION=5.6.35 wget -c http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-${MYSQL_VERSION}.tar.gz -P /tmp if [ $? == "0" ] then echo -e "${COLOR_PURPLE}Mysql ${MYSQL_VERSION}${COLOR_GRENN}Download sucessfully!${COLOR_END}" else echo -e "${COLOR_PURPLE}Mysql ${MYSQL_VERSION}${COLOR_RED}Download failed!${COLOR_END}" fi cd /tmp/ tar -zxf /tmp/mysql-${MYSQL_VERSION}.tar.gz cd mysql-${MYSQL_VERSION} if [ -f /etc/my.cnf ] then mv /etc/my.cnf /etc/my.cnf__$(date +%Y%m%d).bak fi echo "======================================================" echo -e "Please input the root password of mysql: " read -p "(Default password:root):" MYSQL_PASSWD if [ $mysqlrootpw == "" ];then MYSQL_PASSWD="root" fi echo "Mysql root‘s password is ${mysqlrootpw}" echo -e "${COLOR_PURPLE}Please input Mysql Basedir: ${COLOR_END}" read -p "(Default Mysql Basedir:/usr/local/mysql/)" MYSQL_HOME if [ -z $MYSQL_HOME ];then MYSQL_HOME="/usr/local/mysql" fi read -p "(Default Mysql Datadir:/usr/local/mysql/data)" MYSQLDB_HOME if [ -z $MYSQLDB_HOME ];then MYSQLDB_HOME="/usr/local/mysql/data" fi echo "=======================================================" cmake -DCMAKE_INSTALL_PREFIX=${MYSQL_HOME}-${MYSQL_VERSION} -DMYSQL_DATADIR=${MYSQLDB_HOME} -DSYSCONFDIR=/etc -DWITH_BOOST=/usr/local/include/boost -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci make -j${CPU_NUMBERS} && make install ln -s ${MYSQL_HOME}-${MYSQL_VERSION} ${MYSQL_HOME} cp ${MYSQL_HOME}/support-files/my-default.cnf /etc/my.cnf mkdir -p ${MYSQLDB_HOME}/log chown -R mysql:mysql ${MYSQL_HOME} chown -R mysql:mysql ${MYSQLDB_HOME} cd ${MYSQL_HOME};chmod +x ./scripts/mysql_install_db ${MYSQL_HOME}/scripts/mysql_install_db --user=mysql --basedir=${MYSQL_HOME} --datadir=${MYSQLDB_HOME} cat >> /etc/profile <<EOF PATH=\$PATH:${MYSQL_HOME}/bin export PATH EOF source /etc/profile ${MYSQL_HOME}/support-files/mysql.server start if [ $? == "0" ] then echo "Setup successfully!enjoy it...." source /etc/profile else echo "Mysql start failed" fi
本文出自 “搁浅丶” 博客,请务必保留此出处http://yasar.blog.51cto.com/9120455/1913033
以上是关于Centos7编译安装mysql脚本的主要内容,如果未能解决你的问题,请参考以下文章
Apache2.4.25+mysql5.7+php7.13编译安装For Centos7