Node.js 连接数据库报错1251 ER_NOT_SUPPORTED_AUTH_MODE
Node.js 连接数据库报错1251 Client does not support authentication protocol requested by server; consider upgrading MySQL client
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true
原因
错误信息 ER_NOT_SUPPORTED_AUTH_MODE 表示客户端不支持服务器要求的身份验证协议。这通常发生在 MySQL 8.0 版本引入的默认身份验证插件 caching_sha2_password 和较旧的 MySQL 客户端之间。
解决
在数据将 MySQL 用户的身份验证插件改回到 mysql_native_password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456789';
FLUSH PRIVILEGES;