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

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

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

mysqlwordpressmysql-error-1045

提问by Nasser Hadjloo

I'm new to MySQL, I'm trying to run WordPress in my Windows desktop and it needs MySQL.

我是 MySQL 的新手,我正在尝试在我的 Windows 桌面上运行 WordPress,它需要 MySQL。

I install everything with Web Platform Installerwhich is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.

我安装Web Platform Installer了 Microsoft 提供的所有内容。我从来没有为 MySQL 设置 root 密码,在安装 WordPress 的最后一步,它要求输入 MySQL 服务器密码。

What is the default password for root (if there is one) and how to change it?

root 的默认密码是什么(如果有的话)以及如何更改它?

I tried:

我试过:

mysql -u root password '123'

But it shows me:

但它告诉我:

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

After this I try:

在此之后,我尝试:

mysql -u root -p

However, it asks for a password which I don't have.

但是,它要求输入我没有的密码。



Update: as Bozho suggested, I did the following:

更新:正如 Bozho 建议的那样,我做了以下事情:

  1. I stopped the MySQL Service from Windows services
  2. Opened CMD
  3. Changed the location to c:\program files\mysql\bin
  4. Executed the command below

    mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt

  5. The command ran with a warning about character set which I mentioned below

  6. I start the MySQL service from Windows services
  7. I write in the command line

    mysql -u root -pEnterPassword: 123 // 123 was the password

  8. The command line shows the following error

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

  1. 我从 Windows 服务中停止了 MySQL 服务
  2. 打开CMD
  3. 将位置更改为 c:\program files\mysql\bin
  4. 执行了下面的命令

    mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt

  5. 该命令运行时出现了关于我在下面提到的字符集的警告

  6. 我从 Windows 服务启动 MySQL 服务
  7. 我在命令行写

    mysql -u root -pEnterPassword: 123 // 123 was the password

  8. 命令行显示以下错误

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

How do I solve this? I'm waiting to hear from you.

我该如何解决这个问题?我等着你的消息。

采纳答案by Bozho

You can reset your root password. Have in mind that it is not advisable to use root without password.

您可以重置您的 root 密码。请记住,不建议在没有密码的情况下使用 root。

回答by user2977819

for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:

对于这种错误;您只需要以管理员身份为 root 用户设置新密码。请按照以下步骤操作:

[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:NO)
  1. Stop the service/daemon of mysql running

    [root ~]# service mysql stop   
    mysql stop/waiting
    
  2. Start mysql without any privileges using the following option; This option is used to boot up and do not use the privilege system of MySQL.

    [root ~]# mysqld_safe --skip-grant-tables &
    
  1. 停止正在运行的 mysql 的服务/守护进程

    [root ~]# service mysql stop   
    mysql stop/waiting
    
  2. 使用以下选项在没有任何权限的情况下启动 mysql;该选项用于启动,不使用MySQL的特权系统。

    [root ~]# mysqld_safe --skip-grant-tables &
    

At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.

此刻,终端似乎停止了。就这样吧,并使用新终端进行下一步。

  1. enter the mysql command prompt

    [root ~]# mysql -u root
    mysql> 
    
  2. Fix the permission setting of the root user ;

    mysql> use mysql;
    Database changed
    mysql> select * from  user;
    Empty set (0.00 sec)
    mysql> truncate table user;
    Query OK, 0 rows affected (0.00 sec)
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    mysql> grant all privileges on *.* to root@localhost identified by 'YourNewPassword' with grant option;
    Query OK, 0 rows affected (0.01 sec)
    
  1. 进入mysql命令提示符

    [root ~]# mysql -u root
    mysql> 
    
  2. 修复root用户权限设置;

    mysql> use mysql;
    Database changed
    mysql> select * from  user;
    Empty set (0.00 sec)
    mysql> truncate table user;
    Query OK, 0 rows affected (0.00 sec)
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    mysql> grant all privileges on *.* to root@localhost identified by 'YourNewPassword' with grant option;
    Query OK, 0 rows affected (0.01 sec)
    

