zoukankan      html  css  js  c++  java
  • 修改mysql用户密码脚本

    背景:因项目需要,定期修改mysql两个查询用户的密码;

    #!/bin/bash
    user=app1|app2
    oldPwd=12345|12345
    newPwd=45678|45678
    if [[ $user == *"|"* ]] && [[ $oldPwd == *"|"* ]] && [[ $newPwd == *"|"* ]];then
    	echo "user and pwd is ok"
    else
    	echo "must have 管道符|分隔,please add"
    	exit 3
    fi
    
    #用户
    user1=${user%|*}
    user2=${user#*}
    echo "第一个用户:$user1,第二个用户:$user2"
    
    #旧密码
    oldPwd1=${oldPwd%|*}
    oldPwd2=${oldPwd#*}
    
    #新密码
    newPwd1=${newPwd%|*}
    newPwd2=${newPwd#*}
    
    #更新第一个用户密码
    mysql -u$user1 -p$oldPwd1 -e "alter user user()  identified by '$newPwd1';"
    
    if [[ $? -eq 0 ]]
    then
    	echo "$user1:PWD_UPDATE SUCCESS"
    else
    	echo "$user1:PWD_UPDATE FAIL"
    	exit 2
    fi
    
    #更新第二个用户密码
    mysql -u$user2 -p$oldPwd2 -e "alter user user()  identified by '$newPwd2';"
    
    if [[ $? -eq 0 ]]
    then
    	echo "$user2:PWD_UPDATE SUCCESS"
    else
    	echo "$user2:PWD_UPDATE FAIL"
    	exit 1
    fi 
  • 相关阅读:
    开启Spring Boot 之旅
    Java笔试面试练习题---集合
    Python
    Python
    Redis -下载与基本使用
    Git
    Vue全家桶-Vue-router&Vuex
    Es6
    Vue-前端
    Django基础及实战
  • 原文地址:https://www.cnblogs.com/llwxhn/p/15526326.html
Copyright © 2011-2022 走看看