Mysql忘记root密码怎么办
作者:JustRun 时间:2024-01-19 02:29:22
MySQL有时候忘记了root密码是一件伤感的事,这种情况下,如何重置root的密码呢?
找到并编辑mysql的my.ini配置文件,在mysqld节点中添加上skip-grant-table. 如下:
# These let you safely reset the lost root password.
skip-grant-table保存好修改,重启mysql服务。
现在就能不需要root密码的情况下连接上数据库。然后执行下面的更新:
USE mysql;
UPDATE USER
SET password = password('yournewpasswordhere')
WHERE USER = 'root'
AND host = 'localhost';
这样root密码就修改好了,这个时候,将my.ini中的skip-grant-table删除,再重启mysql service
下面介绍Windows 和 Linux 下的密码重置方法。
windows:
1.以系统管理员身份登陆系统。
2.打开cmd-----net start 查看mysql是否启动。启动的话就停止net stop mysql.
3.我的mysql安装在d:\usr\local\mysql4\bin下。
4.跳过权限检查启动mysql.
d:\usr\local\mysql\bin\mysqld-nt --skip-grant-tables
5.重新打开cmd。进到d:\usr\local\mysql4\bin下:
d:\usr\local\mysql\bin\mysqladmin -u root flush-privileges password "newpassword"
d:\usr\local\mysql\bin\mysqladmin -u root -p shutdown 这句提示你重新输密码。
6.在cmd里net start mysql
7.搞定了。
Linux:
MySQL root密码的恢复方法之一
如果忘记了MySQL root密码,可以用以下方法重新设置:
1. KILL掉系统里的MySQL进程;
killall -TERM MySQLd
2. 用以下命令启动MySQL,以不检查权限的方式启动;
safe_MySQLd --skip-grant-tables &
3. 然后用空密码方式使用root用户登录 MySQL;
MySQL -u root
4. 修改root用户的密码;
MySQL> update MySQL.user set password=PASSWORD('新密码') where User='root';
MySQL> flush privileges;
MySQL> quit
重新启动MySQL,就可以使用新密码登录了。
MySQLroot密码的恢复方法二
有可能你的系统没有 safe_MySQLd 程序(比如我现在用的 ubuntu操作系统, apt-get安装的MySQL) , 下面方法可以恢复
1. 停止MySQLd;
sudo /etc/init.d/MySQL stop
(您可能有其它的方法,总之停止MySQLd的运行就可以了)
2. 用以下命令启动MySQL,以不检查权限的方式启动;
MySQLd --skip-grant-tables &
3. 然后用空密码方式使用root用户登录 MySQL;
MySQL -u root
4. 修改root用户的密码;
MySQL> update MySQL.user set password=PASSWORD('newpassword') where User='root';
MySQL> flush privileges;
MySQL> quit
重新启动MySQL
/etc/init.d/MySQL restart
就可以使用新密码 newpassword 登录了。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Javascript:keyCode键盘键码值表
mysql UNIX时间戳与日期的相互转换
简单理解vue中track-by属性
![](https://img.aspxhome.com/file/2023/3/130263_0s.jpg)
Windows下python3.7安装教程
![](https://img.aspxhome.com/file/2023/5/90435_0s.png)
选择utf-8还是GB2312?
![](https://img.aspxhome.com/file/UploadPic/20096/19/11e5d33a4f2g215-39s.jpg)
Python使用线程来接收串口数据的示例
python GUI库图形界面开发之PyQt5 MDI(多文档窗口)QMidArea详细使用方法与实例
![](https://img.aspxhome.com/file/2023/1/121041_0s.png)
网页代码中键盘操作相关标签教程
python数据结构的排序算法
![](https://img.aspxhome.com/file/2023/0/78800_0s.png)
Pytorch中的图像增广transforms类和预处理方法
如何查看连接MYSQL数据库的IP信息
Golang拾遗之实现一个不可复制类型详解
MySQL中主键为0与主键自排约束的关系详解(细节)
![](https://img.aspxhome.com/file/2023/7/124537_0s.png)
python文件和目录操作函数小结
如何编写一个高效的国税系统通讯录数据库?
bootstrap自定义样式之bootstrap实现侧边导航栏功能
![](https://img.aspxhome.com/file/2023/4/56084_0s.png)
vue递归获取父元素的元素实例
详解非极大值抑制算法之Python实现
![](https://img.aspxhome.com/file/2023/3/123803_0s.jpg)
pygame游戏之旅 添加碰撞效果的方法
![](https://img.aspxhome.com/file/2023/6/87756_0s.png)