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

前端 未结 16 855
萌比男神i
萌比男神i 2020-11-22 15:30

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

I install everything with Web Platform Installer which is prov

相关标签:
16条回答
  • 2020-11-22 15:39

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

    0 讨论(0)
  • 2020-11-22 15:40

    if you changed the port to non standard one, then you need to specify it:

    $connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');

    0 讨论(0)
  • 2020-11-22 15:42

    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> 
      
    0 讨论(0)
  • 2020-11-22 15:43

    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.

    0 讨论(0)
  • 2020-11-22 15:43

    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.

    0 讨论(0)
  • 2020-11-22 15:45

    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.

    Stop the mysql server

    sudo mysql.server stop
    

    Start mysql in safe mode

    sudo mysqld_safe --skip-grant-tables
    

    Using mysqld, Change the database to mysql and update the details for user '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

    0 讨论(0)
提交回复
热议问题