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
- uovz 青岛 200G 高防独服上线,青岛联通高防,青岛 BGP 高防全球[VPS测评]
- VirMach→$27 月-E3-1240v1 16GB 1TB 10T全球[VPS测评]
- VPS 零元购 酷番云:1 核 1G 60G 硬盘 2M 带宽 内蒙机房全球[VPS测评]
- 做站 腾讯云双 11 秒杀活动→国内云服务器低至 88 元 年 香港免备香港VPS[主机]
- 疯狂猜成语 图猜成语一根羽毛和一只角是什么成语?全球[VPS测评]
- 稳定 搬瓦工 DC9 机房 CN2 GIA 线路 512M 内存套餐补货全球[VPS测评]
- 疯狂猜成语 图猜成语狗的身体老虎的头是什么成语?全球[VPS测评]
- 极光 KVM 五月中促销活动,香港 cmi 日本 cn2 美国 cn2,日本VPS[主机]
- 做站必选 腾讯云→2 折秒杀活动 性价比高 上海 广州 成都 香港机房香港VPS[主机]
- 大盘机 $7.49 月 1G 硬盘 1T 硬盘 2T 流量 1Gbps 全球[VPS测评]
- Gandi.net新注册.COM域名只需7元/首年带免费Whois隐私保全球[VPS测评]
- WordPress插件:Compress JPEG & PNG imag全球[VPS测评]
- 私有文档、源码、软件目录列表程序:Zdir全球[VPS测评]
- HostKvm 新上洛杉矶CN2VPS 2G内存入门套餐七折终身优惠$6全球[VPS测评]
- AcroServers 波兰商家,全球38个节点,默认1Gbps带宽,€全球[VPS测评]
- 百度高速下载神器PanDownload2.0.6更新 功能更强大全球[VPS测评]
- 华纳云新上美国服务器,5M带宽云服务器年付384元起;洛杉矶高防独立服务独立服务器[U]
- 如何在 CentOS 7 服务器上使用 yum命令安装 PHP7.2全球[VPS测评]
- 潮科技|阿里云发布第七代高主频云服务器ECS和含光800云服务器全球[VPS测评]
- 私有云架设之优选拓普龙S465-24高密度存储服务器机箱评测解析全球[VPS测评]
- MoonVM,香港HKT家宽VPS服务器,动态IP一键切换,1G带宽任意香港VPS[主机]
- UCloud香港云主机怎么样?UCloud香港云主机1核1G1M评测香港VPS[主机]
- edgeNAT:全场6折优惠,韩国CN2、美国CN2、香港CN2月付36韩国VPS[主机]
- 搬瓦工:美国香港cn2 gia线路VPS,10Gbps带宽,移动+联通企美国VPS[主机]
- 无忧云:香港大埔/荃湾云服务器5折优惠,可叠加优惠码,国内高防78元起香港VPS[主机]
- 特网云:新上香港高防云主机,金盾防护无视CC,恶意流量攻击防护香港VPS[主机]
- 桔子数据:1核/1G/50Mbps/洛杉矶CUVIP线路/首月14元;香香港VPS[主机]
- wordpress 上传附件报错 “抱歉,出于安全的考虑,不支持此文件类全球[VPS测评]
- 用玩客云做打印服务器,让你在手机上轻松实现无线打印全球[VPS测评]
- 云服务器和服务器各有什么优缺点?全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-31467.html











