设为首页 加入收藏

TOP

MySQL8.0 on Windows下重置root密码的BUG
2019-09-17 18:29:47 】 浏览:22
Tags:MySQL8.0 Windows 重置 root 密码 BUG

很多人都知道MySQL忘记root密码之后可以通过skip-grant-tables来暂时免密登录MySQL,从而修改root密码,但是这种方式一方面有安全隐患,另一方面也并不怎么适用于Windows系统,今天在通过此方式修改MySQL8.0 on Windows的root密码时遇到了这个问题,写个小随笔记一下。

参考:

https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

https://bugs.mysql.com/bug.php?id=90554

首先看下修改MySQL密码的两种方式:

方法一:

在MySQL的启动文件中添加skip-grant-tables参数后重启MySQL,然后免密登录MySQL后执行:

flush privileges; --必须先执行此命令
ALTER user root@'localhost' identified by 'newpasswd';

然后重启MySQL即可。

方法二:

创建一个名为root_newpass.txt的文本文件,放入如下内容:

ALTER user root@'localhost' identified by 'newpasswd';

然后使用此文件启动一次数据库:

mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file=root_newpass.txt
# --defaults-file必须写在--init-file之前

如果是在Linux下则无需添加--defaults-file项。

之后再按正常方式启动数据库就可以了。

使用方法一无法在MySQL8.0 on Windows上修改root密码的问题在哪儿?

在官方文档关于--skip-grants-tables的描述中5.7和8.0版本里有一句明显的差异,8.0里多了如下一句:

If the server is started with the --skip-grant-tables option to disable authentication checks, 
the server enables --skip-networking automatically to prevent remote connections.

其意思是当你使用--skip-grant-tables跳过授权检测启动MySQL时,MySQL会自动启用--skip-networking参数,这会阻止远程访问。

如果系统是windows那你需要开启shared-memory/shared-memory-base-name或者enable-named-pipe/socket这两对参数任意一对才能本地连接到mysql进行密码重置(关于这俩名字熟悉sqlserver的应该不陌生),但Windows版本的mysql并不会默认设置这些参数,这导致MySQL8.0在Windows上通过--skip-grant-tables重置密码是一件很麻烦的事,虽然这比5.7更安全。

推荐使用方法二在任意平台上进行root密码的重置。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL--时间戳与时区问题 下一篇Redis笔记

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目