当前位置:网站首页>修改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退出,进行重新登陆
结束语
今天的分享就到这里啦!快快通过下方链接注册加入刷题大军吧!各种大厂面试真题在等你哦!
刷题神器,从基础到大厂面试题点击跳转刷题网站

边栏推荐
- AWS elastic three swordsman
- ps 简单使用
- 第二季度邮件安全报告:邮件攻击暴增4倍,利用知名品牌获取信任
- [深入研究4G/5G/6G专题-42]: URLLC-14-《3GPP URLLC相关协议、规范、技术原理深度解读》-8-低延时技术-2-基于slot的调度与Slot内灵活的上下行符号配比
- 埃睿迪再度亮相数字中国峰会 持续深化用科技守护绿水青山
- 软工必备知识点
- 重要安排-DX12引擎开发课程后续直播将在B站进行
- Ceresdao: the world's first decentralized digital asset management protocol based on Dao enabled Web3.0
- Canonical Address
- [advanced ROS] Lecture 9 robot model motion based on rviz and arbotix control
猜你喜欢

With elephant & nbsp; Eplato created by swap, analysis of the high premium behind it

Use of Day6 functions and modules

Say yes, I will love you, and I will love you well

Flume (5 demos easy to get started)

How to put app on the app store?

Wechat campus maintenance and repair applet graduation design finished product of applet completion work (4) opening report

The cooperation between starfish OS and metabell is just the beginning

【ROS进阶篇】第九讲 基于Rviz和Arbotix控制的机器人模型运动

When iPhone copies photos to the computer, the device connection often fails and the transmission is interrupted. Here's the way

这个操作可能不值钱,但却值得学习 | 【图片批量裁剪】
随机推荐
This operation may not be worth money, but it is worth learning | [batch cutting of pictures]
Promise from introduction to mastery (Chapter 4 async and await)
使用BigDecimal类型应该避免哪些问题?(荣耀典藏版)
Feign calls get and post records
组原必备知识点
第二季度邮件安全报告:邮件攻击暴增4倍,利用知名品牌获取信任
pytorch优化器设置
How to put app on the app store?
[hcip] BGP features
Network must know topics
Important arrangements - the follow-up live broadcast of dx12 engine development course will be held at station B
Canvas 从入门到劝朋友放弃(图解版)
Alipay applet authorization / obtaining user information
With elephant & nbsp; Eplato created by swap, analysis of the high premium behind it
上课笔记(5)(1)——#593. 二分查找(binary)
Product axure9 English version, using repeater repeater repeater to realize multi-choice and single choice
关于Sqli-labs单引号不报错的问题
CeresDAO:全球首个基于DAO赋能Web3.0的去中心化数字资产管理协议
The cooperation between starfish OS and metabell is just the beginning
MySQL's way to solve deadlock - lock analysis of common SQL statements
