查看本地数据库/MySQL密码忘记-避坑

查看数据库

1win+r然后输入cmd

2输入mysql -uroot -p

3输入你的密码

4输入 show  databases;

5完成

MySQL密码忘记

1.以管理员身份运行cmd,关闭mysql服务

net stop mysql


2.跳过密码输入授权

mysqld --console --skip-grant-tables --shared-memory 


3.再打开一个cmd窗口,重置密码
### 执行命令 : mysql(会直接进入不用输入密码)

### 执行命令  :   use mysql(进入msql这个数据库)

### 查看一下数据 : select user,password,host from user;
 

此处报错:

ERROR 1054 (42S22): Unknown column 'password' in 'field list'

解决:

问题原因:password 字段是在mysql 8以下的版本中标记mysql数据库里 user表里的密码字段,但是mysql 8的密码字段改了,改成了:authentication_string

所以当环境变成mysql 8的时候 对应的sql语句应该变成:select user, authentication_string, host from user;
 


修改密码  :update user set authentication_string='123456' where user='root' and host='localhost';


报错:

ERROR 1054 (42S22): Unknown column 'password' in 'field list'

修改:update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql>update mysql.user set authentication_string=password('123456') where user=' at line 1

update user set authentication_string='123456' where user='root' and host='localhost';

成功!


4.关闭这两个cmd窗口,重新打开一个
启动服务 :   net start mysql

进入mysql:   mysql -uroot -p
 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值