mysql root 密码剩余
由于某种原因,下面的脚本不会重置 root 密码。该脚本的工作原理是执行这些步骤,但是当我尝试使用新密码以 root 身份重新登录 mysql 时,它无法识别更改并坚持要求我使用旧密码。
这是下面的脚本:
#!/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 时,它会抱怨并且仅在我使用旧密码时才有效。
有什么想法吗?
干杯
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.
Here is the script below:
#!/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."
So when I try mysql -uroot -pakimbo it complains and only works when i use the old password.
Any ideas?
cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不直接使用 mysqladmin 命令呢?
mysqladmin -u root -p'oldpassword' 密码 newpass
这也可用于更改其他用户的密码:
mysqladmin -u sql_username -p oldpassword 密码 newpass
Why not just use the
mysqladmin
command?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
为什么你想像手册中那样从 SQL 使用 mysqladmin 来执行此操作
Why do you want to do it from SQL use mysqladmin as in the manual
请参阅http://dev.mysql.com/doc/refman/ 5.0/en/resetting-permissions.html
有一个 --skip-grant-tables 选项可以在启动时运行。然后以 root 身份连接,重置密码,然后重新启动(不使用跳过授予选项)
See http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
There's a --skip-grant-tables option you can run on startup. Then connect as root, reset your password and then restart w/o the skip grant option