shell脚本一键安装MySQL5.7.29的方法
本文参考51CTO博客作者wjw555的作品
脚本内容:
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
[root@localhost ~]# sh install.mysql.sh mysqlroot [root@localhost ~]# source /etc/profile.d/mysql.sh
说明: mysqlroot 为安装脚本修改MySQL服务默认密码后的新的密码
[root@localhost ~]# mysql -uroot -p'mysqlroot' -e "select now()" mysql: [Warning] Using a password on the command line interface can be insecure. +---------------------+ | now() | +---------------------+ | 2020-10-13 16:18:47 | +---------------------+
到此处MySQL服务启动成功!
总结
到此这篇关于shell脚本一键安装MySQL5.7.29 的文章就介绍到这了,更多相关shell脚本一键安装MySQL内容请搜索潘少俊衡以前的文章或继续浏览下面的相关文章希望大家以后多多支持潘少俊衡!
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
本文地址:/shujuku/MySQL/101915.html