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
- 云霸天下 IDC 日本站群服务器促销,4C 段 253 个 IP,50M站群服务器[IP]
- tmhhost→香港 cn2 服务器(物理机) 400 元 月 X345香港VPS[主机]
- JQuery ajax 中 serialize()方法增加自定义参数全球[VPS测评]
- 日本 VPS 49 元每月 1G 内存 650G 流量 日本大阪 Hos日本VPS[主机]
- 一堆数字 3 一堆数字 5 是什么成语?全球[VPS测评]
- MoeCloud 香港 HGC 商宽 VDS 上线,500M 端口无线流香港VPS[主机]
- 新商家慎重-ManSora Cloud→$7.49 200M 宽带 50全球[VPS测评]
- 便宜 $13.85 每年 1 核 1G 内存 18G SSD 2T 流量全球[VPS测评]
- 真实测评 justhost→8.3 元 月 200M 带宽 不限流量 K全球[VPS测评]
- TeraDelta→美东费城虚拟主机 5GB SSD 空间 不限流量 年虚拟空间(主机)
- 促销 HostSailor→罗马尼亚 KVM XEN 架构 VPS 四折全球[VPS测评]
- HostKvm 10月全场八折优惠 CN2优化线路VPS月付最低7.6刀全球[VPS测评]
- 酷番云双十一 高防服务器1.5折起 2核2G5M带宽无限流量国内高防只需全球[VPS测评]
- 如何防止google voice被回收全球[VPS测评]
- 创意IT服务公司主页网站模板 - Softets全球[VPS测评]
- 6种样式社交论坛网站HTML5模板 - Social全球[VPS测评]
- JGKVM促销,美国cn2vps服务器价格再创新低,平均6.5元/月起美国VPS[主机]
- 香港云服务器对于建站有什么便捷的地方?香港VPS[主机]
- 百看不厌的文案,抖音唯美文案。全球[VPS测评]
- 亿速云双12年终回馈:云服务器2折活动,订单满100元减50元全球[VPS测评]
- 奇异互动:香港2核4G5M云服务器仅83元/月,700元/年;裸金属服务香港VPS[主机]
- 95idc怎么样?香港云主机1核2G2M仅50元/月;香港物理服务器8核香港VPS[主机]
- 阿里云香港vps怎么样?阿里云香港、新加坡云主机如何购买?香港VPS[主机]
- 修罗云:1核/512MB/6GB空间/1TB流量/NAT/KVM/香港H虚拟空间(主机)
- 阿里云香港服务器多少钱一年?香港云服务器租用年付价格表香港VPS[主机]
- 企鹅小屋:1核/512MB/10GB SSD空间/500GB流量/KVM虚拟空间(主机)
- EdgeNAT,香港CN2+BGP vps 带宽5M 月付72元香港VPS[主机]
- 汇速云:香港沙田CN2云主机,2核CPU带宽1M月付6元,2核2M带宽月香港VPS[主机]
- 柚子互联:香港CN2云服务器/天机盾防护/带宽5M,34元/月香港VPS[主机]
- 酷锐云:香港安畅机房4H/4G/60G/20Mbps,45元/月;香港C香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-31467.html











