MySQL 用户“root”@“localhost”的访问被拒绝 - 终端,Mac
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25896082/
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
Stuck with Access Denied for user 'root'@'localhost' - Terminal, Mac
提问by Deedub
I am stuck when trying to access mysql. It's my first time so please be patient with me.
我在尝试访问 mysql 时卡住了。这是我的第一次,所以请耐心等待。
Initially I was try to set up Ruby and Rails and everything worked perfrectly expect access denied when connecting to the server, SO I ran this command.
最初我尝试设置 Ruby 和 Rails,并且一切正常,期望在连接到服务器时拒绝访问,所以我运行了这个命令。
mysql -uroot -p
I've tried various passwords including leaving it blank and get this error.
我尝试了各种密码,包括将其留空并出现此错误。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
I am assuming I need to reset the password for root user but I just can't seem to get it to work.
我假设我需要重置 root 用户的密码,但我似乎无法让它工作。
回答by Muur
One method:
一种方法:
- stop your MySQL server.
start your MySQL server with the
--skip-grant-tables
option. It allows you to connect to the server without a password./path/to/mysqld --skip-grant-tables &
connect to your server using the mysql client:
mysql
change the root password (replace NewPassordby what you want):
UPDATE mysql.user SET password=PASSWORD('NewPassord') WHERE user='root';
restart yout MySQL server.
- 停止你的 MySQL 服务器。
使用该
--skip-grant-tables
选项启动您的 MySQL 服务器。它允许您无需密码即可连接到服务器。/path/to/mysqld --skip-grant-tables &
使用 mysql 客户端连接到您的服务器:
mysql
更改 root 密码(用你想要的替换NewPassord):
UPDATE mysql.user SET password=PASSWORD('NewPassord') WHERE user='root';
重启你的 MySQL 服务器。
There are others ways to reset the MySQL root password: http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html
还有其他方法可以重置 MySQL 根密码:http: //dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html
回答by AmolR
I had a similar issue and this worked like a charm -
我有一个类似的问题,这就像一个魅力 -
Later versions of mysql implement a newer authentication scheme, not all libraries are up to date with this. You can revert to classic authentication by adding the following entry into your my.cnf
更高版本的 mysql 实现了更新的身份验证方案,并非所有库都是最新的。您可以通过将以下条目添加到 my.cnf 中来恢复经典身份验证
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
# Some libraries not compatible with latest authentication scheme as per the SO article [1].
default-authentication-plugin=mysql_native_password
Simply add the following in /private/etc/my.cnf
只需在 /private/etc/my.cnf 中添加以下内容
# Only allow connections from localhost
bind-address = 127.0.0.1
# 只允许来自本地主机的连接
bind-address = 127.0.0.1
Reference: https://www.reddit.com/r/mysql/comments/ae7rf4/access_denied_for_user_rootlocalhost_mac_os/
参考:https: //www.reddit.com/r/mysql/comments/ae7rf4/access_denied_for_user_rootlocalhost_mac_os/
回答by Vijay Surwase
@Muur the last step did not worked for me(mysql Ver 14.14 Distrib 5.7.19) i had to change query to update user set authentication_string=password('1111') where user='root';
update user set password_expired=N where user='root';
@Muur 最后一步对我不起作用(mysql Ver 14.14 Distrib 5.7.19)我不得不将查询更改为 update user set authentication_string=password('1111') where user='root';
update user set password_expired=N where user='root';