博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 安装卸载自动化脚本
阅读量:4951 次
发布时间:2019-06-11

本文共 3732 字,大约阅读时间需要 12 分钟。

#!/bin/sh#mkdir  /root/mysql#tar -xvf   mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar -C /root/mysql#cd  /root/mysql#yum -y install perl-Data-Dumper perl-JSON perl-Time-HiRes#rpm -Uvh mysql-community-*.rpm#systemctl start mysqldlanguage(){    echo $LANG |grep -q zh    if [ $? -eq 0 ];then        return 0    else        return 1    fi}menu(){    clear    language    if [ $? -eq 0 ];then       echo "  ##############----Menu----##############"       echo "# 1. 安装mysql"       echo "# 2. 修改数据库的初始密码"       echo "# 3. 配置数据库"       echo "# 4. 卸载数据库"       echo "# 5. 退出"       echo "  ########################################"    else       echo "  ##############----Menu----##############"       echo "# 1. Install mysql"       echo "# 2. change mysql first password"       echo "# 3. configure mysql"       echo "# 4. remove MySQL"       echo "# 5. exit"       echo "  ########################################"    fi}choice(){    language    if [ $? -eq 0 ];then        read -p "请选择一个菜单[1-5]:" select    else        read -p "Please choice a menu[1-5]:" select    fi}install_mysql(){        language        echo "请上传数据库安装包"        rz -E        mkdir  /root/mysql        tar -xvf   mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar -C /root/mysql        cd  /root/mysql        rm -rf mysql-community-devel-5.7.25-1.el7.x86_64.rpm  mysql-community-embedded-*.rpm  mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm  mysql-community-test-5.7.25-1.el7.x86_64.rpm        yum -y install perl-Data-Dumper perl-JSON perl-Time-HiRes net-tools        rpm -Uvh mysql-community-*.rpm        systemctl start mysqld        if [ $? -eq 0 ]        then                echo "安装成功"        else                echo $?                exit        fi}change_password(){        language        PORT="3306"        USERNAME="root"        PASSWORD=$(cat /var/log/mysqld.log |grep  'temporary password' | awk -F:  '{print $4}' | sed s/[[:space:]]//g)        echo $PASSWORD        mysql_conn="mysql -P${PORT}  -u${USERNAME}   --connect-expired-password    --password=${PASSWORD}"        echo  $mysql_conn        NEWPASS="1234"#       sql="alter mysql.user 'root'@'localhost' identified by \"${NEWPASS}\";flush privileges;" #       echo $sql        $mysql_conn  -e  "set global validate_password_policy=0;"        $mysql_conn  -e  "set global validate_password_length=4;"        $mysql_conn  -e  "set password for 'root'@'localhost'=password('1234');flush privileges;"        if [ $? -eq 0 ]        then                echo "修改密码成功"        else                echo $?                exit        fi}configure_mysql(){        cp /etc/my.cnf  /etc/my.cnf.default        sed -i '3a\[client]\t\ndefault-character-set=utf8 ' /etc/my.cnf        sed -i '/\[mysqld\]/a\character-set-server=utf8\nvalidate_password_length=4\nvalidate_password_policy=0 '  /etc/my.cnf        systemctl restart mysqld        if [ $? -eq 0 ]        then             echo "修改默认编码为utf8成功"           sleep 3        else             echo $?              exit        fi      }remove_mysql(){    language        systemctl stop mysqld        mysql_pack=$(rpm -qa|grep mysql)        for i in  $mysql_pack        do                rpm -e ${i} --nodeps        done        rm -rf /var/lib/mysql        rm -rf /usr/bin/mysql        rm -rf /usr/lib64/mysql        rm -rf /usr/share/mysql    rm -rf /usr/include/mysql    rm -rf  /var/log/mysqld.log        if [ $? -eq 0 ]        then             echo "卸载成功"        else             echo $?              exit        fi}while truedomenuchoicecase $select in1)      install_mysql      ;;2)      change_password      ;;3)      configure_mysql      ;;4)      remove_mysql      ;;5)      quit;break      ;;esacdone

 

转载于:https://www.cnblogs.com/liucsxiaoxiaobai/p/11515714.html

你可能感兴趣的文章
活现被翻转生命
查看>>
POJ 1228
查看>>
SwaggerUI+SpringMVC——构建RestFul API的可视化界面
查看>>
springmvc怎么在启动时自己执行一个线程
查看>>
流操作的规律
查看>>
Python基础学习15--异常的分类与处理
查看>>
javascript运算符的优先级
查看>>
React + Redux 入门(一):抛开 React 学 Redux
查看>>
13位时间戳和时间格式化转换,工具类
查看>>
vue router-link子级返回父级页面
查看>>
C# 通知机制 IObserver<T> 和 IObservable<T>
查看>>
Code of Conduct by jsFoundation
查看>>
div 只显示两行超出部分隐藏
查看>>
C#小练习ⅲ
查看>>
debounce、throttle、requestAnimationFrame
查看>>
linux下的C语言快速学习—进程和文件
查看>>
电源防反接保护电路
查看>>
stm32 堆和栈(stm32 Heap & Stack)
查看>>
SpringMVC从入门到精通之第三章
查看>>
JS基础-dom操作
查看>>