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
- LOCVPS→日本大阪 65 折 XEN2G 套餐月付 44.2 元 充日本VPS[主机]
- vpszi→美国三网 cn2 gia VPS 五一活动”5 折优惠 免费美国VPS[主机]
- 优惠活动 野草云→虚拟主机 VPS 全场 8 折优惠 香港 1G 2G 香港VPS[主机]
- Laravel 报错 Call to undefined functio全球[VPS测评]
- 解决浏览器不能正常下载 txt 而是直接打开的问题(HTML 版本)全球[VPS测评]
- 投稿 hostkvm→香港三网直连线路限量 7 折优惠 KVM 架构 无香港VPS[主机]
- 便宜 $1.08 月 256M 内存 15G 硬盘 1.5T 流量@1G全球[VPS测评]
- 腾讯云秒杀→1C2G1M 年付 88 元三年 268 元 2C4G3M 全球[VPS测评]
- 搬瓦工最新优惠码更新 终身优惠 6.38% 2019 年搬瓦工优惠最多的全球[VPS测评]
- 疯狂猜成语 图猜成语一个大的逆字和一个小的首字是什么成语?全球[VPS测评]
- 活动 HostXen→新用户送 20 元 日本直连 7M 不限流量 VP日本VPS[主机]
- 便宜 PacificRack→1 核 512M 10G 500G 年付$全球[VPS测评]
- 真实测评 野草云 5 月香港 CN2+BGP,1H2G20GB SSD,香港VPS[主机]
- 便宜 Dogyun→78 折优惠开启 1 核 512M 10G SSD 全球[VPS测评]
- WordPress站内链接修改插件:Velvet Blues Updat全球[VPS测评]
- 解决Debian9系统环境中文乱码的问题 检查设置UTF-8编码全球[VPS测评]
- 比TinyPNG好用的Squoosh在线图片压缩全球[VPS测评]
- WordPress文章发布时间怎么精确到秒?全球[VPS测评]
- zetservers罗马尼亚高防vps,10Gbps带宽/2Tbps高防全球[VPS测评]
- 大前端 DUX/D8/XIU WordPress 主题双11全场6折 最全球[VPS测评]
- EtherNetservers促销套餐 1G内存/30G硬盘/2个IP 全球[VPS测评]
- RivenCloud 1G内存 10G SSD 5M带宽不限流量 全区x全球[VPS测评]
- 为什么大家都选择香港服务器建站香港VPS[主机]
- 拼多多正筹建跨境电商平台:密集挖角SHEIN员工,零佣金招商入驻全球[VPS测评]
- 菠萝云服务器怎么样?香港云主机BGP、CN2,2核1G2M带宽仅49元/香港VPS[主机]
- 雪花云怎么样?雪花云香港云服务器1核1G2M仅19元/月香港VPS[主机]
- 腾讯云香港/韩国/日本免备案服务器优惠促销活动日本VPS[主机]
- VPSPlayer,超便宜香港cn2线路小带宽VPS,2核4G内存仅30香港VPS[主机]
- 永恒云:江苏挂机宝6元/月,60元/年;香港建站vps仅18元;深圳BG香港VPS[主机]
- ERP库存管理系统HTML5模板 - DreamsPOS全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-24985.html











