Access denied for user 'root@localhost' (u

2019-01-01 13:23发布

I'm new to mysql, I'm trying to run Wordpress inmy windows desktop and it need 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.

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

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.

12条回答
泛滥B
2楼-- · 2019-01-01 13:46

If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.

查看更多
时光乱了年华
3楼-- · 2019-01-01 13:48

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

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

•Unistall older version of MySQL .NET connector

•Download and install the latest MySql .NET Connector.

查看更多
唯独是你
4楼-- · 2019-01-01 13:49

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

查看更多
余生请多指教
5楼-- · 2019-01-01 13:49

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

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

查看更多
余生请多指教
6楼-- · 2019-01-01 13:51

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 ~]# 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 &
    

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)
    

*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> 
    
查看更多
与风俱净
7楼-- · 2019-01-01 13:52

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

skip-grant-tables

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

Looks like:

Screenshot

查看更多
登录 后发表回答