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

时间:2022-08-09 19:18:35

I'm new to mysql, I'm trying to run Wordpress inmy windows desktop and it need Mysql.

我是mysql新手,我试着在我的windows桌面运行Wordpress,它需要mysql。

I install everything with Web Platform Installer which provided by microsoft. I never seta root password for mysql and in final step of installing wordpressit askfor root password of mysql.

我用微软提供的Web平台安装程序安装了所有东西。我从来没有为mysql设置过root密码,在安装wordpressit的最后一步是询问mysql的根密码。

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

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

I try

我试着

mysql -u root password '123'

but it show me

但是它给我

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

after this I try

这之后我尝试

mysql -u root -p

but it ask for a password which I don't have

但它需要一个密码,我没有

Thank you in advance

提前谢谢你


Update : as Bozho said I did the following

更新:正如博佐所说,我做了以下事情

 1 - I stoped MySql Service from Windows services
 2 - Open CMD
 3 - change location to cd c:\program files\mysql\bin
 4 - write this command

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

 5 - Command run with a warning about characterset which I mentioned below
 6 - I start MySql Service from windows services
 7 - in command line I write

mysql -u root -p
EnterPassword: 123  // 123 was the password

8 - the commandline shows following bug

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

I'm waiting to hear from you.

我在等你的消息。

11 个解决方案

#1


25  

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

您可以重置您的根密码。记住,不建议使用没有密码的root。

#2


38  

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用户设置为admin。按以下步骤进行:

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

    停止mysql的服务/守护进程

    [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.

    使用以下选项启动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

    输入mysql命令提示符

    [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)
    

*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.

    退出shell并在正常模式下重新启动mysql。

    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用户。

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

#3


14  

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

1)可以通过调用MySQL控制台设置根密码。它座落在

C:\wamp\bin\mysql\mysql5.1.53\bin by 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 

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)被拒绝的错误

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用户。

#4


6  

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 captain上犯了同样的错误。Mysql 5.7版。在执行完这些步骤后,我能够连接到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文档了解更多细节

#5


4  

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

简单的编辑我的。ini文件C:\xampp\mysql\bin路径。添加:

skip-grant-tables

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

在# MySQL服务器[sqmyld]和端口=3306之间行。然后重新启动MySQL服务器。

Looks like:

看起来像:

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

#6


3  

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的指示设置根(搜索“windows”,它将带您到设置根的步骤):

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

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

#7


2  

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命令提示符。在它里面导航到你的MySQL bin文件夹,例如C:\MySQL\bin使用cd命令。

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

在命令提示符:mysqld中执行以下命令。exe - u根——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并按Enter。

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'),其中user='root';

#8


1  

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

另一个解决方案是,如果有人收到错误,用户帐户“root”的指定密码无效,或者连接到数据库服务器的密码也正确,则是下面的方法

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

•在windowsregistry中,在HKCU\软件\微软\WebPlatformInstaller下删除mysql_preg键

•Unistall older version of MySQL .NET connector

·MySQL .NET连接器的旧版本。

•Download and install the latest MySql .NET Connector.

•下载并安装最新的MySql。net连接器。

#9


1  

In your code replace the 'root' with your Server username and password with your server password. For example if you have DB and your php files on the server http://www.example.com then obviously you would have to enter into this server site using your username and password.

在您的代码中,用您的服务器用户名和密码替换'root'。例如,如果您在服务器http://www.example.com上有DB和php文件,那么显然您必须使用您的用户名和密码进入这个服务器站点。

#10


0  

Some times it just happens due to installation of Wamp or changing of password options of root user. One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.

有时它只是由于安装了Wamp或修改了根用户的密码选项而发生。可以使用privilages—>root (user),然后将password选项设置为NO,以便在没有任何密码的情况下运行,或者设置密码并在应用程序中使用。

#11


-2  

mysqladmin -u root -p password

enter your current password

输入您的当前密码

then

然后

enter your new password

输入您的新密码

#1


25  

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

您可以重置您的根密码。记住,不建议使用没有密码的root。

#2


38  

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用户设置为admin。按以下步骤进行:

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

    停止mysql的服务/守护进程

    [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.

    使用以下选项启动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

    输入mysql命令提示符

    [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)
    

*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.

    退出shell并在正常模式下重新启动mysql。

    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用户。

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

#3


14  

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

1)可以通过调用MySQL控制台设置根密码。它座落在

C:\wamp\bin\mysql\mysql5.1.53\bin by 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 

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)被拒绝的错误

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用户。

#4


6  

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 captain上犯了同样的错误。Mysql 5.7版。在执行完这些步骤后,我能够连接到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文档了解更多细节

#5


4  

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

简单的编辑我的。ini文件C:\xampp\mysql\bin路径。添加:

skip-grant-tables

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

在# MySQL服务器[sqmyld]和端口=3306之间行。然后重新启动MySQL服务器。

Looks like:

看起来像:

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

#6


3  

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的指示设置根(搜索“windows”,它将带您到设置根的步骤):

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

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

#7


2  

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命令提示符。在它里面导航到你的MySQL bin文件夹,例如C:\MySQL\bin使用cd命令。

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

在命令提示符:mysqld中执行以下命令。exe - u根——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并按Enter。

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'),其中user='root';

#8


1  

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

另一个解决方案是,如果有人收到错误,用户帐户“root”的指定密码无效,或者连接到数据库服务器的密码也正确,则是下面的方法

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

•在windowsregistry中,在HKCU\软件\微软\WebPlatformInstaller下删除mysql_preg键

•Unistall older version of MySQL .NET connector

·MySQL .NET连接器的旧版本。

•Download and install the latest MySql .NET Connector.

•下载并安装最新的MySql。net连接器。

#9


1  

In your code replace the 'root' with your Server username and password with your server password. For example if you have DB and your php files on the server http://www.example.com then obviously you would have to enter into this server site using your username and password.

在您的代码中,用您的服务器用户名和密码替换'root'。例如,如果您在服务器http://www.example.com上有DB和php文件,那么显然您必须使用您的用户名和密码进入这个服务器站点。

#10


0  

Some times it just happens due to installation of Wamp or changing of password options of root user. One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.

有时它只是由于安装了Wamp或修改了根用户的密码选项而发生。可以使用privilages—>root (user),然后将password选项设置为NO,以便在没有任何密码的情况下运行,或者设置密码并在应用程序中使用。

#11


-2  

mysqladmin -u root -p password

enter your current password

输入您的当前密码

then

然后

enter your new password

输入您的新密码