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
- 补货通知 搬瓦工→CN2 GIA 线路 512M 内存套餐补货了 年付 全球[VPS测评]
- QSVM→新加坡 KVM VPS 可选限制流量或不限流量;256MB 内全球[VPS测评]
- 促销 Hostdare→85 折促销优惠 CN2 和 CN2 GIA 线全球[VPS测评]
- ThinkPHP5 动态创建数据表方法全球[VPS测评]
- Vultr Debian 8 及 Centos7 系统 VPS 安装破解全球[VPS测评]
- 云创网络→55.2 元 月 512MB 内存 10GB SSD 空间 1虚拟空间(主机)
- 搬瓦工 CN2 GIA 线路 DC6 补货 年付 46.8 美元 支持支全球[VPS测评]
- 新商家慎重-LosAngelesVPS→$2.99 月 1 核 1G 不美国VPS[主机]
- 补货通知 $37.49 每年 512 内存 10G 硬盘 300G 流量全球[VPS测评]
- BandwagonHost - 搬瓦工上线全新 CN2 GIA ECOM全球[VPS测评]
- GigsGigsCloud 日本东京软银 VPS 预售,500M 大带宽日本VPS[主机]
- RAKsmart 双旦活动→圣何塞服务器 46 美元 香港服务器 122美国VPS[主机]
- 桔子 VPS→cn2 gia vps 29 元 月 512M 内存 20全球[VPS测评]
- 凑合-TenVM→40 元 月 512MB 内存 10GB SSD 空间虚拟空间(主机)
- RackNerd 520 狂欢促销,便宜美国 g 口 vps vds 五美国VPS[主机]
- 真实测评 云邦互联 E38 核 16GB 2TB 硬盘 10M 宽带 C全球[VPS测评]
- 免费VPS推荐,有三天五天的,也有永久免费的全球[VPS测评]
- Wikihost CN2 香港虚拟主机 → 8折终身优惠码香港VPS[主机]
- 推荐! Virmach → 1C 512M RAM 15G SSD 25全球[VPS测评]
- 游戏服务器是什么意思?游戏服务器可以用云服务器吗?全球[VPS测评]
- 邢志宏:加快推动高质量建设跨境电商综试区起势成势全球[VPS测评]
- WordPress去掉分类链接中category目录的两种方法全球[VPS测评]
- 2023年 IDC市场结构和方向的深度分析全球[VPS测评]
- 磐逸云怎么样?香港沙田cn2vps 带宽5M年付128元香港VPS[主机]
- UCloud促销:快杰云主机52元/年起,可选台湾(台北)/香港/北京/香港VPS[主机]
- 跨境电商洋码头生死攸关:买手流失资金被冻结保全全球[VPS测评]
- 消费复苏形势良好,我们将多措并举实施扩大内需政策全球[VPS测评]
- 快云科技:香港CN2 GIA云服务器,全场7折终身优惠,带宽20M,20香港VPS[主机]
- 八点云主机怎么样?香港2核4G5M带宽云主机,98元/月;国内4核8G云香港VPS[主机]
- 华纳云双十一钜惠活动:香港美国云服务器低至3.5折美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-21735.html











