What should I do if I forget the password of mysql?

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.