使用命令行更改mysql用户密码 [英] Change mysql user password using command line

查看:334
本文介绍了使用命令行更改mysql用户密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用命令行更新数据库用户的密码,但该密码对我不起作用.这是我正在使用的代码:

I'm trying to update the password for a database user using the command line, and it's not working for me. This is the code I'm using:

mysql> UPDATE user SET password=PASSWORD($w0rdf1sh) WHERE user='tate256';

有人可以告诉我这段代码有什么问题吗

Could someone tell me what's wrong with this code.

推荐答案

在您的代码中,尝试将密码放在单引号内.另外,根据mysql的文档,工作-

In your code, try enclosing password inside single quote. Alternatively, as per the documentation of mysql, following should work -

SET PASSWORD FOR 'jeffrey'@'localhost' = PASSWORD('cleartext password');

FLUSH PRIVILEGES;

最后一行很重要,否则不幸的是您的密码更改不会生效.

The last line is important or else your password change won't take effect unfortunately.

我在本地进行了测试,并且可以正常工作-

I ran a test in my local and it worked -

mysql>  set password for 'test' = PASSWORD('$w0rdf1sh');
Query OK, 0 rows affected (0.00 sec)

我的是版本5.您可以使用以下命令来确定您的版本-

Mine is version 5. You can use following command to determine your version -

SHOW VARIABLES LIKE "%version%";

这篇关于使用命令行更改mysql用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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