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
- 智商税-GigsGigsCloud→马来西亚 VPS 1 核 512M 全球[VPS测评]
- 2020 年最新国外便宜 VPS 盘点全球[VPS测评]
- dogyun→挑战低价-15 元 月 美国 cn2 gia VPS KV美国VPS[主机]
- 腾讯云秒杀→1C2G1M 年付 88 元三年 268 元 2C4G3M 香港VPS[主机]
- 搬瓦工补货 $37 年 512M 内存 10G SSD 300G@1Gb全球[VPS测评]
- 推荐 中小型企业怎么选择云服务器和 VPS 企业买 VPS 那里比较好!全球[VPS测评]
- DMIT→$48.88 季 1GB 内存 10GB SSD 空间 1TB虚拟空间(主机)
- DedeCMS 中 dede:channel 标签调用栏目简介 desc全球[VPS测评]
- word 文档回车后有点或者其他符号怎么办?全球[VPS测评]
- 酷锐云→15 元 月 1GB 内存 30GB 空间 100GB 流量 1虚拟空间(主机)
- 恒星云→香港 CN2 沙田 VPS 超低延迟 50ms 限时优惠首月 香港VPS[主机]
- stsdust 广州移动 vds 预售,1Gbps 带宽无限流量,硬件资全球[VPS测评]
- 基于CentOS系统的VPS安全设置与优化全球[VPS测评]
- Cloudcone双十一特价便宜VPS,KVM架构,1Gbps带宽,年付全球[VPS测评]
- 收不到 Google AdSense 广告联盟 PIN 码怎么办?全球[VPS测评]
- Flasheberg 法国服务器VPS 测试 (IP不错)全球[VPS测评]
- ionswitch-美国西雅图 1C1G10GB 1TB 1Gbps 3美国VPS[主机]
- CrownCloud -512M内存 1000G HDD 6T流量 1G全球[VPS测评]
- CMCUCT:2核2GB/20GB香港ntt线路vps 6TB流量/1G香港VPS[主机]
- 恒创科技怎么样?香港美国云服务器/独服/高防全场2.5折起美国VPS[主机]
- 实例 GIA0910629396 重启失败,原因:sudo: unabl全球[VPS测评]
- 亿速云11.11上云狂欢节活动:2核4G国内/香港云服务器,价格999元香港VPS[主机]
- 海量科技:香港2核2G云服务器,5M独享带宽,低至168元/月香港VPS[主机]
- 适合美容院的正能量抖音文案,唯美阳光,正能量满满全球[VPS测评]
- 麻花云双12年终盛典:香港云主机9元起,老客户续费6折;安徽BGP线路v香港VPS[主机]
- uuuvps:香港VPS低至97元/年,CN2+bgp网络,香港机房VP香港VPS[主机]
- 搬瓦工:美国香港cn2 gia线路VPS,10Gbps带宽,移动+联通企美国VPS[主机]
- 菠萝云服务器怎么样?香港云主机BGP、CN2,2核1G2M带宽仅49元/香港VPS[主机]
- tmhhost:香港安畅机房三网CN2 GIA VPS,月付45起;美国美国VPS[主机]
- CombCloud,香港沙田CN2VPS测评,2核1G52元/月,安畅C香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-28229.html











