Get the App
SLTechnology News&Howtos  ›  Database  › 

Solve the problem that MySQL 8.0 input is correct and still prompt Access denied

Shulou Source: shulou.com Published: 2022-06-01 19:24:37 09月18日 Update

This article was first posted on cartoon's blog.

Please indicate the source of the reprint: https://cartoonyu.github.io/cartoon-blog

Recently started to learn MySQL, the installation is very smooth, according to the online ready-made tutorials can be successfully installed.

However, before entering

Mysql-uroot-p

When entering the password again, I encountered this situation.

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

Many solutions have been found online, but there is basically only one, which is added to the mysqld entry in the .ini file.

Skip-grant-tables

Then restart the server and follow the previous steps again (finally, do not enter the password), but still a statement stopped me.

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

Integrated a lot of methods on the Internet, one by one to try, and finally succeeded.

The overall idea is to modify the contents of the .ini configuration file, but in the form of a command line. I don't know if it is because the version iterates to shield the previous method of directly modifying the file. In any case, it is possible to modify it on MySQL 8.0 through command line modification.

Let's get started.

Open cmd as an administrator Switch to MySQL's bin directory and close the MySQL server net stop mysql to skip the steps to enter the password (note: the file name and path should match your own) mysqld-- defaults-file= "D:\ MySQL\ my.ini"-- console-- skip-grant-tables indicates success if a statement like screenshot circle appears! [] (https://cache.yisu.com/upload/information/20200310/35/73912.jpg) restart server The server net start mysql logs in to the MySQL server mysql-uroot-p and you can log in successfully after entering the password. (the number 1 looks a lot like the letter l) it's almost done at this point, 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 believes that the random password provided during installation is not secure and allows the user to reset the password.

Looked for it on the Internet, and then found a ready-made way.

Reference article: https://dev.mysql.com/doc/ref...

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

Then log in to the server again and you will be able to operate normally.

Tags: Password input server service success file method command method step statement or new secret login security almost anyway content provenance blog Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Huawei Docker Microsoft