mysql 8 修改密码(ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 解决)

        主要思路是去mysql数据库中修改user表的密码加密类型,然后再修改密码。

  • 首先找到mysql配置文件my.cnf配置跳过认证,skip-grant-tables;
  • 登陆mysql查看root用户的密码加密类型,如果是caching_sha2_password就需要修改一下,然后再修改密码。

mysql配置文件my.cnf配置跳过认证

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
skip-grant-tables # 主要修改这句配置
bind-address = 127.0.0.1
port=3306
mysqlx-bind-address = 127.0.0.1

然后重启mysql服务,然后重新登陆mysql就不需要密码了。

mysql.server restart

下一步查看当前root用户的密码类型,plugin列如果是caching_sha2_password,需要修改加密类型。

# 修改root用户密码加密类型
update user set plugin = 'mysql_native_password' where user = 'root';
➜  etc git:(stable) mysql -u root -p    
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.1.0 Homebrew

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> 
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root             | *DEBB004B48E4F9A8AFBF31E01A47F19BA77C5DDA                              | mysql_native_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> 

然后修改密码。重启mysql服务。

# 密码你自己定义
ALTER USER 'root'@'localhost' IDENTIFIED BY '你定义密码';

mysql.server restart

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值