惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
I
InfoQ
C
Check Point Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
Last Week in AI
Last Week in AI
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
B
Blog
T
The Blog of Author Tim Ferriss
H
Help Net Security
云风的 BLOG
云风的 BLOG

Shiroha白羽的博客

Golang 踩坑 —— interface 为参数的时候传 nil 指针 Codeforces Round 925 (Div. 3) Codeforces Round 924 (Div. 2) Codeforces Round 923 (Div. 3) Codeforces Round 922 (Div. 2) Codeforces Round 921 (Div. 2) Educational Codeforces Round 161 (Rated for Div. 2) Codeforces Round 920 (Div. 3) Codeforces Round 919 (Div. 2) Hello 2024 Good Bye 2023 Codeforces Round 918 (Div. 4) 个人备份的常用 macOS 清理命令 Codeforces Round 917 (Div. 2) Pinely Round 3 (Div. 1 + Div. 2) Educational Codeforces Round 160 (Rated for Div. 2) Codeforces Round 915 (Div. 2) Codeforces Round 914 (Div. 2) Codeforces Round 913 (Div. 3) Educational Codeforces Round 159 (Rated for Div. 2) Codeforces Round 912 (Div. 2) Codeforces Round 911 (Div. 2) CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!) Educational Codeforces Round 158 (Rated for Div. 2) Codeforces Round 910 (Div. 2) Codeforces Round 909 (Div. 3) Codeforces Round 908 (Div. 2) Educational Codeforces Round 157 (Rated for Div. 2) C++自定义的字面量 Codeforces Round 907 (Div. 2)
记一次 Navicat 连接 MySQL 一直报认证错误(Access denied)
Shiroha · 2021-01-02 · via Shiroha白羽的博客

今天一时兴起,想在 WSL2 里下个 MySQL。方法也很简单,直接 sudo apt install mysql-server
本来以为顺风顺水,结果却在 Navicat 连接 MySQL 的操作上出事了

问题

Navicat 无法连接上 MySQL

配置情况

Navicat Premium 15.0.19
MySQL 8.0.22
WSL2(Ubuntu 20)

现状

终端可以通过sudo mysql连上 MySQL
终端不可以通过mysql -u root -p的方式连接,显示密码错误(Access denied for user 'root'@'localhost')
终端可以通过默认用户连接(默认用户为 /etc/mysql/debian.cnf 文件中的 debian-sys-maint,密码为安装MySQL时随机生成得到的)
Navicat不可以通过直接连接或者通过 ssh 的方式连接,显示密码错误(Access denied for user 'root'@'localhost')
Navicat可以通过默认用户连接

经过

尝试1

首先是尝试了百度的结果,重置 MySQL 的 root 账户的密码
因为可以通过sudo mysql直接进入数据库,也就不需要那么多百度出来的奇奇怪怪的操作了
直接进入数据库,然后尝试了下面几行代码

1
2
3
use mysql;
alter user 'root'@'localhost' identified by 'newPassword';
exit

然后,测试mysql -u root -p连接——失败

尝试2

后来在MySQL官网找到了重置root密码的方法,然后赶紧拿来测试
官网链接
其中的一点提到

B.3.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems

大致操作就是先终止 MySQL,然后使用 MySQL 的附加参数来设置一个初始化文件,然后使得 MySQL 去运行此文件。

然后,测试mysql -u root -p连接——失败

其实觉得挺奇怪的,既然都能重启 MySQL 了,说明你已经拿到这个设备的 root 权限了,为什么不直接用 sudo mysql 进入直接run这条命令呢?

尝试3

最终我在一份不起眼的博客上找到了解决方案
博客连接
其中提到了一个很重要的命令

1
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';

This command changes the password for the user root and sets the authentication method to mysql_native_password. This is a traditional method for authentication, and it is not as secure as auth_plugin.

其中的mysql_native_password是所谓的传统验证方案,也就是 Navicat 连接 MySQL 的解决方案

然后将方案1的命令稍作改正得到

1
2
3
use mysql;
alter user 'root'@'localhost' identified with mysql_native_password by 'newPassword';
exit

然后,测试mysql -u root -p连接——成功!

后续

mysql5.8开始将caching_sha2_password作为默认的身份验证插件,该caching_sha2_password和 sha256_password认证插件提供比mysql_native_password插件更安全的密码加密 ,并 caching_sha2_password提供了比更好的性能sha256_password。由于这些优越的安全性和性能特性 caching_sha2_password它是MySQL 8.0首选的身份验证插件,而且也是默认的身份验证插件而不是 mysql_native_password。此更改会影响服务器和libmysqlclient 客户端库;目前来说和经常使用的客户端软件兼容性不好

这也是导致目前 Navicat 无法连接到 MySQL 5.8及以后版本的原因。当然如此操作后的影响便是无法直接使用sudo mysql的方式连接到数据库,只能通过 mysql -u root -p的传统密码验证的方式来登陆