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
- 一个大的功字和一个小的成字还有法院是什么成语?全球[VPS测评]
- VMware 提示→您已输入用户名 客户机操作系统将保留此用户名。全球[VPS测评]
- HKServerSolution→699 元 年 2G 内存 15GB 虚拟空间(主机)
- Krypt ION→$15 月 1GB 内存 25GB SSD 空间 5虚拟空间(主机)
- losangelesvps 洛杉矶 G 口无限流量 vps 特惠,1 核全球[VPS测评]
- Rabbithosts→4400 元 月 2 核 4GB 内存 20GB虚拟空间(主机)
- 极客主机→49 元 月 KVM-1GB 20GB 300GB 拉斯维加斯全球[VPS测评]
- 疯狂猜成语 图猜成语一个锤子在打铁还有火苗是什么成语?全球[VPS测评]
- 促销 极光 KVM 月中优惠→东京 CN2 线路 1 核 1G 套餐月付全球[VPS测评]
- HKServerSolution→599 元 年 2 核 2G 内存 2虚拟空间(主机)
- 9s9s→大带宽洛杉矶 CN2 GIA VPS 圣何塞不限流量 VPS 全球[VPS测评]
- 阿里云双 11 活动推荐→云服务器首年 86 元起 个人 企业 香港全能香港VPS[主机]
- UEditor 上传图片超出一定宽度后被自动压缩怎么办?全球[VPS测评]
- JQuery 根据指定值动态设置 select 下的 option 选中全球[VPS测评]
- 疯狂猜成语 图猜成语三个生字中间的生子下面是一个幸字是什么成语?全球[VPS测评]
- Chrome插件Logo Grabber快速取得网站或品牌Logo全球[VPS测评]
- 超值! CCleaner Pro 5折促销 折后仅98.02元全球[VPS测评]
- CloudCone 512M 内存 15G 储存 1T流量 洛杉矶 MC全球[VPS测评]
- 2020黑五 Spartanhost → 个人用户最佳性价比抗DDoS全球[VPS测评]
- 缓解云计算人才焦渴,苏州工业园区用三年引得源头活水来全球[VPS测评]
- MoonVM,香港HKT家宽VPS服务器,动态IP一键切换,1G带宽任意香港VPS[主机]
- 菠萝云服务器怎么样?香港云主机BGP、CN2,2核1G2M带宽仅49元/香港VPS[主机]
- 微基主机:1核1G香港云服务器,100Mbps/香港CN2直连/KVM/香港VPS[主机]
- jquery css3实现的进度条动画特效,带加载进度条百分比动态效果。全球[VPS测评]
- 2023年 IDC市场结构和方向的深度分析全球[VPS测评]
- 谷歌浏览器网址如何显示http,www,Chrome谷歌浏览器恢复地址栏全球[VPS测评]
- jquery css3实现的进度条动画特效,带加载进度条百分比动态效果。全球[VPS测评]
- 纳米云怎么样?纳米云香港vps,4核1G主机价格80元/月香港VPS[主机]
- 搬瓦工vps:10Gbps美国vps cn2 gia,1Gbps香港cn日本VPS[主机]
- 极光kvm怎么样,便宜大带宽香港cmi vps/美国gia vps低至1美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-21735.html











