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

Sharing the solution for forgetting mysql password

黄舟
黄舟Original
2017-06-18 10:38:591274browse

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)

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)

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 ]

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


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

3. Restart MySQL


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

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; //刷新

5. Thenlog outlog in again


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

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!

Statement:
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