error: 'Access denied for user 'root'@'localhost' (using password: YES)' and NO both On windows 10. How to do root login?

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

The error message "Access denied for user 'root'@'localhost' (using password: YES)" indicates that the MySQL server rejected the login attempt for the 'root' user with the provided password. Similarly, the error "Access denied for user 'root'@'localhost' (using password: NO)" indicates that the login attempt without a password was also denied.

By default, MySQL does not allow remote root logins for security reasons. However, you can try the following steps to log in as the 'root' user on a local MySQL server running on Windows 10:

  1. Check if MySQL Service is Running: Ensure that the MySQL server service is running. You can open the "Services" application (services.msc) and check if the "MySQL" service is running.

  2. Verify MySQL Server Installation: Verify that MySQL is installed correctly and accessible from the command prompt. Open a command prompt and try running the following command to connect to MySQL:

    css
    mysql -u root -p

    You will be prompted to enter the root password. If the login is successful, you should see the MySQL command-line interface.

  3. Reset Root Password (if needed): If you don't remember the root password or if it's not working, you can reset it. Note that this step requires administrative privileges on the MySQL server.

    • Stop the MySQL server service.

    • Open a command prompt and navigate to the MySQL bin directory (e.g., C:\Program Files\MySQL\MySQL Server 8.0\bin).

    • Run the following command to start the MySQL server in safe mode:

      css
      mysqld --skip-grant-tables
    • This will start the MySQL server without password authentication. Open another command prompt and navigate to the MySQL bin directory again.

    • Run the following command to connect to MySQL as the root user:

      mysql -u root
    • You should now be logged in as the root user without being prompted for a password.

    • Run the following SQL command to update the root password:

      sql
      FLUSH PRIVILEGES;
      ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
    • Replace 'new_password' with your desired root password.

    • Stop the MySQL server from the command prompt where it was started in safe mode.

  4. Start MySQL Server Normally: Start the MySQL server service normally.

After following these steps, you should be able to log in as the root user with the specified password. Remember to keep the root password secure and avoid using it unnecessarily for regular operations. Instead, create and use separate MySQL users with appropriate privileges for your applications.