当前位置:Gxlcms > 数据库问题 > mysql数据库密码忘记恢复脚本

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

时间:2021-07-01 10:21:17 帮助过:57人阅读

#!/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

人气教程排行