tnblog
首页
登录

shell脚本强制修改MySQL --root密码

89人阅读 2019/12/14 9:37 总访问:2457 评论:0 手机 收藏
分类: Linuxshell

话不多说直接拿去撸;



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','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','root',password('${pwd}'),'127.0.0.1')"

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','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','root',password('${pwd}'),'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"


评价
写代码里面打羽毛球最好的
排名
6
文章
6
粉丝
16
评论
8
{{item.ArticleTitle}}
{{item.BlogName}} : {{item.Content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2020TNBLOG.NET