我最近安装了MySQL,似乎在安装后我必须重置密码。它不让我做别的事。

现在我已经用通常的方式重置了密码:

update user set password = password('XXX') where user = root;

(顺便说一句:我花了很长时间才发现MySQL出于某种奇怪的原因将字段“password”重命名为“authentication_string”。我对这样的变化感到很不安。

不幸的是,似乎我需要改变密码不同的方式,我不知道。也许在座有人已经遇到过这个问题了?


当前回答

MySQL 5.7。X你需要切换到本地密码才能改变它,比如:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';

其他回答

如果您使用MySQL 5.7.6及以上版本:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

如果你使用MySQL 5.7.5及更早版本:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

MySQL文档

5.7版本。“password”字段已被删除。'authentication_string'替换它

use mysql;
update user set authentication_string=password('123456') where user='root';
flush privileges;

UPDATE user SET authentication_string=PASSWORD("MyPassWord") WHERE user ='root'; 错误1064(42000):你有一个错误的SQL语法;查看MySQL服务器版本对应的手册,在第一行'("MyPassWord") WHERE User='root "附近使用正确的语法

解决与

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

以下网站参考资料

https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

这招对我很管用:

ALTER USER(用户名)

我在这里找到的: http://dev.mysql.com/doc/refman/5.7/en/alter-user.html#alter-user-current

要更改用户密码:

首先,以root登录 $ sudo mysql 修改用户密码 修改用户名:USER @ localhost