在 Mac 上安装后使用 ALTER USER 语句重置 MySQL root 密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33467337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reset MySQL root password using ALTER USER statement after install on Mac
提问by dengar81
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.
我是整个 Mac 体验的新手。我最近安装了 MySQL,似乎我必须在安装后重置密码。它不会让我做任何其他事情。
Now I already reset the password the usual way:
现在我已经按照通常的方式重置了密码:
update user set password = password('XXX') where user = root;
(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.)
(顺便说一句:我花了很长时间才发现 MySQL 出于某种奇怪的原因将字段“密码”重命名为“authentication_string”。我对这样的更改感到非常沮丧。)
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?
不幸的是,我似乎需要以我不知道的不同方式更改密码。也许这里有人已经遇到过这个问题?
回答by Madmint
If this is NOTyour first timesetting 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.
To set up your password for the first time:
首次设置密码:
mysql> SET PASSWORD = PASSWORD('your_new_password');
Query OK, 0 rows affected, 1 warning (0.01 sec)
Reference: https://dev.mysql.com/doc/refman/5.6/en/alter-user.html
回答by shnraj
If you started mysql using mysql -u root -p
如果您使用 mysql 启动 mysql -u root -p
Try ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
尝试 ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Source: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
来源:http: //dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
回答by Ezio Shiki
I have same problem on Mac
我在 Mac 上有同样的问题
First, log in mysql with sandbox mode
一、用沙盒模式登录mysql
mysql -u <user> -p --connect-expired-password
Then, set password
然后设置密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('XXXX');
Query OK, 0 rows affected, 1 warning (0.01 sec)
It works for me ~
对我有用~
通过:https: //dba.stackexchange.com/questions/118852/your-paswssword-has-expired-after-restart-mysql-when-updated-mysql-5-7-8-rcde
回答by Johel Alvarez
If you use MySQL 5.7.6 and later:
如果您使用 MySQL 5.7.6 及更高版本:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
If you use MySQL 5.7.5 and earlier:
如果您使用 MySQL 5.7.5 及更早版本:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
回答by Vadim Smilansky
On MySQL 5.7.x you need to switch to native password to be able to change it, like:
在 MySQL 5.7.x 上,您需要切换到本机密码才能更改它,例如:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
回答by Vadim Smilansky
Run these:
运行这些:
$ cd /usr/local/mysql/bin
$ ./mysqladmin -u root password 'password'
Then run
然后运行
./mysql -u root
It should log in. Now run FLUSH privileges;
它应该登录。现在运行 FLUSH 权限;
Then exit the MySQL console and try logging in. If that doesn't work run these:
然后退出 MySQL 控制台并尝试登录。如果这不起作用,请运行以下命令:
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET authentication_string=PASSWORD("XXXXXXX") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Change xxxxxx to ur new password. Then try logging in again.
将 xxxxxx 更改为您的新密码。然后再次尝试登录。
Update. See this http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
更新。看到这个http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
It should solve your problem.
它应该可以解决您的问题。
If you are on oracle try this
如果你在 oracle 上试试这个
ALTER USER username IDENTIFIED BY password
回答by Mateo Barahona
Maybe try that ?
也许试试看?
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('XXX');
or
或者
SET PASSWORD FOR 'root'@'%' = PASSWORD('XXX');
Depending on which access you use.
取决于您使用的访问权限。
(and not sure you should change yourself field names...)
(并且不确定您是否应该更改自己的字段名称...)
回答by Manoj Behera
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Use this line...
使用这条线...
回答by Siddharth Pandey
UPDATE user SET authentication_string=PASSWORD("MyPassWord") WHERE User='root'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("MyPassWord") WHERE User='root'' at line 1
更新用户 SET authentication_string=PASSWORD("MyPassWord") WHERE User='root'; ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '("MyPassWord") WHERE User='root'' 附近使用正确的语法
Resolved with
解决了
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Reference from below site
来自以下网站的参考
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
回答by Kenny Alvizuris
On Ver 14.14 Distrib 5.7.19, for macos10.12 (x86_64)
, I logged in as:
mysql -uroot -p
then typed in the generated password by MySQL when you install it. Then..
在 上Ver 14.14 Distrib 5.7.19, for macos10.12 (x86_64)
,我登录为:
mysql -uroot -p
然后在安装时输入 MySQL 生成的密码。然后..
ALTER USER 'root'@'localhost' IDENTIFIED BY '<new_password>';
ALTER USER 'root'@'localhost' IDENTIFIED BY '<new_password>';
Example:
例子:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ab1234';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ab1234';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ mysql -uroot -p
And you can type in 'Ab1234'
你可以输入'Ab1234'