What should I do if I forget the password of mysql?
Solution to MySQL password loss:
[root@localhost ~]# mysql -uroot -pERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
If this occurs, it is generally because MySQL does not exist.
[root@localhost ~]# mysql -uroot -pERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
This is generally caused by incorrect password input.
Solution:
1. Stop MySQL
[root@localhost ~]# service mysqld stopStopping mysqld: [ OK ]
2. modify the configuration file and add the following content to the last line:
Skip-grant-tables // skip authorization and directly access the database
3. Restart MySQL
[root@localhost ~]# service mysqld start[root@localhost ~]# mysql -uroot -p mysql>
4. Set a new password for MySQL.
Mysql> use mysql // The password is stored in MySQL. You need to enter mysql> desc user; // view the Field password in the user table. It is generally found in the password table + ------------------------ + certificate + ------ + ----- + ------------------------- + ------- + | Field | Type | Null | Key | Default | Extra | + ------------------------ + ----------------------------------- + ------ + ----- + --------------------- + ------- + | Host | char (60) | NO | PRI | User | char (16) | NO | PRI | Password | char (41) | NO | mysql> update user set password = password ('passw0rd ') where user = "root"; // set the password to passw0rdmysql> flush privileges; // refresh
5. Then exit and log on again.
[root@localhost ~]# mysql -uroot -ppassw0rdmysql>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.