MySQL 8.0如何重置密码
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

安装 MySQL 8.0 后,默认的用户 root 是没有密码的,需要修改默认的初始化密码。假如忘记了 root 用户的密码,也是需要重置密码的。
首先安装 MySQL 8.0 后,启动 MySQL 服务。我这里是在 MAC 上安装使用的。
brew install mysqlbrew services start mysql| 12 | brew install mysqlbrew services start mysql |
因为默认是没有密码的,所以先直接进入 MySQL 服务中。
➜ ~ mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 13Server version: 8.0.12 HomebrewCopyright (c) 2000, 2018, Oracle and/or its seoiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsseoiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>| 1234567891011121314 | ➜ ~ mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 13Server version: 8.0.12 Homebrew Copyright (c) 2000, 2018, Oracle and/or its seoiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsseoiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> |
方法一
假如启动 MySQL 时候启动了授权表,也就是没有加上 skip-grant-tables 启动参数。使用这种方法设置密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123456';| 1 | ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123456'; |
如果你用数据库可视化软件VPS.COM.IN时,出现下面的报错:
Unable to load authentication plugin ‘caching_sha2_password’.| 1 | Unable to load authentication plugin ‘caching_sha2_password’. |
这是因为 MySQL 8.0 使用的新的身份验证机制 caching_sha2_password,如果不想用这个,可以用之前的旧的验证方式。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';| 1 | ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; |
或者修改默认的配置也可以。
[mysqld]default_authentication_plugin=mysql_native_password| 12 | [mysqld]default_authentication_plugin=mysql_native_password |
方法二
假如启动 MySQL 时候没有启动了授权表,也就是加上 skip-grant-tables 启动参数。
这种时候一般是忘记了 root 用户的密码,这里的 root 用户是 MySQL 的用户,不要和 Linux 上的用户搞混了。
使用这种方法设置密码:
首先关闭并启动 MySQL,并进入 MySQL 命令行。
brew services stop mysqlmysqld --skip-grant-tables --skip-networkingmysql| 123 | brew services stop mysqlmysqld --skip-grant-tables --skip-networkingmysql |
把密码设置为空。
UPDATE mysql.user SET authentication_string=null WHERE User='root';FLUSH PRIVILEGES;exit;| 123 | UPDATE mysql.user SET authentication_string=null WHERE User='root';FLUSH PRIVILEGES;exit; |
然后关闭 MySQL 并正常启动,不需要 skip-grant-tables 启动参数了。
mysql -uroot| 1 | mysql -uroot |
重复方法一的操作设置密码。
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123456';| 1 | ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '123456'; |
[资源]历史优惠活动内容
猜你可能想看的VPS
- Ramnode 充值送 25% KVM 月费 3 美元起 支持小时计费 全球[VPS测评]
- 老板抠门-标准互联襄阳电信高防云服务器 最高 200G DDOS 防御 全球[VPS测评]
- PHP 保留两位小数(不四舍五入)全球[VPS测评]
- 特价 $1.8 月 512M 内存 10G 硬盘 1T 流量@1Gbps全球[VPS测评]
- ThinkPHP5 输出最后执行的 sql 语句全球[VPS测评]
- PHP 判断字符串是否以指定字符(串)开头的方法全球[VPS测评]
- 有点绕-Cloudean→€10 月 2GB 内存 30GB SSD 空虚拟空间(主机)
- 活动倒计时 Virmach→$15 年的 KVM 特价促销方案即将结束 全球[VPS测评]
- 便宜 $6.6 年 256M 内存 10G 硬盘 256G 流量@1Gb全球[VPS测评]
- raksmart 美国大陆优化服务器带宽速度及综合性能测评,raksma独立服务器[U]
- 五月促销 RAKsmart→美国站群首月半价 年付免费送 3 个月 I3站群服务器[IP]
- WordPress如何代码实现完全禁用REST API全球[VPS测评]
- Gandi.net新注册.COM域名只需7元/首年带免费Whois隐私保全球[VPS测评]
- 快速云:vps云服务器的区别是什么?2022-08-1913:32来源:全球[VPS测评]
- 中概股扫描网传拼多多正筹备跨境电商平台首站登陆美国美国VPS[主机]
- 瓜云互联怎么样?香港/美国洛杉矶CN2高防vps 50G月付34元美国VPS[主机]
- UCloud云服务器2020年度大促:北京/上海云服务器/香港免备案云服香港VPS[主机]
- 精编案例丨游戏行业转型升级迫在眉睫,云计算助力打造下一代游戏体验全球[VPS测评]
- 游戏服务器是什么意思?游戏服务器可以用云服务器吗?全球[VPS测评]
- 磐逸云怎么样?1核1G香港安畅CN2 VPS带宽5M年付128元香港VPS[主机]
- 永恒云:江苏挂机宝6元/月,60元/年;香港建站vps仅18元;深圳BG香港VPS[主机]
- 阿里云ecs香港服务器怎么购买?阿里云香港2核8G5M云服务器仅2449香港VPS[主机]
- 亿速云双12年终回馈:云服务器2折活动,订单满100元减50元全球[VPS测评]
- 如何更改WHMCS默认后台路径让WHMCS系统更安全全球[VPS测评]
- 麻花云:香港CN2VPS月付19元起,安徽移动8核/16G/20M独服2香港VPS[主机]
- 月神科技:香港云服务器,2核2G5M年付200元/年;美国2核2G50M美国VPS[主机]
- kvmla,新加坡VPS、香港VPS、日本VPS,2核2G云主机仅425日本VPS[主机]
- Ubuntu关机命令是什么?Ubuntu关机命令介绍全球[VPS测评]
- 明恒互联:双旦同庆活动开启,100G国内高防云售价116元/月,香港云主香港VPS[主机]
- 快云科技:香港VPS服务器_双向CN2/20Mbps大带宽,29元/月起香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-21735.html











