忘记密码 Mac12 mysql8.0.27链接报错 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

这篇博客记录了解决MySQL在Navicat中连接失败,错误信息为Access denied for user 'root'@'localhost'的问题。步骤包括停止并以管理员模式启动MySQL服务,然后在新的终端窗口中登录并修改root用户的密码。通过ALTER USER语句更新密码,并使用FLUSH PRIVILEGES刷新权限。最后,退出MySQL,重启服务。确保密码设置符合复杂性要求。
摘要由CSDN通过智能技术生成

使用Navicat连接MySql的时候报错Access denied for user ‘root’@‘localhost’ (using password: YES),很纳闷,我刚安装,密码也是刚设置的,密码怎么就不对了呢…

解决方法:

  1. 第一步:停止mysql服务。百度了一下很多都是说在系统偏好中停止,博主自己试了一下,毫无反应,只能在终端中输入:
sudo /usr/local/mysql/support-files/mysql.server stop
  1. 第二步: 在终端中以管理员权限启动mysqld_safe
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

执行结果:

2021-12-10T06:47:47.6NZ mysqld_safe Logging to '/usr/local/mysql/data/MacBook-Pro.local.err'.
2021-12-10T06:47:47.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2021-12-10T07:02:21.6NZ mysqld_safe mysqld from pid file /usr/local/mysql/data/MacBook-Pro.local.pid ended
  1. 第三步:保留当前窗口,新开一个终端登录mysql
/usr/local/mysql/bin/mysql

登陆成功后可以看到:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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.
  1. 第四步:打开"mysql"这个数据库,SQL如下:(注意只需要复制后面的use 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
  1. 第五步:更新root的密码,SQL如下(8.0不适用类似set password for ‘root’@‘localhost’=password(‘123’);的语法)。这里的密码要用包含至少8位大写+小写+特殊字符+数字的密码,sql:
mysql>ALTER user 'root'@'localhost' IDENTIFIED BY 'xxX123_';

执行结果:

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

这里说是MySQL服务器正在使用–skip grant tables选项运行,所以无法执行此语句

先执行:

mysql> flush privileges;

回车出现成功提示:

Query OK, 0 rows affected (0.00 sec)

然后再执行:

mysql>ALTER user 'root'@'localhost' IDENTIFIED BY 'xxX123_';

修改成功:

Query OK, 0 rows affected (0.01 sec)
  1. 最后:

退出mysql

mysql> exit

杀死mysqld_safe进程:

kill mysqld_safe

重启mysql:

sudo /usr/local/mysql/support-files/mysql.server restart

由于博主也是刚开始使用mysql,很多问题都需要面向百度才行,以上只是用作记录,下次如果再出现省的再去翻了,如果有什么不对的地方,欢迎指正。

最后附上参考的文章: https://blog.csdn.net/m0_51329905/article/details/114209098
https://blog.csdn.net/appleyuchi/article/details/104265671

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值