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
- GeorgeDatacenter→$5 月 1GB 内存 25GB SS虚拟空间(主机)
- 死海网络→CN2 GIA 线路高速 VPS 美国原生 IP 可看奈飞 提美国VPS[主机]
- 浩瀚星辰→1750 元 月 8 核 2GB 内存 120GB 空间 不限虚拟空间(主机)
- 优惠 Namesilo→CO 域名注册 5 年仅需要 7.7 美元 免费全球[VPS测评]
- FlashFXP 错误 530 Login incorrect 解决方法全球[VPS测评]
- 真实测评 Vultr 美国亚特兰大(Atlanta)机房 VPS 测评美国VPS[主机]
- 腾讯云→热门云产品限时限量特惠秒杀 云服务器 1 核 2G 99 元 1全球[VPS测评]
- 推荐 iON→KT 旗下品牌 CN2 线路 洛杉矶机房 全场限时 5 折全球[VPS测评]
- teraswitch→$4 月 OpenStack 1g 内存 1 核 美国VPS[主机]
- Vultr→韩国 日本 新加坡 洛杉矶 欧洲等 KVM VPS 随时更换日本VPS[主机]
- WordPress前端优化设置教程全球[VPS测评]
- 私有文档、源码、软件目录列表程序:Zdir全球[VPS测评]
- 搭建VPS环境选择LAMP环境还是LNMP环境好全球[VPS测评]
- 搬瓦工VPS面板新增Mount ISO内置100+系统镜像 附安装Gno全球[VPS测评]
- Cloudcone 年付 $9.9 的美国便宜 VPS 套餐补货美国VPS[主机]
- ht-hosting-3欧 月1C2g20g 德国杜尔塞夫 1Gbps 全球[VPS测评]
- 快速云:vps云服务器的区别是什么?2022-08-1913:32来源:全球[VPS测评]
- 亚马逊卖家与广告流量之间的博弈才刚刚开始?品牌卖家如何冲破广告之困...全球[VPS测评]
- 香港的云服务器值得租用吗?有什么好处?香港VPS[主机]
- anyhk:香港HGC/WTT/HKT线路、台湾HiNet线路NAT套餐香港VPS[主机]
- 企鹅小屋怎么样?深港IPLC专线销售 500M大带宽/2核1G内存/55全球[VPS测评]
- 岚云:香港安迅/沙田CN2直连,75折起,1核/1G/30G SSD/1香港VPS[主机]
- 再“掷”53亿元 宜家能否挽回中国消费者全球[VPS测评]
- 影速科技怎么样?影速科技海外云服务器价格多少钱?全球[VPS测评]
- 持续高温!长沙所有初中新生停止军训!全球[VPS测评]
- 腾讯云vps优惠:288元/3年,可选机房,北京/上海/广州/重庆/香港美国VPS[主机]
- 众创逸云:国庆中秋节大促销优惠,不限流量香港CN2线路VPS 5.9元/香港VPS[主机]
- TmhHost:香港大带宽云服务器/季付8折/200带宽,120元/3月香港VPS[主机]
- centos7如何查看firewall防火墙状态:开启/关闭/重启防火墙全球[VPS测评]
- 恒创科技:国庆中秋双节同庆,香港1核2G云服务器,年付378元香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-28229.html











