Detailed explanation of the solution to mysql5.7 password forgetting
ENV:
[root@centos7 ~] # uname-r3.10.0-514.el7.x86_64 [root@centos7 ~] # cat / etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@centos7 ~] # rpm-qa mysql [root@centos7 ~] # rpm-qa | grep mysqlmysql-community-common-5.7.26-1.el7.x86_64mysql-community-client-5.7.26-1.el7.x86_64mysql57-community-release-el7-11.noarchmysqlour Community- Server-5.7.26-1.el7.x86_64mysql-community-libs-5.7.26-1.el7.x86_64mysql-community-libs-compat-5.7.26-1.el7.x86_64
Error logging in:
[root@centos7] # mysql-u root-pEnter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
The password is forgotten (just like not knowing the password after installation)
Some people on the Internet say that the password of mysql is an empty password, but in fact, after the mysql5.7 version, the password is no longer empty.
If you just installed it, you can find it in the log file of mysql.
Grep 'temporary password' / var/log/mysqld.log
Add: if you find the password provided by mysql, you can use the
Password provided by mysqladmin-u root-p 'mysql' password 'own new password'
Directly change the password of mysql, but this method has security risks, after all, the password is displayed on the command line, not recommended but not opposed.
If you forget, modify it as follows:
1. Modify / etc/my.cnf to join skip-grant-tables
[root@centos7 ~] # vim / etc/my.cnf
Join in a blank position and save to exit
[mysqld] skip-name-resolveskip-grant-tables [root@centos7 ~] # systemctl restart mysqld
two。 An empty password goes directly to mysql.
[root@centos7] # mysql-u root-pEnter password: (here is an empty password, enter directly) Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 2Server version: 5.7.26 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Mysql >
Enter the mysql library
Mysql > use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-A Database changedmysql >
The mysql here is not unchanged, and the database location is changed.
3. Change the password: UPDATE user SET authentication_string=PASSWORD ('newpassword') where USER='root'
Mysql > UPDATE user SET authentication_string=PASSWORD ('newpassword') where USER='root';Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql > mysql > FLUSH PRIVILEGES;Query OK, 0 rows affected (0.00 sec) mysql >
4 change back to / etc/my.cnf
Comment out # skip-grant-tables
[root@centos7 ~] # vim / etc/my.cnf [mysqld] skip-name-resolve#skip-grant-tables [root@centos7 ~] # systemctl restart mysqld
5. Re-enter mysql with a new password
[root@centos7 ~] # mysql-u root-p Enter password: (previously demonstrated as newpassword) Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 6Server version: 5.7.26 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement. Mysql >
6. Change root password, change root password: alter user 'root'@'localhost' identified by' password
Modify a user's password
ALTER USER testuser IDENTIFIED BY '123456'
Modify the currently logged in user
ALTER USER USER () IDENTIFIED BY '123456passport leads MySQL > alter user user () identified by'Linuxpasswordwords to query OK, 0 rows affected (0.00 sec) mysql >
It can be seen that the complexity of the password has a great requirement.
7. After the modification is completed, you can continue to operate mysql.
Mysql > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | +-+ 4 rows in set (0.00 sec) mysql > exitBye
The above is the mysql5.7 password forgetting solution introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!