码迷,mamicode.com
首页 > 数据库 > 详细

mysql数据库密码忘记恢复脚本

时间:2018-02-27 10:57:12      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:sdff

#!/bin/bash
skip=awk ‘/skip-grant-tables/{print $1}‘ /etc/my.cnf
if [ ! -n "$skip" ];then ##判断是否有skip-grant-tables
sed -i ‘/^[mysqld]/askip-grant-tables‘ /etc/my.cnf ##变量为空就执行插入
else
sed -i ‘s/#skip-grant-tables/skip-grant-tables/g‘ /etc/my.cnf ##变量不为空就加注释
fi
sed -i ‘s/validate_password/#validate_password/g‘ /etc/my.cnf
systemctl stop mysqld
systemctl start mysqld
expect << EOF
spawn mysql
expect "mysql>" {send "update mysql.user set authentication_string=password(\"123456\") where user=\"root\";\n"}
expect "mysql>" {send "flush privileges;\n"}
expect "mysql>" {send "quit\n"}
expect "mysql>" {send "quit\n"}
EOF
sed -i ‘s/skip-grant-tables/#skip-grant-tables/g‘ /etc/my.cnf
sed -i ‘s/#validate_password/validate_password/g‘ /etc/my.cnf
systemctl stop mysqld
systemctl start mysqld

mysql数据库密码忘记恢复脚本

标签:sdff

原文地址:http://blog.51cto.com/13587169/2073343

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!