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
- 促销 HostKvm→香港云地国际 新加坡套餐限量 7 折促销 月付 5香港VPS[主机]
- 疯狂猜成语 图猜成语一个人端着盘子里面装着梨另一个人在推辞是什么成语?全球[VPS测评]
- vultr 韩国 vps 云服务器上线,三网直连,按小时计费,1 核 1韩国VPS[主机]
- ZJI 香港云地多 IP 站群服务器 237 个 IP 香港站群服务器 站群服务器[IP]
- 波特兰会炸-Moonvm→波特兰 VPS 1 核 1G 内存 15G S全球[VPS测评]
- 中秋特惠 魔方云→KVM 架构 VPS 全场 9 折优惠 香港 CN2 香港VPS[主机]
- HostHatch→芝加哥 伦敦大硬盘 VPS 年付 15 美元起 NV全球[VPS测评]
- 90VM→100 元 月 1GB 内存 20GB SSD 空间 1TB 虚拟空间(主机)
- LOCVPS→57.6 元 月-2GB 40GB 3M 香港大埔 CN2香港VPS[主机]
- 惊字下面一个石字是什么成语?全球[VPS测评]
- php 生成随机颜色最简单办法 php 一句话代码生成随机颜色全球[VPS测评]
- 腾讯云秒杀→云服务器 1C1G1M 年付 99 元起 2C4G6M 三年全球[VPS测评]
- 疯狂猜成语 图猜成语一个人隔着河在看对面的火是什么成语?全球[VPS测评]
- 硅云香港云服务器促销,免备案 100%CPU 性能,最高 80M 带宽,香港VPS[主机]
- LOCVPS 香港邦联全新套餐,高性价比 Cn2 线路,2 核 2G 内香港VPS[主机]
- VirMach→$27 月-E3-1240v1 16GB 1TB 10T全球[VPS测评]
- 私有文档、源码、软件目录列表程序:Zdir全球[VPS测评]
- Vultr VPS主机如何添加自定义防火墙规则全球[VPS测评]
- WordPress免插件代码实现Gravatar头像缓存全球[VPS测评]
- DediPath不走心的万圣节促销,VPS月付1.75美元起;便宜服务器全球[VPS测评]
- Securebit-$10 月 瑞士 1核心1G内存10G硬盘 独立IP独立服务器[U]
- Virmach → $1.5 月付 512M 内存 10G SSD硬盘 全球[VPS测评]
- 常见的CN2,GIA,CIA 各个网络线路解释全球[VPS测评]
- CubeCloud,香港cn2,美国cn2 gia线路vps主机,2核1美国VPS[主机]
- WordPress去掉分类链接中category目录的两种方法全球[VPS测评]
- 20个温暖心灵的问题,抖音,朋友圈都可以拿去发。全球[VPS测评]
- ExCloud:1核256M存/8GB SSD空间/100GB流量/OV虚拟空间(主机)
- 印象云vps,香港安畅gia低至22元起,1核1G内存,小带宽无限流量,香港VPS[主机]
- 极光KVM:美国香港vps CN2 GIA专线高速稳定,BGP服务器低至美国VPS[主机]
- 磐逸云怎么样?香港沙田cn2vps 带宽5M年付128元香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-24985.html











