在 Mac 上安装后使用 ALTER USER 语句重置 MySQL 根密码

2021-11-20 00:00:00 macos mysql

我是 Mac 体验的新手.我最近安装了 MySQL,似乎我必须在安装后重置密码.它不会让我做任何其他事情.

I'm new to the whole Mac experience. I recently installed MySQL and it seems I have to reset the password after install. It won't let me do anything else.

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

Now I already reset the password the usual way:

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

(顺便说一句:我花了很长时间才发现 MySQL 出于某种奇怪的原因将字段密码"重命名为authentication_string".我对这样的更改感到非常沮丧.)

(BTW: took me ages to work out that MySQL for some bizarre reason has renamed the field 'password' to 'authentication_string'. I am quite upset about changes like that.)

不幸的是,我似乎需要以我不知道的不同方式更改密码.也许这里有人已经遇到过这个问题?

Unfortunately it seems I need to change the password a different way that is unknown to me. Maybe someone here has already come across that problem?

推荐答案

如果这不是您第一次设置密码,请尝试以下方法:

If this is NOT your first time setting up the password, try this method:

mysql> UPDATE mysql.user SET Password=PASSWORD('your_new_password')
           WHERE User='root'; 

如果您收到以下错误,很可能您以前从未设置过密码:

And if you get the following error, there is a high chance that you have never set your password before:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 

要第一次设置密码:

mysql> SET PASSWORD = PASSWORD('your_new_password');
Query OK, 0 rows affected, 1 warning (0.01 sec)

<小时>

参考:https://dev.mysql.com/doc/refman/5.6/en/alter-user.html

相关文章