mysql root密码休息 [英] mysql root password rest

查看:119
本文介绍了mysql root密码休息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,下面的脚本不会重置root密码.该脚本的工作方式是执行这些步骤,但是当我尝试使用新密码以root用户身份重新登录到mysql时,它无法识别更改,并坚持要使用旧密码.

For some reason, the script below doesn't reset the root password. The script works in that it performs the steps, but when I try to log back in to mysql as root with the new password, it doesn't recognize the change and insists I use the old one.

这是下面的脚本:

#!/bin/bash

echo "Resetting root password"
sudo /etc/init.d/mysql stop
sleep 2


if [ -f /root/mysql.reset.sql ]; then
    rm -f /root/mysql.reset.sql
    touch /root/mysql.reset.sql
else
    touch /root/mysql.reset.sql
fi

echo "UPDATE mysql.user SET Password=PASSWORD('akimbo') WHERE User='root'; FLUSH        
PRIVILEGES;" >> /root/mysql.reset.sql
mysqld_safe --init-file=/root/mysql.reset.sql &
/etc/init.d/mysql start
sleep 2

echo "Done setting mysql password for user root. Password is password."

因此,当我尝试mysql -uroot -pakimbo时,它会抱怨并且仅在使用旧密码时有效.

So when I try mysql -uroot -pakimbo it complains and only works when i use the old password.

有什么想法吗?

欢呼

推荐答案

为什么不只使用mysqladmin命令?

mysqladmin -u root -p'oldpassword' password newpass

这也可以用于更改其他用户的密码:

This can also be used for changing other user's passwords as well:

mysqladmin -u sql_username -p oldpassword password newpass

这篇关于mysql root密码休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