*if you don`t want any password or rather an empty password

*如果您不想要任何密码或空密码

    mysql> grant all privileges on *.* to root@localhost identified by '' with grant option;
    Query OK, 0 rows affected (0.01 sec)*
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

Confirm the results:

确认结果:

    mysql> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
  1. Exit the shell and restart mysql in normal mode.

    mysql> quit;
    [root ~]# kill -KILL [PID of mysqld_safe]
    [root ~]# kill -KILL [PID of mysqld]
    [root ~]# service mysql start
    
  2. Now you can successfully login as root user with the password you set

     [root ~]# mysql -u root -pYourNewPassword 
     mysql> 
    
  1. 退出shell并以正常模式重新启动mysql。

    mysql> quit;
    [root ~]# kill -KILL [PID of mysqld_safe]
    [root ~]# kill -KILL [PID of mysqld]
    [root ~]# service mysql start
    
  2. 现在您可以使用您设置的密码以root用户身份成功登录

     [root ~]# mysql -u root -pYourNewPassword 
     mysql> 
    

回答by yellobird

1) You can set root password by invoking MySQL console. It is located in

1) 您可以通过调用 MySQL 控制台来设置 root 密码。它位于

C:\wamp\bin\mysql\mysql5.1.53\binby default.

C:\wamp\bin\mysql\mysql5.1.53\bin默认情况下。

Get to the directory and type MySQL. then set the password as follows..

进入目录并输入 MySQL。然后设置密码如下..

    > SET PASSWORD FOR root@localhost = PASSWORD('new-password');

2) You can configure wamp's phpmyadmin application for root user by editing

2)您可以通过编辑为root用户配置wamp的phpmyadmin应用程序

C:\wamp\apps\phpmyadmin3.3.9\config.inc.php 

Note :-if you are using xampp then , file will be located at

注意:-如果您使用的是 xampp,则文件将位于

C:\xampp\phpMyadmin\config.inc.php

It looks like this:

它看起来像这样:

        $cfg['Servers'][$i]['verbose'] = 'localhost';
        $cfg['Servers'][$i]['host'] = 'localhost';
        $cfg['Servers'][$i]['port'] = '';
        $cfg['Servers'][$i]['socket'] = '';
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['extension'] = 'mysqli';
        $cfg['Servers'][$i]['auth_type'] = 'config';
        $cfg['Servers'][$i]['user'] = 'root';
        $cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
        $cfg['Servers'][$i]['AllowNoPassword'] = false;

The error "Access denied for user 'root@localhost' (using password:NO)" will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword']to false

当您设置$cfg['Servers'][$i]['AllowNoPassword']false时,将解决错误“用户 'root@localhost' 拒绝访问(使用密码:NO)”

If you priviously changed the password for 'root@localhost', then you have to do 2 things to solve the error "Access denided for user 'root@localhost'":

如果您私下更改了 'root@localhost' 的密码,那么您必须做 2 件事来解决错误“用户 'root@localhost' 的访问被拒绝”:

  1. if ['password'] have a empty quotes like ' 'then put your password between quotes.
  2. change the (using password:NO) to (using password:YES)
  1. 如果 ['password'] 有一个像' '这样的空引号,那么把你的密码放在引号之间。
  2. 将(使用密码:否)更改为(使用密码:是)

This will resolve the error.

这将解决错误。

Note: phpmyadmin is a separate tool which comes with wamp. It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.

注意:phpmyadmin 是 wamp 自带的一个单独的工具。它只是提供一个到 MySQL 的接口。如果您更改了我的 sql root 的密码,那么您应该更改 phpmyadmin 配置。通常phpmyadmin配置为root用户。

回答by Sushantkumar M

I was getting the same error on OS X El captain. Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.

我在 OS X El 船长上遇到了同样的错误。Mysql 5.7 版。执行这些步骤后,我能够使用 root 连接到 mysql。

Stop the mysql server

停止mysql服务器

sudo mysql.server stop

Start mysql in safe mode

以安全模式启动mysql

sudo mysqld_safe --skip-grant-tables

Using mysqld, Change the database to mysql and update the details for user 'root'.

使用 mysqld,将数据库更改为 mysql 并更新用户“root”的详细信息。

show databases;
use mysql;
UPDATE mysql.user 
    SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
exit;

After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details

之后杀死'mysqld_safe'进程并正常启动mysql。您应该能够使用 root 和新密码登录到 mysql。SQL 文档了解更多详情

回答by Ryan Oscar

Simply edit my.inifile in C:\xampp\mysql\bin path. Just add:

只需编辑my.iniC:\xampp\mysql\bin 路径中的文件。只需添加:

skip-grant-tables

line in between lines of # The MySQL server [mysqld]and port=3306. Then restart the MySQL server.

# The MySQL server [mysqld]和之间的线port=3306。然后重启MySQL服务器。

Looks like:

好像:

Screenshot

截屏

回答by sholsapp

Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):

确保 MySQL 服务正在您的机器上运行,然后按照 MySQL 的说明进行初始设置 root(搜索“windows”,它将带您进入设置 root 的步骤):

http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html

http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html

回答by Silverstorm

Another solution if someone gets the error The specified password for user account ‘root' is not valid, or failed to connect to the database serveralso with the right password, is the follow

如果有人收到错误The specified password for user account 'root' is not valid, or failed to connect to the database serveralso failedwith the right password 的另一种解决方案,请执行以下操作

?In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller

?在Windows注册表中,删除HKCU\Software\Microsoft\WebPlatformInstaller下的mysql_pwd注册表项

?Unistall older version of MySQL .NET connector

?卸载旧版本的 MySQL .NET 连接器

?Download and install the latest MySql .NET Connector.

?下载并安装最新的MySql .NET 连接器

回答by Katie

For MySQL 5.7. These are the below steps:

对于 MySQL 5.7。这些是以下步骤:

Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.

完全停止您的 MySQL 服务器。这可以通过访问 Windows XP 和 Windows Server 2003 中的服务窗口来完成,您可以在其中停止 MySQL 服务。

Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.

使用“运行”窗口中的“cmd”打开您的 MS-DOS 命令提示符。在其中使用 cd 命令导航到您的 MySQL bin 文件夹,例如 C:\MySQL\bin。

Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables

在命令提示符下执行以下命令:mysqld.exe -u root --skip-grant-tables

Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.

保持当前的 MS-DOS 命令提示符不变,并打开一个新的 MS-DOS 命令提示符窗口。

Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.

使用 cd 命令导航到您的 MySQL bin 文件夹,例如 C:\MySQL\bin。

Enter mysql and press enter.

输入 mysql 并按回车键。

You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.

您现在应该可以使用 MySQL 命令提示符了。输入使用mysql;以便我们切换到“mysql”数据库。

Execute the following command to update the password:

执行以下命令更新密码:

update user set authentication_string=password('1111') where user='root';

更新用户集 authentication_string=password('1111') where user='root';

回答by Vikash Kumar

Use mysql -u root -p It will ask for password, insert password and enter.

使用 mysql -u root -p 会要求输入密码,输入密码后回车。

回答by profiile_samir

For some information I've get error after changing password:

对于某些信息,我在更改密码后收到错误消息:

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

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

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

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

In both cases there was error.

在这两种情况下都有错误。

But the thing is after that I've tried it with

但事情是在那之后我试过了

mysql -uroot -ppasswordinstead of

mysql -uroot -ppassword代替

mysql -u root -p password-> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.

mysql -u root -p password-> -uroot 和 -ppassword 之间有空格,所以如果有人遇到麻烦可以尝试这种方式。