每日一shell(十一)mysql强制自动修改密码

2022年 10月 18日 发表评论
免费、便宜/高性价比 服务器汇总(已更新):点击这里了解

本站教程收集整理的这篇文章主要介绍了每日一shell(十一)mysql强制自动修改密码,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。

如果不记得MysqL的root密码,那么就只能强制修改密码了,使用sHell轻松自动修改密码:

#!/bin/bash  #Author Aiker  PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  export PATH  read -p "Please input your new password:" c  pwd=$c  service MysqLd stop  MysqLd_safe --skip-grant-tables&  echo '正在修改密码...';  echo 'The set password...';  sleep 6  MysqL -uroot -e "insert into Mysql.user(SELEct_priv,Insert_priv,update_priv,delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,CREATE_TMp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routIne_priv,Alter_routIne_priv,Create_user_priv,Event_priv,trigger_priv,create_tablespace_priv,User,password,host)values('Y','Y','root',password('${pwD}'),'127.0.0.1')"  MysqL -uroot -e "insert into Mysql.user(SELEct_priv,'localhost')"  MysqL -uroot -e "updatE Mysql.user SET password=passworD('${pwD}') WHERE user='root'";  MysqL -uroot -e "updatE Mysql.user SET authentication_String=passworD('${pwD}') WHERE user='root'";  MysqL -uroot -e "FLUSH PRIVILEGES";  pkill -9 MysqLd_safe  pkill -9 MysqLd  sleep 2  service MysqLd start    echo '==========================================='  echo "MysqL root密码成功修改为: ${pwD}"  echo "The root password set ${pwD}  successuful"

测试效果:

[root@aaa ~]# sh MysqLpwd.sh   Please input your new password:12345678  ShutTing down Mysql.. succesS!   正在修改密码...  The set password...  2018-03-14T18:19:51.793872Z MysqLd_safe Logging to '/data/MysqL/aaa.err'.  2018-03-14T18:19:51.814649Z MysqLd_safe StarTing MysqLd daemon with databases from /data/MysqL  ERROR 1054 (42S22) at line 1: UnkNown column 'password' in 'field list'  ERROR 1054 (42S22) at line 1: UnkNown column 'password' in 'field list'  ERROR 1054 (42S22) at line 1: UnkNown column 'password' in 'field list'  MysqLpwd.sh: line 17: 45426 Killed                  MysqLd_safe --skip-grant-tables  StarTing MysqL succesS!   ===========================================  MysqL root密码成功修改为: 12345678  The root password set 12345678  successuful  [root@aaa ~]# MysqL -uroot -p           Enter password:   Welcome to the MysqL monitor.  Commands end with ; or g.  Your MysqL connection id is 2  Server version: 5.7.21-log source diStribution    copyright (C) 2000,2018,Oracle and/or its affiliates. All rights reserved.    Oracle is a registered Trademark of Oracle Corporation and/or its  affiliates. Other names may be Trademarks of their respective  owners.    Type 'Help;' or 'h' for Help. Type 'c' to clear the current input statement.    MysqL> quit  Bye

本站总结

以上是本站教程为你收集整理的每日一shell(十一)mysql强制自动修改密码全部内容,希望文章能够帮你解决每日一shell(十一)mysql强制自动修改密码所遇到的程序开发问题。

如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。

小咸鱼

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: