Enter the correct solve the MySQL 8.0 is still prompt Access denied problem

    This article first appeared in the cartoon's blog
    please indicate the source: https://cartoonyu.github.io/cartoon-blog

    In recent time began to learn MySQL, installed very smoothly, in accordance with existing online tutorials can be installed successfully.
    However, input

mysql -uroot -p

    When re-enter the password, I encountered this situation

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

    The Internet to find a lot of solutions, but only a basic, mysqld entry in the .ini file to add

skip-grant-tables

    Then restart the server, and then just follow the steps of it again (last without entering a password), but still a statement stopped me

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

    Comprehensive online many ways, himself a fight then went to a trial, and finally succeeded
    ideological or modify the contents of .ini configuration file on the whole, but a modified form of the command line, do not know because the version of the previous iteration of the direct method to modify the file screen, in any case, by modifying the command line in MySQL 8.0 is possible.

    Here's get started.

  • Open cmd as an administrator, to switch to the MySQL bin directory
  • Shut down the MySQL server
net stop mysql
  • Skip to enter the password (Note: The file name and path to be consistent with their own)
mysqld --defaults-file="D:\MySQL\my.ini" --console --skip-grant-tables
  • If the statement is similar to the screenshot circled appears it indicates success
![](https://cartoon-blog.oss-cn-beijing.aliyuncs.com/2347090715-5cce5863cf948_articlex.png)
  • Restart the server
net start mysql
  • Login MySQL server
mysql -uroot -p
输入密码之后就能登录成功了。(数字1跟字母l很像很像)
  • At this point you can almost completed, but when I type
show databases;

    MySQL give my feedback is:

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

    I guess it should be considered a random MySQL password provided at installation unsafe, allowing users to reset the password.
    Internet looking for a bit, then find a ready-made way to
    refer to the article:https://dev.mysql.com/doc/ref...

  • Password never expires
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码' PASSWORD EXPIRE NEVER;
  • There are cryptographic deadline
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码' PASSWORD EXPIRE;

     Then log back on the server will be able to look at a normal operation.

Guess you like

Origin blog.51cto.com/12583767/2421975