Mysql database password changes

1, modify the my.cnf

  

 

   Adding skip-grant-tables in this file inside 

  

 

   After the changes, save. Then restart the database

2, because my system is Centos7, the database is mariadb, so execute the command as follows;

  

 

3, then restart the database, we do not need to re-enter the password to verify the database.

4, change your password into the database;

  

  [root@ub1 ~]$ mysql
  Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 3
  Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
  ... ...
  mysql> use mysql;
  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A

  Database changed
  mysql>

  Modify the update password

  UPDATE user SET password=PASSWORD('your_new_passwd')WHERE User='root';

  It is noteworthy that mysql and mariadb is not the same, there is no password in mysql in this field, the password should be changed authentication_string;

  

  mysql> UPDATE user SET authentication_string=PASSWORD('root')WHERE User='root';
  Query OK, 0 rows affected, 1 warning (0.31 sec)
  Rows matched: 1 Changed: 0 Warnings: 1

5. After he must remember to refresh the password database, I many times before the operation was not successful because they did not refresh the database;

  mysql> flush privileges;

6, finally /etc/my.cnfthe skip-grant-tables commented

7, restart the server, the password to take effect.

  You need to verify the password to get into the database;

  

 

   

 

   This completes.

 

 

  

 

Guess you like

Origin www.cnblogs.com/SliverLee/p/11458609.html