Solution to the problem of Access denied for user'root'@'localhost' (using password: YES) in MySQL 8.0 login under win10

Solution to the problem of Access denied for user'root'@'localhost' (using password: YES) in MySQL 8.0 login under win10

I started learning MySQL recently. The installation went smoothly and I was able to install it successfully by following the ready-made tutorials on the Internet.

But, as I happily type

mysql -uroot -p

When I entered the password again, I encountered this situation

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

I have found many solutions online, but there is basically only one solution, which is to add the mysqld entry in the .ini file

skip-grant-tables

Then restart the server and follow the steps again (without entering the password at the end), but there is still a statement that stops me

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

I combined many methods on the Internet, tried them one by one, and finally succeeded.

The overall idea is to modify the contents of the .ini configuration file, but it is modified through the command line. I don’t know if it is because the version iteration has blocked the previous method of directly modifying the file. In any case, it is possible to modify it through the command line on MySQL 8.0.

Let’s get started.

1. Open cmd as an administrator and switch to the bin directory of MySQL

2. Shut down the MySQL server

net stop mysql

3. Skip the password entry step

mysqld --defaults-file="D:\MySQL\my.ini" --console --skip-grant-tables

( Note: the file name and path must match your own)

If a statement similar to the one circled in the screenshot appears, it means success

4. Restart the server

net start mysql

5. Log in to MySQL server

mysql -uroot -p

After entering the password, you can log in successfully.

(The number 1 is very similar to the letter l)

At this point, it's almost done, but when I type

show databases;

The feedback from MySQL is:

You must reset your password using ALTER USER statement before executing this statement.

My guess is that MySQL thinks the random password provided during installation is insecure and asks the user to reset the password.

I searched online and found a ready-made method, reference article

Password never expires

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password' PASSWORD EXPIRE NEVER;

Password has a limited time

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password' PASSWORD EXPIRE;

Then log in to the server again and it will work normally.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A quick solution to the first login failure in mysql5.7.20
  • Solution to the root password login problem in MySQL 5.7
  • How to install the green version of MySQL Community Server 5.7.16 and implement remote login
  • Solve the problem of ERROR 1045 (28000): Access denied for user ''root''@''localhost'' when logging in after installing MySQL 5.7.17 on Ubuntu 16.04
  • Tutorial on logging into MySQL after installing Mysql 5.7.17
  • Solve the problem of being unable to log in after installing MySQL 5.7 without a data folder

<<:  Summary of various uses of JSON.stringify

>>:  When adding a Windows 2008 server subdomain to a parent domain, an error message appears: the domain already exists

Recommend

How to install MySQL under Linux (yum and source code compilation)

Here are two ways to install MySQL under Linux: y...

Specific use of MySQL window functions

Table of contents 1. What is a window function? 1...

Use neat HTML markup to build your pages

The Internet is an organism that is constantly ev...

Summary of some related operations of Linux scheduled tasks

I have searched various major websites and tested...

Installation and daemon configuration of Redis on Windows and Linux

# Installation daemon configuration for Redis on ...

Docker overlay realizes container intercommunication across hosts

Table of contents 1. Docker configuration 2. Crea...

Linux command line quick tips: How to locate a file

We all have files stored on our computers -- dire...

Native js to implement a simple calculator

This article example shares the specific code of ...

React ref usage examples

Table of contents What is ref How to use ref Plac...

Vue Router loads different components according to background data

Table of contents Requirements encountered in act...

Manually implement the two-way data binding principle of Vue2.0

In one sentence: Data hijacking (Object.definePro...

OpenSSL implements two-way authentication tutorial (with server and client code)

1. Background 1.1 Problems A recent product testi...

Perform data statistics on different values ​​of the same field in SQL

Application scenario: It is necessary to count th...