MySQL8.0:无密码进入mysql并更改密码

1、问题描述以及环境

打开navicat发现之前一直用的连接失效,错误弹窗如下。
在这里插入图片描述

  • Windows10
  • MySql8.0

操作之前先关闭MySQL服务:

Win + R 输入 services.msc

2、修改my.ini文件以及创建data文件夹

进入到C:\Program Files\MySQL\MySQL Server 8.0下,与网上搜的不同的是我没有.ini文件以及data文件夹,用管理员权限创建my.ini文件,内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
skip-grant-tables
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect='SET NAMES utf8mb4'
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = C:\Program Files\MySQL\MySQL Server 8.0 
datadir =  C:\Program Files\MySQL\MySQL Server 8.0\data
port = 3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

3、管理员权限打开命令行窗口

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

在这里插入图片描述

4、无密码进入mysql

然后再打开一个命令行窗口,输入mysql可以直接进;
在这里插入图片描述
在这里插入图片描述
show tables可以看见最下面有一个user表;
在这里插入图片描述
在user表中可以查看用户以及密码如下:

 select user,host,authentication_string from user;

g.csdnimg.cn/direct/31a0dbe365c24c97b65da8823c5c9663.png)
密码有可能是明文,有可能是加密的。
再输入以下:

flush privileges;
set password for root@localhost='root'

再用navicat连接,成功连接。
在这里插入图片描述

参考博客:
Mysql 80 解决忘记密码无法跳过错误 mysqld --console --skip-grant-tables --shared-memory 代码无效的问题
Mysql8.0数据库修改密码/无法修改密码【改用"mysqld --console --skip-grant-tables --shared-memory"修改密码】
windows下忘记MySQL用户名与密码的办法(最新亲测可用)

PS:
😥搭环境需谨慎orz

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值