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
- 阿里云服务器 2020 年 2 月促销,100%CPU 性能,2 核 4全球[VPS测评]
- iWFHosting→$8.99 月 KVM-2GB 25GB 1.5T全球[VPS测评]
- DedeCMS 去掉后台登录页面广告的办法全球[VPS测评]
- layer 弹窗关闭时刷新父页面的两种方法全球[VPS测评]
- 搬瓦工换机房提示 Migration backend is curren全球[VPS测评]
- 疯狂猜成语 图猜成语一个人在火中跑向一锅汤是什么成语?全球[VPS测评]
- 数脉科技香港服务器五一促销,阿里云网络与自治网络自由切换,10M 无限流香港VPS[主机]
- 劳动节促销 标准互联→所有云服务器买两年送一年 圣何塞 CN2 GIA 全球[VPS测评]
- 疯狂猜成语 图猜成语一个美女和一滩水是什么成语?全球[VPS测评]
- DediPath 元旦优惠→VPS 全场 8 折 Hybrid Serv全球[VPS测评]
- 玩具-Hostdoc→$3.68 年付 堪萨斯 VPS 1 核 256M全球[VPS测评]
- QN 机房-SmartHost→$6.95 月 4 核 8GB 内存 4虚拟空间(主机)
- hosts 文件位置全球[VPS测评]
- Typecho 在小皮面板中添加伪静态规则全球[VPS测评]
- Debian LNMP/LEMP/WordPress/Typecho 快全球[VPS测评]
- Kuroit → 3£ 月 荷兰 1C1G10G硬盘 10Gbps端口2全球[VPS测评]
- 萌云英国伦敦GIA VPS 三网GIA 解锁流媒体全球[VPS测评]
- 什么是云服务器?云服务器怎么登陆?全球[VPS测评]
- centos7如何查看firewall防火墙状态:开启/关闭/重启防火墙全球[VPS测评]
- 轻云互联,香港美国vps终身8.8折17元/月起,cn2直连线路,50G美国VPS[主机]
- jquery css3实现的进度条动画特效,带加载进度条百分比动态效果。全球[VPS测评]
- 咖啡主机怎么样?咖啡香港/美国/法国VPS主机价格及配置推荐美国VPS[主机]
- 创意IT服务公司主页网站模板 - Softets全球[VPS测评]
- UCloud促销:快杰云主机52元/年起,可选台湾(台北)/香港/北京/香港VPS[主机]
- 极光kvm怎么样,便宜大带宽香港cmi vps/美国gia vps低至1美国VPS[主机]
- SugarHosts,美国云服务器,洛杉矶cn2中美极速专线,香港建站服美国VPS[主机]
- WordPress去掉分类链接中category目录的两种方法全球[VPS测评]
- 酷锐云:春节特惠,4核4G80G10M仅60元/月起,香港/美国云服务器美国VPS[主机]
- 香港云服务器怎么选?云服务器性能测评对比香港VPS[主机]
- 舍利云:香港美国vps云服务器/BGP线路元旦全场9折,低至36元/月美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-24985.html











