使用shell脚本如何安装MySQL5.7.29-创新互联
这篇文章将为大家详细讲解有关使用shell脚本如何安装MySQL5.7.29,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
创新互联建站是一家专业提供正安企业网站建设,专注与成都网站制作、网站设计、H5场景定制、小程序制作等业务。10年已为正安众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。脚本内容:
vim install.mysql.sh #!/bin/bash [ -f /etc/init.d/functions ]&& . /etc/init.d/functions ###Check if user is root if [ $UID -ne 0 ]; then echo "Error: You must be root to run this script, please use root to install" exit 1 fi clear echo "=========================================================================" echo "A tool to auto-compile & install MySQL 5.7.29 on Redhat/CentOS Linux " echo "=========================================================================" #pkill -9 mysql #date +%Y-%m-%d-%H-%M #卸载系统自带的Mysql #/bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps #/bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps #/bin/rm -f /etc/my.cnf #set mysql root password echo "===========================" mysqlrootpwd="$1" if [ "$1" = "" ]; then mysqlrootpwd="rootmysql" fi #which MySQL Version do you want to install? echo "===========================" isinstallmysql57="5.7.29" echo "Install MySQL 5.7.29,Please input y" read -p "(Please input y , n):" # Initialize the installation related content. #Delete Old Mysql program rpm -qa|grep mysql rpm -e mysql cat >>/etc/security/limits.conf<> /etc/sysctl.conf echo "============================Install MySQL 5.7.29==================================" #Backup old my.cnf #rm -f /etc/my.cnf if [ -s /etc/my.cnf ]; then mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak fi echo "============================MySQL 5.7.29 installing…………=========================" ##define mysql directory configuration variable Datadir=/data/mysql/data Binlogdir=/data/mysql/binlog Logdir=/data/mysql/logs ##yum install devel and wget mysql yum install numactl /usr/bin/wget -P /tmp http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz sleep 2 tar xf /tmp/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ ln -s /usr/local/mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql grep mysql /etc/passwd RETVAL=$? if [ $RETVAL -ne 0 ];then useradd mysql -s /sbin/nologin -M action "mysql user added successfully" /bin/true else action " $(echo -e "\e[31;47;5m mysql user already exists\e[0m")" /bin/false fi if [ ! -d "$Datadir" ] then mkdir -p /data/mysql/data fi if [ ! -d "$Binlogdir" ] then mkdir -p /data/mysql/binlog fi if [ ! -d "$Logdir" ] then mkdir -p /data/mysql/logs fi chown -R mysql:mysql /data/mysql chown -R mysql:mysql /usr/local/mysql #edit /etc/my.cnf #SERVERID=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'` cat >>/etc/my.cnf< /etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh echo "============================MySQL 5.7.29 install completed=========================" ps -eo start,cmd,pid|grep mysql /usr/local/mysql/bin/mysqladmin -uroot -p"$Pass" password $mysqlrootpwd
名称栏目:使用shell脚本如何安装MySQL5.7.29-创新互联
标题路径:http://pwwzsj.com/article/ccejoi.html