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
- 无 IPV4-vServer.site→€0.49 月 1 核 512M全球[VPS测评]
- 商家投稿 HostKvm→全新上线香港 Cera 全线 8 折优惠 新加香港VPS[主机]
- 标准互联→全场云服务器 8 折 香港云服务器年付 256 元起 美国年付美国VPS[主机]
- 分享一些支持比特币付款的国外独立服务器商家独立服务器[U]
- Dell latitude 3450 怎么关闭触摸板(win7)全球[VPS测评]
- MyW→洛杉矶 德国等虚拟 分销主机 不限流量 不限域名;2GB SSD虚拟空间(主机)
- 微基主机→香港 CN2 虚拟主机 6GB 空间 100GB 月流量 10虚拟空间(主机)
- 微基主机 IDC.WIKI→美国 CN2 虚拟主机 日本 CN2 VPS日本VPS[主机]
- 搬瓦工 CN2 GIA 补货啦,10Gbps 超大带宽美国 CN2 GI美国VPS[主机]
- VM.DOG→$50 月 2GB 内存 60GB 空间 不限流量 1Gb虚拟空间(主机)
- CombCloud 五一限时促销,香港大浦 沙田 cn2vps 七折优惠香港VPS[主机]
- 许诺云双十一 全场优惠 充值300送50 香港CN2GIA线路美国高防 美国VPS[主机]
- WordPress 支持上传 webp 图片的方法全球[VPS测评]
- HostSlim Cyber Monday 荷兰便宜OpenVZ VPS全球[VPS测评]
- 哪些WordPress收费主题最靠谱?全球[VPS测评]
- 六六云666clouds-日本软银 36元 月付8折 年付6折 联通友好日本VPS[主机]
- Mansora 2018圣诞优惠全球[VPS测评]
- 阿里云轻量级服务器低至144年付全球[VPS测评]
- 香港云服务器怎么选?云服务器性能测评对比香港VPS[主机]
- 40火伞高压电爬坡更让企业用电于民全球[VPS测评]
- 晚点独家丨拼多多9月上线跨境电商平台,首站美国美国VPS[主机]
- EdgeNAT,香港CN2+BGP vps 带宽5M 月付72元香港VPS[主机]
- 冀青云怎么样?香港CN2-GIA vps月28元/香港NTT 月9元香港VPS[主机]
- 云米科技:美国CERA三网回程GIA 10Mbps大带宽,年付最低400美国VPS[主机]
- 六一云:香港CN2/洛杉矶高防/CDN,“返利+折扣”双优惠,折上折送实香港VPS[主机]
- 2.45亿、成都公安(大数据基座-服务器)采购:神码、虹信、海康、超聚变全球[VPS测评]
- 互盟云元旦活动:云服务器1核2G首月仅18元,香港虚拟主机年付仅1折香港VPS[主机]
- 咖啡主机怎么样?美国洛杉矶高防vps,cn2直连,香港沙田vps美国VPS[主机]
- 腾讯云香港服务器2核4G30M仅804元/年,2412元/3年;国内轻量香港VPS[主机]
- HostKvm:韩国香港vps10月份最新促销,海外VPS全场八折优惠韩国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-28229.html











