连接数据库时caching_sha2_password怎么解决

时间:2025-03-05 09:23:37

解决方法

网上流行的解决方案是把sha2认证改回以前的认证方式,方法如下:

// 启动Mysql服务
 start

// 登录Mysql(需要输入密码) mysql -u root -p

// 选择数据库(这一步不可省略) use mysql

// 查看plugin设置 select host, user, plugin from user;

// 可以看到root的plugin是caching_sha2_password,我们希望改成mysql_native_password ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'xxxxx';

// 大功告成,关闭Mysql exit stop

其它

其实我们还可以用ssh进行免密登录,这样就绕过了caching_sha2_password认证了(我的猜想)

以后用ssh登录试一试~~