忘记密码mysql 8.2重置root密码|macos+linux

重置密码

2024年1月6日验证

1.找到support-files下的服务

# 查找mysql位置
which mysql
#/usr/local/bin/mysql

# 查找原始位置
ls -al /usr/local/bin | grep mysql

# 进入原始的为值找到support-files文件夹
# 注意路径要全,我这里是macos系统就是Cellar下
cd /usr/local/Cellar/mysql/8.2.0_1/support-files

# 停止之前的服务,2选1
sudo mysql.server stop # MacOS命令
sudo service mysql stop # Linux命令

# 运行mysql服务 跳过密码验证,记得sudo
sudo ./mysql.server --skip-grant-tables

2.无密码登录

# 无密码登录
mysql -u root
# 删除密码,刷新,退出
mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
mysql> flush privileges; 
mysql> exit

# 重新登录
mysql -u root

3.修改密码

注意密码复杂度需要根据验证等级设置,后面附查看方法
默认中等:>=8位,大写字母+小写字母+特殊字符

mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'Chris999000...';
mysql>flush privileges;
mysql>exit;

4. 验证是否修改成功

# macos 操作
sudo mysql.server stop
## 正常启动
sudo mysql.server start
----------------------------------------
## linux下操作
sudo service mysql stop
sudo service mysql start
mysql -u root -p
# 输入新的密码
mysql>

查看密码等级信息

# 输入这个命令
mysql> SHOW VARIABLES LIKE 'validate_password%';
# 显示结果
+-------------------------------------------------+--------+
| Variable_name                                   | Value  |
+-------------------------------------------------+--------+
| validate_password.changed_characters_percentage | 0      |
| validate_password.check_user_name               | ON     |
| validate_password.dictionary_file               |        |
| validate_password.length                        | 8      |
| validate_password.mixed_case_count              | 1      |
| validate_password.number_count                  | 1      |
| validate_password.policy                        | MEDIUM |
| validate_password.special_char_count            | 1      |
+-------------------------------------------------+--------+
8 rows in set (0.02 sec)

Fix - MySQL ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

There are three levels of password validation policy enforced when Validate Password plugin is enabled:

  • LOW Length >= 8 characters.
  • MEDIUM Length >= 8, numeric, mixed case, and special characters.
  • STRONG Length >= 8, numeric, mixed case, special characters and dictionary file.
  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是重置MySQL密码的步骤: 1. 打开命令行窗口,并使用管理员权限运行命令提示符(Windows)或终端(Linux/macOS)。 2. 停止MySQL服务。在命令行中输入以下命令: ```shell sudo service mysql stop # Linux sudo systemctl stop mysql # Linux (systemd) sudo /etc/init.d/mysql stop # Linux (init.d) ``` 3. 启动MySQL服务,并跳过权限验证。在命令行中输入以下命令: ```shell sudo mysqld_safe --skip-grant-tables & # Linux ``` 4. 打开另一个命令行窗口,并使用管理员权限运行命令提示符(Windows)或终端(Linux/macOS)。 5. 连接到MySQL服务器。在命令行中输入以下命令: ```shell mysql -u root # 连接到MySQL服务器 ``` 6. 切换到MySQL数据库。在命令行中输入以下命令: ```shell use mysql; # 切换到mysql数据库 ``` 7. 更新root用户的密码。在命令行中输入以下命令: ```shell update user set authentication_string=password('新密码') where user='root'; # 更新root用户的密码 ``` 8. 刷新权限。在命令行中输入以下命令: ```shell flush privileges; # 刷新权限 ``` 9. 退出MySQL。在命令行中输入以下命令: ```shell quit; # 退出MySQL ``` 10. 停止MySQL服务。在命令行中输入以下命令: ```shell sudo service mysql stop # Linux sudo systemctl stop mysql # Linux (systemd) sudo /etc/init.d/mysql stop # Linux (init.d) ``` 11. 启动MySQL服务。在命令行中输入以下命令: ```shell sudo service mysql start # Linux sudo systemctl start mysql # Linux (systemd) sudo /etc/init.d/mysql start # Linux (init.d) ``` 现在,您已经成功重置MySQL密码。您可以使用新密码登录MySQL服务器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值