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测评]
- 什么是云服务器?云服务器怎么登陆? 全球[VPS测评]
- 菜单选中标记CSS3动画效果 全球[VPS测评]
- 牛信云入选艾瑞《2022年中国跨境电商服务行业趋势报告》典型厂商 全球[VPS测评]
- 如何设置指定路径跳转指定域名? 全球[VPS测评]
- 瓜云互联怎么样?香港/美国洛杉矶CN2高防vps 50G月付34元 美国VPS[主机]
- 宏海数据9.9云服务器:香港VPS CN2线路1核1G 9.9/首月 香港VPS[主机]
- UOVZ怎么样?香港30M大带宽VPS 直连线路月付50元 香港VPS[主机]
- 亿速云“双11”上云狂欢大促 高防云服务器、裸金属服务器优惠套餐 全球[VPS测评]
- 品光网络怎么样?香港美国服务器/云/高防,开年采购3.5折起 美国VPS[主机]
- 硅云:香港云服务器2核2G5M促销1999元/3年起,香港虚拟主机1G空 虚拟空间(主机)
- 麻花云双12活动:香港CN2云主机首月9元;安徽移动vps月付29元 香港VPS[主机]
- 快云科技:香港CN2VPS,2核/2GB内存/3M独享,仅售14.98元 香港VPS[主机]
- 酷锐云元旦促销活动:香港CN2/美国CN2高防vps月付20元起/美国原 美国VPS[主机]
- 悦智网络:香港cn2 VPS阿里云线路,四川德阳高防vps,大连高防vp 香港VPS[主机]
- 蓝队云服务器怎么样?蓝队云服务器价格和优势是什么? 全球[VPS测评]
- edgeNAT:香港/韩国/美国CN2云服务器,企业运营,年付6折/月付 韩国VPS[主机]
- ucloud云主机怎么样?ucloud云服务器1核2G仅52元/年起;香 香港VPS[主机]
- 众创逸云:香港CN2/美国CN2降价促销,4核4G云服务器低至68元/月 美国VPS[主机]
- 特网云:香港高防CN2云服务器,新加坡/美国/洛杉矶/英国/荷兰等,5M 美国VPS[主机]
- 搬瓦工vps:10Gbps美国vps cn2 gia,1Gbps香港cn 日本VPS[主机]
- 腾讯云vps优惠:288元/3年,可选机房,北京/上海/广州/重庆/香港 美国VPS[主机]
- anyhk:香港HGC云服务器,1核/256MB/5GB SSD/600 香港VPS[主机]
- 创意加载进度HTML动画特效,SVG+CSS3实现的动画死神来了load 全球[VPS测评]
- 什么是云服务器?云服务器怎么登陆? 全球[VPS测评]
- 中国云计算,能啃的只剩硬骨头了 全球[VPS测评]
- 数字化东风已来,亚马逊云科技跨境电商合作企业招募大会即将开启 全球[VPS测评]
- 新华全媒+丨第六届全球跨境电商大会:跨境电商加快拓宽中国贸易新通道 全球[VPS测评]
- 老六云怎么样?香港cn2vps月付23元香港NTT月付9.9元 香港VPS[主机]
- wikihost,微基主机:1核/1G/15G/100Mbps/香港vp 香港VPS[主机]
转载请注明原文地址: http://140.238.13.167:12355/read-31467.html











