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
- 2022年有哪些顶级托管服务提供商 全球[VPS测评]
- 拼多多拟建跨境电商平台:挖角SHEIN员工,0佣金招商入驻 全球[VPS测评]
- 云计算竞争日趋白热化云计算行业市场前景分析 全球[VPS测评]
- Vultr新用户100美金 最新活动来啦!新用户充值活动来了,充100美 全球[VPS测评]
- 老六云怎么样?香港cn2vps月付23元香港NTT月付9.9元 香港VPS[主机]
- 极光KVM:美国香港vps CN2 GIA专线高速稳定,BGP服务器低至 美国VPS[主机]
- edgeNAT:全场6折优惠,韩国CN2、美国CN2、香港CN2月付36 韩国VPS[主机]
- 亿速云“双11”上云狂欢大促 高防云服务器、裸金属服务器优惠套餐 全球[VPS测评]
- HostHatch:1核/2GB/20GB空间/KVM/香港/洛杉矶/纽 虚拟空间(主机)
- 紫云服务器怎么样?紫云香港云服务器1核1G2M仅65元/月 香港VPS[主机]
- RAKsmart促销活动:韩国服务器低价抢购,美国G口服务器低至$99, 韩国VPS[主机]
- 阿里云香港服务器多少钱一年?香港云服务器租用年付价格表 香港VPS[主机]
- tmhhost:香港安畅机房三网CN2 GIA VPS,月付45起;美国 美国VPS[主机]
- 水墨云:特惠香港、日本、韩国、洛杉矶小内存vps;IPLC专线/海外CN 日本VPS[主机]
- 天生云:香港沙田CN2 GIA VPS,1核1G40G/2M带宽,月付8 香港VPS[主机]
- 2021恒创科技开年采购季:香港/美国云服务器低至299元/年 美国VPS[主机]
- UCloud:香港云服务器,1核1G内存89元/年起(可选购3年/CN2 香港VPS[主机]
- VoLLCloud:香港200Mbps不限速大宽带VPS,免费vps领取 香港VPS[主机]
- 欧路云:美国圣何塞vps原生IP服务器!限量50台/弹性CN2,8元/月 美国VPS[主机]
- HTML5绿色有机食品电商网站模板 - Organtio 全球[VPS测评]
- 6种样式社交论坛网站HTML5模板 - Social 全球[VPS测评]
- 如何根据业务需求选择合适的云服务器配置? 全球[VPS测评]
- 什么是云服务器?云服务器怎么登陆? 全球[VPS测评]
- 虾皮跨境电商怎么样?虾皮跨境电商靠谱吗? 全球[VPS测评]
- 华凯易佰同比扭亏跨境电商行业回暖H2旺季将至|中报追踪 全球[VPS测评]
- 如何设置指定路径跳转指定域名? 全球[VPS测评]
- Linux chown -R 指令介绍与使用 全球[VPS测评]
- 轻云互联,香港美国vps终身8.8折17元/月起,cn2直连线路,50G 美国VPS[主机]
- 咖啡主机:享受7、8折促销 美国vps仅需15.4元/月 香港vps仅需 美国VPS[主机]
- YYYHost:4核4G香港cn2vps,20G SSD/3Mbps不限 香港VPS[主机]
转载请注明原文地址: http://140.238.13.167:12355/read-24985.html











