# reset-root.sh
# 功能:初始化mysql-5.7初始密码的脚本 root/root
# 时间:2017/08/02 10:46:07
#!/bin/bash
mycnf=" /etc/my.cnf"
# IMPORTANT
sed -i '/symbolic-links=0/a\skip-grant-tables=1' $mycnf
service mysqld restart
if [ `rpm -qa | grep expect | wc -l` -eq 0 ]
then
yum clean all
yum install -y expect
fi
/usr/bin/expect <<-EOF
spawn mysql -uroot
expect "*mysql>"
send "use mysql;\r"
send "update user set authentication_string = password('root'), \
password_expired = 'N', password_last_changed = now() where user = 'root';\r";
send "flush privileges;\r"
send "delete from user where user<>'root';\r"
send "update user set host='%' where user='root';\r"
send "flush privileges;\r"
# 退出MySQL
expect "*mysql>"
send "exit;\r";
expect eof
EOF
# IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT
sed -i -e '/skip-grant-tables=1/d' $mycnf
service mysqld restart
重置:mysql-5.7 root用户密码为:root
最新推荐文章于 2023-01-04 23:03:51 发布