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
- MoeCloud→4000 元 月 4 核 4GB 内存 50GB SS全球[VPS测评]
- jsTree 自定义右键菜单方法全球[VPS测评]
- apache 设置 txt 文件直接下载而不是网页在线打开全球[VPS测评]
- SaltyFishTech 劳动节促销,100M 带宽新品德国 cn2v全球[VPS测评]
- GigsGigsCloud→新上小内存美国 CN2 GIA 套餐 1 核美国VPS[主机]
- reset.css 分享全球[VPS测评]
- 疯狂猜成语 图猜成语一个人在唱歌一个人在哭泣是什么成语?全球[VPS测评]
- servaRICA→$15 月 3 核 3GB 内存 2TB 空间 不限虚拟空间(主机)
- [11.11]ZJI→充 500 送 50 香港服务器 65 折 日本站站群服务器[IP]
- $4 月 512M 内存 20G SSD 1Gbps 不限流量 KVM 日本VPS[主机]
- Purplehost→$4.3 月 2GB 内存 20GB SSD 空间虚拟空间(主机)
- 便宜 VPS 1.97 卢布 天 512M 内存 5G SSD 1Gbp全球[VPS测评]
- 抗投诉 offshorededicated→不限内容 完全无视版权投诉 独立服务器[U]
- 繁体的無字中间包含一个有字是什么成语?全球[VPS测评]
- 一个房子房顶是金字下面有一个娇字是什么成语?全球[VPS测评]
- MikyHost → 25$ 年 1C512M25G硬盘 1T流量 新加日本VPS[主机]
- Sunucu al → 5.3$ 月 土耳其 2C2G35G硬盘 ipv全球[VPS测评]
- CubeCloud 新年促销 75 折全球[VPS测评]
- 50KVM VPS免费自助换IP功能全球[VPS测评]
- LightCloud 2019 新春: 终身折扣 VDS折扣 充全球[VPS测评]
- 长三角地区的算力需求规模到底有多大?全球[VPS测评]
- 实例 GIA0910629396 重启失败,原因:sudo: unabl全球[VPS测评]
- 晚点独家丨拼多多9月上线跨境电商平台,首站美国美国VPS[主机]
- 咖啡主机:美国高防vps、香港vps 可享受6-7折促销 每月仅需14元美国VPS[主机]
- 2020年国外VPS哪个最好?教你学会选择国外VPS全球[VPS测评]
- 精美的宠物医院网站WordPress主题 - Valkuta全球[VPS测评]
- ExCloud:1核256M存/8GB SSD空间/100GB流量/OV虚拟空间(主机)
- DMIT:香港/洛杉矶GIA等KVM VPS,黑五DMIT优惠码活动,稳香港VPS[主机]
- 极光kvm怎么样,便宜大带宽香港cmi vps/美国gia vps低至1美国VPS[主机]
- 欧路云:美国特价云服务器/50M带宽8元/月起;香港云服务器月付15元起美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-24985.html











