nodejs使用express连接MySQL数据库

刚搭建了本地的MySQL数据库,用nodejs连接的时候报错:

nodejs使用express连接MySQL数据库

错误:Client does not support authentication protocol requested by server; consider upgrading MySQL client

(客户端不支持服务器请求的身份验证协议;请考虑升级MySQL客户端)

查找了一些网上的资料文档发现是新版本MySQL的版本加密方式不同,参考资料解决,用命令行连接数据库:

mysql -u root -p

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

原因:MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”

参考资料:

https://blog.csdn.net/ad996454914/article/details/80904771

https://blog.csdn.net/qq_19707521/article/details/80226321

https://blog.csdn.net/XDMFC/article/details/80263215