密码重置 LINUX 后,用户 'root'@'localhost' 的访问被拒绝(使用密码:是)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19533441/
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
Access denied for user 'root'@'localhost' (using password: Yes) after password reset LINUX
提问by progrAmmar
I have a MySQL installed on my linux server, I forgot it's password so I went and changed it using the methods I found on the web. What I did was as follows:
我在我的 linux 服务器上安装了一个 MySQL,我忘记了它的密码,所以我使用我在网上找到的方法更改了它。我所做的如下:
/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql --user root mysql
SELECT * FROM user; // I checked if I could access the user table or not
update user SET password = PASSWORD('new_pass') WHERE user = 'root';
flush privileges;
exit
The update query did change the password as it showed me the number of rows affected and Query OK etc.
更新查询确实更改了密码,因为它向我显示了受影响的行数和查询确定等。
Then I restarted mysql
然后我重新启动了mysql
/etc/init.d/mysql stop
/etc/init.d/mysql start
Now when I logged in with the new password
现在当我使用新密码登录时
mysql -u root -p new_pass
it still gives me errors "ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Yes)"
它仍然给我错误 “ERROR 1045 (28000): Access denied for user 'root'@'localhost'(使用密码:是)”
Is there something that I am missing?
有什么我想念的吗?
采纳答案by progrAmmar
Actually I took a closer look at the user table in mysql database, turns out someone prior to me edited the ssl_type field for user root to SSL.
实际上,我仔细查看了 mysql 数据库中的用户表,结果发现在我之前有人将用户 root 的 ssl_type 字段编辑为 SSL。
I edited that field and restarted mysql and it worked like a charm.
我编辑了该字段并重新启动了 mysql,它就像一个魅力。
Thanks.
谢谢。
回答by Sharad
You can try this solution :-
你可以试试这个解决方案:-
To have mysql asking you for a password, you also need to specify the -p-option: (try with space between -p and password)
要让 mysql 要求您输入密码,您还需要指定 -p-option:(尝试在 -p 和密码之间使用空格)
mysql -u root -p new_password
In the Second linksomeone has commented the same problem.
在第二个链接中,有人评论了同样的问题。
回答by Divz
I was able to solve this problem by executing this statement
我能够通过执行这个语句来解决这个问题
sudo dpkg-reconfigure mysql-server-5.5
Which will change the root password.
这将更改root密码。
回答by tk_
You have to reset the password! steps for mac osx(tested and working) and ubuntu
您必须重置密码!mac osx(测试和工作)和 ubuntu 的步骤
Stop MySQL
停止 MySQL
$ sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
以安全模式启动它:
$ sudo mysqld_safe --skip-grant-tables
(above line is the whole command)
(上一行是整个命令)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
这将是一个持续的命令,直到该过程完成,所以打开另一个 shell/终端窗口,在没有密码的情况下登录:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
Start MySQL
启动 MySQL
sudo /usr/local/mysql/support-files/mysql.server start
your new password is 'password'.
您的新密码是“密码”。
回答by user3911158
I had the same problem. You have to write mysql -u root -p
我有同样的问题。你必须写mysql -u root -p
NOT mysql
or mysql -u root -p root_password
不是mysql
或mysql -u root -p root_password
回答by Belter
I meet the same problem, @progrAmmarenlightened me, "took a closer look at the user table in mysql database".
我遇到了同样的问题,@ progrAmmar启发了我,“仔细查看了 mysql 数据库中的用户表”。
My problem is not ssl_type, instead of the first field:Host. I changed the value by using
我的问题不是ssl_type,而是第一个字段:Host。我通过使用更改了值
update user set Host='localhost' where User='root' and Host='%';
update user set Host='localhost' where User='root' and Host='%';
in mysqld_safe --skip-grant-tables
model.
在mysqld_safe --skip-grant-tables
模型中。
Then it works well.
然后它运作良好。
回答by Stephen Schrauger
You may need to clear the plugin
column for your root account. On my fresh install, all of the root user accounts had unix_socket
set in the plugin
column. This was causing the root sql account to be locked only to the root unix account, since only system root could login via socket.
您可能需要清除plugin
根帐户的列。在我的全新安装中,所有 root 用户帐户都已unix_socket
在plugin
列中设置。这导致 root sql 帐户仅被锁定到 root unix 帐户,因为只有系统 root 可以通过套接字登录。
If you update user set plugin='' where User='root';flush privileges;
, you should now be able to login to the root account from any localhost unix account (with a password).
如果是update user set plugin='' where User='root';flush privileges;
,您现在应该可以从任何 localhost unix 帐户(使用密码)登录到 root 帐户。
See this AskUbuntu question and answerfor more details.
有关更多详细信息,请参阅此 AskUbuntu 问题和答案。
回答by Yang Wang
On mac os, please follow below steps:
在 mac os 上,请按照以下步骤操作:
Stop MySQL
停止 MySQL
$ sudo /usr/local/mysql/support-files/mysql.server stop Start it in safe mode:
$ sudo /usr/local/mysql/support-files/mysql.server stop 以安全模式启动:
$ sudo mysqld_safe --skip-grant-tables (above line is the whole command)
$ sudo mysqld_safe --skip-grant-tables(上面一行是整个命令)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
这将是一个持续的命令,直到该过程完成,所以打开另一个 shell/终端窗口,在没有密码的情况下登录:
$ mysql -u root
$ mysql -u 根
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; Start MySQL
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; 启动 MySQL
sudo /usr/local/mysql/support-files/mysql.server start your new password is 'password'.
sudo /usr/local/mysql/support-files/mysql.server start 你的新密码是'password'。
回答by Michal
In my case:
就我而言:
- /etc/init.d/mysql stop
- mysqld_safe --skip-grant-tables &
- /etc/init.d/mysql 停止
- mysqld_safe --skip-grant-tables &
(in new window)
(在新窗口中)
- mysql -u root
- mysql> use mysql;
- mysql> update user set authentication_string=password('password') where user='root';
- mysql>flush privileges;
- mysql> quit
- /etc/init.d/mysql restart
- mysql -u 根
- mysql> 使用 mysql;
- mysql> 更新用户设置 authentication_string=password('password') where user='root';
- mysql>刷新权限;
- mysql> 退出
- /etc/init.d/mysql 重启