mysql 8.0. 16 winx64 and Linux Method for Modifying root User Password

  • 2021-12-09 10:19:53
  • OfStack

Please solve the basic operations such as connecting to the database by yourself. This article focuses on how to change the password.

1. Query the user password:

Query user password command:


select host, user, authentication_string from mysql.user ;

host: ip'location 'that allows users to log in% indicates that it can be remote;

user: The user name of the current database;

authentication_string: User password (this field is mentioned later);

2. Set (or modify) the user password:

If the default root password is empty, you can't connect with navicat below (5.7 I installed before seems to be OK), so you need to modify the password of root here.

This is the key step. For this reason, it was pitted for a long time. Later, I consulted a lot to know that the password field and password () function were abandoned after mysql 5.7. 9;

authentication_string: The field represents the user password.

3. To modify the root password:

1. If there is content in the field of authentication_string of the current root user, you can set it to null first, otherwise you can go through two steps directly.


update user set authentication_string='' where user='root';# Password set to null 

2. Modify the root user password using ALTER as ALTER user 'root' @ 'localhost' ES50BY 'New Password'. As follows:


alter user 'root'@'%' identified with mysql_native_password by 'xxxx';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019';
 Or  alter user 'root'@'localhost' identified with mysql_native_password by 'xxxx';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019'

Hint:

root @ is followed by the contents of the Host field of the user table, and the default for new installations is localhost, because remote access is added here, so localhost is manually changed to%.

Executable after modification: flush privileges; (Reload Permissions Table)

flush privileges;

Note: After mysql 8.0, the following methods are no longer applicable. Remember! ! !


UPDATE user SET password=PASSWORD(" New password ") WHERE user=' User name ';

If there is anything wrong with the above words, please correct them in detail and leave a message to facilitate everyone to grow together in the future;

I also hope this blog can help everyone!


Related articles: