ubuntu system mysql5.7 forget pit / set the root

Change the root password on there are a lot of notes, but in mysql5.7 the following invalid, then find the same notes is 5.7, amend really good. Now recorded.

 

The first step, modify the configuration file so that mysql Mysql skip authentication

My mysql through apt install mysql-server installation

Profile directory /etc/mysql/mysql.conf.d/mysql.cnf

Edit mysql.cnf, find [mysqld] (brackets with English), add a line below

skip-grant-tables

Save and exit

[ Remind ] default /etc/mysql/mysql.cnf is an import file is generally not recommended to directly modify, edit this file if you can, you need to enter the [mysqld], and back to the line input skip-grant-tables

Alternate Method : Use the account to log debian, you can not modify mysql.cnf Login

sudo came /etc/mysql/debian.cnf
# Find the password line, copy passwords

  

The second step, restart mysql, then avoid dense Login

sudo service mysql restart

Then msyql -u root -p Enter, then Enter to enter the mysql

The third step is to change the root password

mysql> use mysql;
MySQL >  Update  User  SET authentication_string = PASSWORD ( "your password") WHERE  User = ' the root ' ;
MySQL >  Update  the User  the SET plugin = "mysql_native_password"; # without modification, executed directly focused 
MySQL > flush privileges ;
mysql> quit;

Previous tutorial, we know that the authentication_string update this table, no operating line 3, so that quit restart mysql, still can not log in as root

This should be reason 5.7 update security rules, we must implement Article 3 and Article 4 oh

The fourth step, re-edit mysql.cnf 

In front of the skip-grant-tables, plus a # comment out if a production environment, you must modify Oh, or very dangerous Kazakhstan

And then restart the mysql service sudo service mysql restart

Enter another mysql -u root -p #

Enter the password to log Mysql 

 

Guess you like

Origin www.cnblogs.com/qumogu/p/12632186.html