当前位置:网站首页>修改MySQL密码的四种方法(适合初学者)
修改MySQL密码的四种方法(适合初学者)
2022-07-28 01:26:00 【@每天都要敲代码】
作者简介:大家好我是@每天都要敲代码,一位材料转码农的选手,希望一起努力,一起进步!
个人主页:@每天都要敲代码的个人主页
推荐一款模拟面试、刷题神器,从基础到大厂面试题点击跳转刷题网站进行注册学习作为初学者,对于MySQL密码的修改,目前我已知的有四种方法:前三种是在知道密码的情况下修改,因为需要我们先登录;最后一种适合忘记密码的情况下进行修改!
目录
方法1:用set password命令
(1)首先要先登录MySQL:

(2)修改密码格式为:
set password for 用户名@localhost = password('新密码'); 一定不要忘记最后面的分号,例如:我们把密码改成成123:
set password for [email protected] = password('123');出现以下界面说明修改成功:

方法2:用mysqladmin
利用mysqladmin,我们不需要先登录,但是需要直到原来的密码;我们可以直接修改,修改密码格式为:
mysqladmin -u用户名 -p旧密码 password 新密码,注意,password前面没有 - ,例如:我们再把密码改成123456:
mysqladmin -uroot -p123 password 123456出现以下界面说明修改成功

方法3:用update直接编辑user表
(1)首先要先登录MySQL
(2)然后依次输入:
use mysql # 连接权限数据库
update user set password=password('521') where user='root' and host='localhost'; # 改密码
flush privileges; # 刷新权限出现以下界面说明修改成功:

方法4:忘记密码处理方式
1. 关闭正在运行的MySQL服务。
win+r输入:services.msc回车,找到MySQL,手动关闭MySQL服务
2. 打开DOS窗口,利用cd命令转到mysql的bin目录:建议直接找到mysql的bin目录下输入cmd回车
3. 输入mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。
4. 再开一个DOS窗口(刚才那个DOS窗口已经不能动了),转到mysql的bin目录。
5. 输入mysql回车,如果上面修改成功,将直接出现 mysql> 这样的提示符。
6. 连接权限数据库: use mysql
6. 改密码:update user set password=password("123") where user="root";
7. 刷新权限(必须步骤):flush privileges; (不要忘记分号)
8.exit或者ctrl+c退出,进行重新登陆
结束语
今天的分享就到这里啦!快快通过下方链接注册加入刷题大军吧!各种大厂面试真题在等你哦!
刷题神器,从基础到大厂面试题点击跳转刷题网站

边栏推荐
- Share an esp32 relay
- Emotional drama in the world Zhou Bingkun lost his job because he saw Tu Zhiqiang and was shot
- Lock mechanism in MySQL database InnoDB storage engine (glory Collection Edition)
- Wechat campus maintenance and repair applet graduation design finished product of applet completion work (4) opening report
- cn+dt
- Which database is the fastest to query data only?
- [hcip] BGP Foundation
- 怎么简单实现菜单拖拽排序的功能
- 小程序毕设作品之微信校园浴室预约小程序毕业设计成品(2)小程序功能
- cn+dt
猜你喜欢

MySQL数据库InnoDB存储引擎中的锁机制(荣耀典藏版)

How is insert locked in MySQL? (glory Collection Edition)

使用BigDecimal类型应该避免哪些问题?(荣耀典藏版)

Wechat campus bathroom reservation applet graduation design finished product (2) applet function

Plato Farm在Elephant Swap上铸造的ePLATO是什么?

Today in history: the father of database passed away; Apple buys cups code; IBM chip Alliance

Three core issues of concurrent programming (glory Collection Edition)

分层图解决的一些最短路问题
![[data processing] boxplot drawing](/img/4e/c4f863d06d8b318e6bb2d40e0c5ed3.png)
[data processing] boxplot drawing

小程序毕设作品之微信校园浴室预约小程序毕业设计成品(2)小程序功能
随机推荐
功能测试和非功能测试区别简析,上海好口碑软件测试公司推荐
Unity saves pictures to albums and rights management
Which database is the fastest to query data only?
【软件测试】—— 自动化测试之unittest框架
C # introducing WinAPI to pass the character set of Chinese string parameters
In practical work, how do I use postman for interface testing?
[advanced ROS] Lecture 9 robot model motion based on rviz and arbotix control
QT implementation disable shortcut key
【愚公系列】2022年07月 Tabby集成终端的使用
Design of edit memory path of edit box in Gui
Canvas 从入门到劝朋友放弃(图解版)
This operation may not be worth money, but it is worth learning | [batch cutting of pictures]
OBS键盘插件自定义diy
What is eplato cast by Plato farm on elephant swap?
分层图解决的一些最短路问题
Interviewer: what is the factory method mode?
Promise from introduction to mastery (Chapter 4 async and await)
JS event loop synchronous task, asynchronous task (micro task, macro task) problem analysis
【ROS进阶篇】第九讲 基于Rviz和Arbotix控制的机器人模型运动
Compile and use Qwt in qt|vs2017
