After mysql 8.0 forget the root password reset

 

Recently very bad state, has been reeling reeling faint, a test case, before work to modify a bit the root password, and then they leave from work the next day to discover the root password forgotten
Just automated installation script ready and we have been thinking forget reload instances had direct, simple and easy way also can not spend half a minute, anyway, is a test case, no major problems
found some mindset, it has recently been implying that he do some a up on the exclusion of things, to force a change of mindset, then reset it, do not reinstall to get around this problem by
Tried several ways, some lines and some not, say so the simplest possible method:
 
1, stop the instance (if instances in the open then), a non-start service name, that use mysqld command with the --skip-grant-tables Starting MySQL as a service
   /usr/local/mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/usr/local/mysql8_data/mysql8000/etc/my.cnf --skip-grant-tables &
  或者
  /usr/local/mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld_safe --defaults-file=/usr/local/mysql8_data/mysql8000/etc/my.cnf  --skip-grant-tables &
2, to the local values ​​of the instance connected sock, so that the input password sock Enter file specified instance, the transport may continue normal connection
3, switch to the mysql library,
    3.1.执行update user set authentication_string = '' where user = 'root';
    3.2 refresh permission, flush privilegs;
    3.3 reset the password: alter user 'root' @ '%' identified by '********';
    3.4 refresh permission, flush privilegs;
4, after exiting the current connection, if it continues to use in step 2 are connected, it found Rom, must enter a password
 

 

Note that, after the password is forgotten, then start the instance with --skip-grant-tables, can only log in sock connection locally.
If you are using tcp / ip log is not feasible, then prompted for a password, continue to enter, you will be prompted Can not connect to MySQL server on ' 127.0.0.1', not difficult to understand, in order to ensure safety, can only reset the password locally attached (sock).

 

 

over, continue to work.

 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/wy123/p/11942689.html