博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
每日一shell(十一)mysql强制自动修改密码
阅读量:6222 次
发布时间:2019-06-21

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

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

#!/bin/bash#Author AikerPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHread -p "Please input your new password:" cpwd=$cservice mysqld stopmysqld_safe --skip-grant-tables&echo '正在修改密码...';echo 'The set password...';sleep 6mysql -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_safepkill -9 mysqldsleep 2service mysqld startecho '==========================================='echo "mysql root密码成功修改为: ${pwd}"echo "The root password set ${pwd}  successuful"

测试效果:

[root@aaa ~]# sh mysqlpwd.sh Please input your new password:12345678Shutting 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/mysqlERROR 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-tablesStarting MySQL SUCCESS! ===========================================mysql root密码成功修改为: 12345678The 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 2Server version: 5.7.21-log Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye

转载于:https://blog.51cto.com/m51cto/2087004

你可能感兴趣的文章
磁盘I/O的性能评估方法
查看>>
计算机排序算法
查看>>
My Emacs For Common Lisp
查看>>
数据处理函数
查看>>
网站目录下多出的 core 文件
查看>>
The Definitive Guide To Django 2 学习笔记(五) 第四章 模板 (一)基本模板系统
查看>>
Ubuntu下无法安装sun-java6-jdk的解决办法
查看>>
c++智能指针
查看>>
Serializable java序列化
查看>>
SQL PLUS远程连接
查看>>
SharePoint 2013 InfoPath 无法保存下列表单
查看>>
Ini操作类
查看>>
python登陆Tom邮箱的代码一例
查看>>
[实变函数]4.3 可测函数的构造
查看>>
sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
查看>>
[转]最全的常用正则表达式大全——包括校验数字、字符、一些特殊的需求等等本文出处...
查看>>
AndroidUI 控件命名格式
查看>>
数据库系统基本概念
查看>>
tcpCopy
查看>>
10个小众网
查看>>