MySql 错误 1045 (28000): 用户 'root'@'localhost' 访问被拒绝(使用密码:NO)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42742075/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:15:09  来源:igfitidea点击:

MySql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

mysql

提问by Alan P.

I've tried multiple solutions from StackOverflow but haven't had any success. I'm on Mac OSX (Sierra 10.12.3) trying to create a new database and user. From terminal I enter:

我已经尝试了 StackOverflow 的多种解决方案,但都没有成功。我在 Mac OSX (Sierra 10.12.3) 上尝试创建一个新的数据库和用户。从终端我输入:

mysql -u root

which outputs this error:

输出此错误:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

错误 1045 (28000): 用户 'root'@'localhost' 访问被拒绝(使用密码:NO)

To try and resolve it I stopped mysql from 'System Preferences', then from terminal typed:

为了尝试解决它,我从“系统偏好设置”停止了 mysql,然后从终端输入:

sudo mysqld_safe —skip-grant-tables

I opened a second tab and entered:

我打开了第二个选项卡并输入:

mysql -u root

Then from in mysql:

然后从 mysql:

update mysql.user set password_expired = 'N', authentication_string=PASSWORD('newpassword') where user = 'root';

flush privileges;

I then restart the computer (killing the process with CMD + C doesn't work). After restarting, trying mysql -u rootstill produces the same error.

然后我重新启动计算机(使用 CMD + C 终止进程不起作用)。重新启动后,尝试mysql -u root仍然产生相同的错误。

I am able to access mysql via a MySQL client and a non-root user.

我可以通过 MySQL 客户端和非 root 用户访问 mysql。

Any help is appreciated.

任何帮助表示赞赏。

采纳答案by Ansel Faillace

Just to confirm: You are sure you are running MySQL 5.7, and not MySQL 5.6 or earlier version. And the plugin column contains "mysql_native_password". (Before MySQL 5.7, the password hash was stored in a column named password. Starting in MySQL 5.7, the password column is removed, and the password has is stored in the authentication_string column.) And you've also verified the contents of authentication string matches the return from PASSWORD('mysecret'). Also, is there a reason we are using DML against the mysql.user table instead of using the SET PASSWORD FOR syntax? – spencer7593

确认一下:您确定您运行的是 MySQL 5.7,而不是 MySQL 5.6 或更早版本。插件列包含“mysql_native_password”。(在 MySQL 5.7 之前,密码哈希存储在名为 password 的列中。从 MySQL 5.7 开始,密码列被删除,密码 has 存储在 authentication_string 列中。)并且您还验证了身份验证字符串的内容匹配来自 PASSWORD('mysecret') 的返回值。另外,我们是否有理由对 mysql.user 表使用 DML 而不是使用 SET PASSWORD FOR 语法?– 斯宾塞7593

So Basically Just make sure that the Plugin Column contains "mysql_native_password".

所以基本上只要确保插件列包含“mysql_native_password”。

Not my work but I read comments and noticed that this was stated as the answer but was not posted as a possible answer yet.

不是我的工作,但我阅读了评论并注意到这被列为答案,但尚未作为可能的答案发布。

回答by Pramod Patil

For security reason mysql -u root wont work untill you pass -p in command so try with below way

出于安全原因,mysql -u root 将无法工作,直到您在命令中传递 -p,因此请尝试以下方式

 mysql -u root -p[Enter]
 //enter your localhost password

回答by gud3

mysql -u root -p;

And mysql will ask for the password

并且 mysql 会询问密码

回答by Alex Angelico

just use:

只需使用:

$ sudo mysql

without the "-u root" parameter.

没有“-u root”参数。

回答by lofihelsinki

If you need to skip the password prompt for some reason, you can input the password in the command (Dangerous)

如果由于某种原因需要跳过密码提示,可以在命令中输入密码(危险)

mysql -u root --password=secret

回答by b2ok

You must run your mysql by xampp-controle.exe in folder XAMPP. After that login:

您必须通过 XAMPP 文件夹中的 xampp-controle.exe 运行您的 mysql。登录后:

mysql -u root

回答by invalid entry

Is it possible the root password is not what you think it is? Have you checked the file /root/.mysql_secret for the password? That is the default location for the automated root password that is generated from starting from version 5.7.

是否有可能 root 密码不是您认为的那样?您是否检查过文件 /root/.mysql_secret 的密码?这是从 5.7 版开始生成的自动 root 密码的默认位置。

cat /root/.mysql_secret

回答by daewoo

Try this (on Windows, i don't know how in others), if you have changed password a now don't work.

试试这个(在 Windows 上,我不知道其他人如何),如果您更改了密码,现在不起作用。

1) kill mysql 2) back up /mysql/data folder 3) go to folder /mysql/backup 4) copy files from /mysql/backup/mysql folder to /mysql/data/mysql (rewrite) 5) run mysql

1)杀死mysql 2)备份/mysql/data文件夹3)转到文件夹/mysql/backup 4)将文件从/mysql/backup/mysql文件夹复制到/mysql/data/mysql(重写)5)运行mysql

In my XAMPP on Win7 it works.

在我的 Win7 上的 XAMPP 中,它可以工作。

回答by mohammed_ayaz

Comment by @Niagaradadhelped me. I was entering the wrong password the whole time.

@Niagaradad 的评论帮助了我。我一直在输入错误的密码。

Notice the error message

注意错误信息

ERROR 1045 (28000): Access denied for user 'ayaz'@'localhost' (using password: YES)

错误 1045 (28000):用户 'ayaz'@'localhost' 访问被拒绝(使用密码:是)

It says, Password: Yes. That means I am sending the password to SQL and that is wrong.

它说,密码:是的。这意味着我将密码发送到 SQL,这是错误的。

Usually root account doesn't have passwordif you haven't set one. If you have installed mysql via homebrewthen root account won't have a password.

如果您没有设置密码,通常root 帐户没有密码。如果您通过自制软件安装了 mysql,那么root 帐户将没有密码。

Here is the comment.

这是评论。

so, not exactly the same then. NO means you are not sending a password to MySQL. YES means you are sending a password to MySQL but the incorrect one. Did you specifically set a password for the mysql root user when you installed MySQL? By default there is no password so you can use mysql -u root -p and hit enter.

所以,不完全一样。NO 表示您没有向 MySQL 发送密码。YES 表示您正在向 MySQL 发送密码,但该密码不正确。你安装MySQL的时候有没有专门给mysql root用户设置过密码?默认情况下没有密码,因此您可以使用 mysql -u root -p 并按 Enter。