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
- MySQL service shutdown is running
service mysql stop
- Open the terminal input
mysqld --skip-grant-tables
Start MySQL service is meant to skip the permissions table when certification.
- To open a terminal, enter mysql, and then enter, if successful, MySQL mysql prompt will appear>
- 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
- Enter / etc / mysql / folder to view files debian.cnf, cat debian.cnf
- MySQL open service
- User name: debian-sys-maint Password: P7D ..... connect mysql server
- 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.