服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Mysql - mysql忘记密码怎么办

mysql忘记密码怎么办

2020-07-30 18:31小白丿 Mysql

mysql忘记密码怎么办?这篇文章主要为大家详细介绍了MySQL忘记密码的解决办法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

MySQL忘记密码的解决办法:

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

如果说出现这个一般就是因为MySQL没有起来

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

当出现这个的一般就是因为密码输入错误

解决办法:

1.停掉MySQL

?
1
2
[root@localhost ~]# service mysqld stop
Stopping mysqld:                      [ OK ]

2.修改配置文件,在最后一行加入以下内容

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

3.重启MySQL

?
1
2
3
[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql -uroot -p 
mysql>

4.重新给MySQL设置密码

?
1
2
3
4
5
6
7
8
9
10
11
12
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.然后退出重新登陆

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

延伸 · 阅读

精彩推荐