Ubuntu-MySQL root user password is forgotten solution

 MySQL forget the root user's password solution


 

MySQL Version: 5.7.26

Ubuntu version: 18.04.2 LTS

MySQL on Ubuntu If you forget the root user password, there are two solutions:

A method, skip the authorization avoid dense Login

  1. MySQL service shutdown is running 
    service mysql stop
  2. Open the terminal input
    mysqld --skip-grant-tables  

    Start MySQL service is meant to skip the permissions table when certification. 

  3. To open a terminal, enter mysql, and then enter, if successful, MySQL mysql prompt will appear>
  4. Began to change the root password
    use mysql; # to enter the mysql database called
     the SELECT  the User , Host, authentication_string from  user ; # check user table of contents
     Update  user  the SET authentication_string = password ( "your new password") the WHERE  the User = "root" and Host = ' localhost '; 
    # Note MySQL5. 7 field representatives password is authentication_string 
    flush privileges ; # refresh permission after the modifications are complete, you need to use the statement to reload the privilege tables
     Exit ;
    service mysql restart # restart the MySQL service 
    next log in normally to

Method two, with another account login, and then edit your user table

  1. Enter / etc / mysql / folder to view files debian.cnf, cat debian.cnf
  2. MySQL open service
  3. User name: debian-sys-maint Password: P7D ..... connect mysql server
  4. Then began to change the root user's password
    use mysql; # to enter the mysql database called
     the SELECT  the User , Host, authentication_string from  user ; # check user table of contents
     Update  user  the SET authentication_string = password ( "your new password") the WHERE  the User = "root" and Host = ' localhost '; 
    # Note MySQL5. 7 field representatives password is authentication_string 
    flush privileges ; # refresh permission after the modifications are complete, you need to use the statement to reload the privilege tables
     Exit ;

 Next, use the new root password to log in normally.

 

Guess you like

Origin www.cnblogs.com/NanaseHaruka/p/10957032.html