MySql 忘记密码怎么办

mysql忘记密码的解决办法:
[[email protected] ~]# mysql -uroot -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
如果说出现这个一般就是因为MySQL没有起来
[[email protected] ~]# mysql -uroot -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
当出现这个的一般就是因为密码输入错误
解决办法:
1.停掉MySQL
[[email protected] ~]# service mysqld stop
Stopping mysqld: [ OK ]
2.修改配置文件,在最后一行加入以下内容 
skip-grant-tables //跳过授权直接进入数据库
3.重启MySQL
[[email protected] ~]# service mysqld start
[[email protected] ~]# mysql -uroot -p 
mysql> 
4.重新给MySQL设置密码
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.然后退出重新登陆
[[email protected] ~]# mysql -uroot -ppassw0rd
mysql>

亲测有效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值