忘记了MySQL密码,你该怎么做?(遇到事情凡事不要慌!!!)

提前语

碰到mysql突然给你报错,或者是时间长了之后,不知哪根筋搭错了,就会突然之间忘记自己的密码。
我的密码可能是让我不经意间,设置MySQL中用户权限的时候给整丢了,真是令我头大。
在这里插入图片描述
但是今天还有任务,不能听之任之。只能开动小脑筋。努努力也就成功了。你不拼一把没谁知道行不行!!!

干货来啦

第一步

打开cmd(windows+r),使用命令行 net stop mysql ;关闭服务器,如果服务器提示(阻止访问),那么就选择打开任务管理器,在进程中找
tu强制结束任务

第二步

找到你mysql的安装文件的具体位置
例如
在这里插入图片描述一定要进入bin级目录然后双击目录栏:如下
在这里插入图片描述然后输入 cmd就可以直接跳转到
在这里插入图片描述

第三步

命令行输入:
记得是你自己的MySQL版本号:我的是 5.5

mysqld --defaults-file="C:\Program Files (x86)\MySQL\MySQL Server 5.5\my.ini" --console --skip-grant-tables

输入的这个命令可以直接开启MySQL服务并跳过输入密码的步骤。

第四步

另起一个cmd窗口,进行数据库的操作

C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases
    -> use mysql
    -> UPDATE user SET Password=PASSWORD('newpassword') where user='root'
    -> FLUSH PRIVILEGES
    -> quit

newpassword是你设置的新密码。

然后关掉两个打开的cmd窗口,再之后你就可以进行登录了。

运行成功

在这里插入图片描述

原创文章 28 获赞 41 访问量 1021

猜你喜欢

转载自blog.csdn.net/wenquan19960602/article/details/104929964