Home > Database > Mysql Tutorial > Sharing the solution for forgetting mysql password

Sharing the solution for forgetting mysql password

黄舟
Release: 2017-06-18 10:38:59
Original
1265 people have browsed it

mysqlWhat should I do if I forget my password? This article mainly introduces in detail the solution for MySQL forgotten password, which has certain reference value. Interested friends can refer to

The solution for MySQL forgotten password:

[root@localhost ~]# mysql -uroot -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Copy after login

If this occurs, it is usually because MySQL has not started up


[root@localhost ~]# mysql -uroot -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Copy after login

When this occurs, it is usually because the password is entered incorrectly

Solution Method:

1. Stop MySQL


[root@localhost ~]# service mysqld stop
Stopping mysqld:                      [ OK ]
Copy after login

2. Modify the configuration file, in the last line Add the following content


skip-grant-tables  //跳过授权直接进入数据库
Copy after login

3. Restart MySQL


[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql -uroot -p  
mysql>
Copy after login

4. Restart MySQL Set password


mysql> use mysql //密码存放在MySQL中,需要进入
mysql> desc user; //查看user表中的字段
密码一般存在password表中
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| 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"; //设置密码为passw0rd
mysql> flush privileges; //刷新
Copy after login

5. Thenlog outlog in again


[root@localhost ~]# mysql -uroot -ppassw0rd
mysql>
Copy after login

The above is the detailed content of Sharing the solution for forgetting mysql password. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template