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
- 大硬盘 VPS 35 刀每年 512M 内存 0.5T 硬盘 virma全球[VPS测评]
- 便宜 VPS $1.49 月 2CPU 512M 内存 10G SSD 全球[VPS测评]
- 国庆特惠 咖啡主机→美国三网 CN2 GIA 线路 VPS 月付低至 1美国VPS[主机]
- Word2007 清除最近打开的文档记录全球[VPS测评]
- 上新极光 KVM→美国洛杉矶 PZ 中美优化线路 KVM 123.45 美国VPS[主机]
- 疯狂猜成语 图猜成语一个而两个志上面还有一个圆圈是什么成语?全球[VPS测评]
- iWFHosting→KVM2G 每月 8.99 美元起 洛杉矶可选 1全球[VPS测评]
- Linode正式更换至新的云管理面板全球[VPS测评]
- WordPress隐藏后台登录地址的最简单方法全球[VPS测评]
- 阿里云ECS服务器如何创建修改删除自动快照策略?全球[VPS测评]
- CloudCone便宜 KVM VPS,1G内存/50GB容量/1Gbp全球[VPS测评]
- Wikihost(idc.wiki) → 日本CN2 去程163回程C日本VPS[主机]
- 美国信贷市场的痛苦将不亚于上世纪70年代的通胀时期美国VPS[主机]
- 原创解析:云计算含义及定义全球[VPS测评]
- 磐逸云怎么样?1核1G香港安畅CN2 VPS带宽5M年付128元香港VPS[主机]
- GreenCloudVPS:5折、6折优惠,日本、新加坡、香港等KVM 日本VPS[主机]
- UCloud云服务器2020年度大促:北京/上海云服务器/香港免备案云服香港VPS[主机]
- 快速云:云服务器和vps区别是什么云服务器和vps哪个比较安全2022-全球[VPS测评]
- 阳帝云:香港大宽带vps仅15元/月;美国vps200G防御仅28元/月美国VPS[主机]
- 互盟云怎么样?1核2G云服务器仅468元/年,香港云主机58元/月香港VPS[主机]
- 硅云香港云服务器促销活动:CPU性能100%性能,无需备案香港VPS[主机]
- 2021年UCloud云服务器价格表,UCloud全球云主机租用报价表全球[VPS测评]
- 六六云:香港BGP云服务器/80M大带宽,月付45元起,5折优惠码可用香港VPS[主机]
- edgenat:韩国cn2+香港cn2,VPS八折优惠,8核8G/50gWINDOWS
- 8K超高清记录中国空间站凌月:天和核心舱与问天实验舱组成“土”字结构虚拟空间(主机)
- 2021年UCloud云服务器价格表,UCloud全球云主机租用报价表全球[VPS测评]
- 56云服务器怎么样?56云服务器价格和优势是什么?全球[VPS测评]
- 极光KVM双12:全场月付/季付产品全部5折,永久优惠,年付最高立减15全球[VPS测评]
- 磐逸云怎么样?香港沙田cn2vps 带宽5M年付128元香港VPS[主机]
- dogyun:香港/韩国/美国cn2定制VPS,静态云服务器终身8折,低韩国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-31467.html











