使用Navicat连接MySql的时候报错Access denied for user ‘root’@‘localhost’ (using password: YES),很纳闷,我刚安装,密码也是刚设置的,密码怎么就不对了呢…
解决方法:
- 第一步:停止mysql服务。百度了一下很多都是说在系统偏好中停止,博主自己试了一下,毫无反应,只能在终端中输入:
sudo /usr/local/mysql/support-files/mysql.server stop
- 第二步: 在终端中以管理员权限启动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
- 第三步:保留当前窗口,新开一个终端登录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.
- 第四步:打开"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
- 第五步:更新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)
- 最后:
退出mysql
mysql> exit
杀死mysqld_safe进程:
kill mysqld_safe
重启mysql:
sudo /usr/local/mysql/support-files/mysql.server restart
由于博主也是刚开始使用mysql,很多问题都需要面向百度才行,以上只是用作记录,下次如果再出现省的再去翻了,如果有什么不对的地方,欢迎指正。
最后附上参考的文章: https://blog.youkuaiyun.com/m0_51329905/article/details/114209098
https://blog.youkuaiyun.com/appleyuchi/article/details/104265671
end