shell脚本一键安装MySQL5.7.29的方法
本文参考51CTO博客作者wjw555的作品
脚本内容:
viminstall.mysql.sh #!/bin/bash [-f/etc/init.d/functions]&&./etc/init.d/functions ###Checkifuserisroot if[$UID-ne0];then echo"Error:Youmustberoottorunthisscript,pleaseuseroottoinstall" exit1 fi clear echo"=========================================================================" echo"Atooltoauto-compile&installMySQL5.7.29onRedhat/CentOSLinux" echo"=========================================================================" #pkill-9mysql #date+%Y-%m-%d-%H-%M #卸载系统自带的Mysql #/bin/rpm-e$(/bin/rpm-qa|grepmysql|xargs)--nodeps #/bin/rpm-e$(/bin/rpm-qa|grepmariadb|xargs)--nodeps #/bin/rm-f/etc/my.cnf #setmysqlrootpassword echo"===========================" mysqlrootpwd="$1" if["$1"=""];then mysqlrootpwd="rootmysql" fi #whichMySQLVersiondoyouwanttoinstall? echo"===========================" isinstallmysql57="5.7.29" echo"InstallMySQL5.7.29,Pleaseinputy" read-p"(Pleaseinputy,n):" #Initializetheinstallationrelatedcontent. #DeleteOldMysqlprogram rpm-qa|grepmysql rpm-emysql cat>>/etc/security/limits.conf<>/etc/sysctl.conf echo"============================InstallMySQL5.7.29==================================" #Backupoldmy.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"============================MySQL5.7.29installing…………=========================" ##definemysqldirectoryconfigurationvariable Datadir=/data/mysql/data Binlogdir=/data/mysql/binlog Logdir=/data/mysql/logs ##yuminstalldevelandwgetmysql yuminstallnumactl /usr/bin/wget-P/tmphttp://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz sleep2 tarxf/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 grepmysql/etc/passwd RETVAL=$? if[$RETVAL-ne0];then useraddmysql-s/sbin/nologin-M action"mysqluseraddedsuccessfully"/bin/true else action"$(echo-e"\e[31;47;5mmysqluseralreadyexists\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-Rmysql:mysql/data/mysql chown-Rmysql:mysql/usr/local/mysql #edit/etc/my.cnf #SERVERID=`ifconfigeth0|grep"inetaddr"|awk'{print$2}'|awk-F.'{print$3$4}'` cat>>/etc/my.cnf< /etc/profile.d/mysql.sh source/etc/profile.d/mysql.sh echo"============================MySQL5.7.29installcompleted=========================" ps-eostart,cmd,pid|grepmysql /usr/local/mysql/bin/mysqladmin-uroot-p"$Pass"password$mysqlrootpwd
[root@localhost~]#shinstall.mysql.shmysqlroot [root@localhost~]#source/etc/profile.d/mysql.sh
说明:mysqlroot为安装脚本修改MySQL服务默认密码后的新的密码
[root@localhost~]#mysql-uroot-p'mysqlroot'-e"selectnow()" mysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure. +---------------------+ |now()| +---------------------+ |2020-10-1316:18:47| +---------------------+
到此处MySQL服务启动成功!
总结
到此这篇关于shell脚本一键安装MySQL5.7.29的文章就介绍到这了,更多相关shell脚本一键安装MySQL内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!