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>
亲测有效。
最后
以上就是懦弱黑米最近收集整理的关于MySql 忘记密码怎么办的全部内容,更多相关MySql内容请搜索靠谱客的其他文章。
发表评论 取消回复