MySQL '用户'root'@'localhost'的访问被拒绝(使用密码:NO)'

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

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

mysql

提问by ziiweb

I'm trying to set the password of the user root but I'm gettin the error below, any idea?

我正在尝试设置用户 root 的密码,但出现以下错误,知道吗?

+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*436576511F70A4E3B305E1AB8E209851945D8687' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


mysql> exit
Bye
root@tirengarfio:/var/www/rs2# mysqladmin -u root password foo,
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

回答by djrconcepts

$ mysqladmin -u root -p password
Enter password: 
New password: 
Confirm new password:

passwordis to be typed literally. It's a command. You don't have to substitute passwordwith your actual password.

password是按字面写的。这是一个命令。您不必替换password为您的实际密码。

回答by Hamsavardhini Deventhiran

# /etc/init.d/mysqld stop

Stopping MySQL: [ OK ]

# mysqld_safe --skip-grant-tables &

[1] 13694

# Starting mysqld daemon with databases from /var/lib/mysql



# mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.0.77 Source distribution



Type 'help;' or '\h' for help. Type '\c' to clear the buffer.



mysql>

回答by MiDo

Set/Change password:

设置/更改密码:

mysqladmin -u root -p password

Login to MySQL console:

登录 MySQL 控制台:

mysql -u root -p

To exit the console:

要退出控制台:

.\q

回答by Kostya Berger

Those are all good answers, but don't quite touch the deep cause of the problem one most likely has if faced with the OP question. That is, not knowing the ORIGINAL "starting" password created during the installation time.

这些都是很好的答案,但如果面对 OP 问题,请不要完全触及最有可能出现的问题的深层原因。也就是说,不知道在安装期间创建的原始“开始”密码。

And all these command lines with "-u root ..." etc. imply knowing and using THAT password.

所有这些带有“-u root ...”等的命令行意味着知道并使用那个密码。

Now this part from the original installation message may help anyone facing the problem above:

现在原始安装消息中的这部分可能会帮助任何面临上述问题的人:

Initial password for first time use of MySQL is saved in $HOME/.mysql_secret
ie. when you want to use "mysql -u root -p" first you should see password
in /root/.mysql_secret

首次使用 MySQL 的初始密码保存在 $HOME/.mysql_secret 中,
即。当您想首先使用“mysql -u root -p”时,您应该
在 /root/.mysql_secret 中看到密码

回答by robkriegerflow

This is basically a more detailed version of a previous answer.

这基本上是先前答案的更详细版本。

In your Terminal, go to the location of your utility program, mysqladmin

在您的终端中,转到实用程序mysqladmin的位置

For example, if you were doing local development and using an application like M/W/XAMP, you might go to the directory:

例如,如果您正在进行本地开发并使用 M/W/XAMP 之类的应用程序,您可能会转到以下目录:

/Applications/MAMP/Library/bin

/应用程序/MAMP/库/bin

This is where mysqladmin resides.

这是 mysqladmin 所在的位置。

If you're not using an application like MAMP, you may also be able to find your local installation of mysql at: /usr/local/mysql

如果您没有使用像 MAMP 这样的应用程序,您也可以在以下位置找到 mysql 的本地安装:/usr/local/mysql

And then if you go to: /usr/local/mysql/bin/

然后如果你去:/usr/local/mysql/bin/

You are in the directory where mysqladmin resides.

您位于 mysqladmin 所在的目录中。

Then, to change the password, you will do the following:

然后,要更改密码,您将执行以下操作:

  1. At your Terminal prompt enter the exactcommand below (aka copy and paste) and press enter. The word "password" is part of the command, so don't be confused and come to the conclusion that you need to replace this word with some password you created previously or want to use in the future. You will have a chance to enter a new password soon enough, but it's not in this first command that you will do that:

    ./mysqladmin -u root -p password

  2. The Terminal will ask you to enter your original or initial password, not a new one yet. From the above image you provided, it looks like you have one already created, so enter it here:

  1. 在您的终端提示符下输入下面的确切命令(又名复制和粘贴),然后按enter。“密码”一词是命令的一部分,所以不要混淆并得出结论,您需要将这个词替换为您之前创建的某个密码或将来要使用的密码。您将有机会尽快输入新密码,但在第一个命令中您不会这样做:

    ./mysqladmin -u root -p 密码

  2. 终端会要求你输入你的原始或初始密码,而不是一个新的还没有。从您提供的上图来看,您似乎已经创建了一个,因此请在此处输入:

Enter password:oldpassword

Enter password:旧密码

  1. The Terminal will ask you to enter a new password. Type it here and press enter:
  1. 终端会要求您输入新密码。在此处输入并按Enter键:

New password:newpassword

New password:新密码

  1. Then the Terminal will ask you to confirm the new password. Type it here and press enter:
  1. 然后终端会要求您确认新密码。在此处输入并按Enter键:

Confirm new password:newpassword

Confirm new password:新密码

Reset or restart your Terminal.

重置或重新启动您的终端。

In some cases, as with M/W/XAMP, you will have to update this new password in various files in order to get your application running properly again.

在某些情况下,与 M/W/XAMP 一样,您必须在各种文件中更新此新密码,以使您的应用程序再次正常运行。

回答by kevin Hyman

when trying to run this command i got the same error

尝试运行此命令时,我遇到了同样的错误

sudo mysqladmin create asteriskcdrdba

i simply add a few lines to the code

我只是在代码中添加几行

-u root -p

and pressed the enter key. i then typed my password and hit enter. Linux liked my command as nothing more was displayed

并按下回车键。然后我输入我的密码并按回车键。Linux 喜欢我的命令,因为没有显示更多内容

so maybe try

所以也许试试

sudo <your command here> -u <username> -p

after that hit enter and enter your password

然后点击回车并输入你的密码

回答by sunny

Firstly, go to the folder support-files on terminal, and start the server by mysql.server start, Secondly, go to the folder bin on terminal or type /usr/local/mysql/bin/mysqladmin -u root -p password

首先进入终端的support-files文件夹,通过mysql.server start启动服务器,然后进入终端文件夹bin或者输入/usr/local/mysql/bin/mysqladmin -u root -p password

It would ask you for the old temporary password which was given to you while installing Mysql, type that and type in your new password and it would work.

它会询问您在安装 Mysql 时提供给您的旧临时密码,输入该密码并输入您的新密码,它会起作用。

回答by Mirza

  • open my.cnfusing following path
  • my.cnf使用以下路径打开

C:\xampp\mysql\bin

C:\xampp\mysql\bin

  • under #The following options will be passed to all MySQL clients #passwordremove #comment sign if it is there password = "newpassword"

  • save file

  • close file

  • re-start mysql

  • under #以下选项将传递给所有 MySQL 客户端, 如果有则#password删除#注释符号password = "newpassword"

  • 保存存档

  • 关闭文件

  • 重新启动mysql